GenericMappingTools / GenericMappingTools/pygmt

Get projection/crs from GMT_GRID_HEADER

Open
#3,470 0 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
Python
Stars
874
Forks
255
Avg merge
1d 21h
Merged PRs (30d)
40

Description

### Description of the desired feature

This is a feature request to add a method for getting the projected coordinate reference system (CRS) from a GMT_GRID (#2398)/GMT_IMAGE (#3338)/GMT_CUBE (#3150) struct when parsing a NetCDF/GeoTIFF file. Motivation from https://github.com/GenericMappingTools/pygmt/pull/2235#discussion_r1780317848:

>> In `GMT_IMAGE.to_dataarray()`, perhaps we should parse the `header->ProjRefPROJ4` and set the correct CRS to the 3-band xarray.DataArray. ...
>
> Yeah, I was thinking of parsing the projection information from the header when you mentioned this `ProjRefPROJ4` field at https://github.com/GenericMappingTools/pygmt/pull/3128#discussion_r1779965090. But ideally we'll need to handle PROJ4/WKT/EPSG:
>
> https://github.com/GenericMappingTools/pygmt/blob/f97c3a462a0d65e10da7707a71c9cc991457759a/pygmt/datatypes/header.py#L138-L143
> ...

### Implementation details

Use [`pyproj.CRS.from_string`](https://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_string) to make a CRS from PROJ4/WKT/EPSG. Create a new method/property under `_GMT_GRID_HEADER` at https://github.com/GenericMappingTools/pygmt/blob/v0.13.0/pygmt/datatypes/header.py#L67

We can also consider exposing a `.gmt.proj` or `.gmt.crs` xarray accessor property (xref #499). But note that there is some discussion at https://github.com/geoxarray/geoxarray/issues/21 on whether there should be a common `.crs` accessor in some xarray library that can be used across [rioxarray](https://github.com/corteva/rioxarray)/[geoxarray](https://github.com/geoxarray/geoxarray)/[odc-geo](https://github.com/opendatacube/odc-geo)/etc.

### Are you willing to help implement and maintain this feature?

Yes

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.