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 #2235 (comment):
In
GMT_IMAGE.to_dataarray()
, perhaps we should parse theheader->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 #3128 (comment). But ideally we'll need to handle PROJ4/WKT/EPSG:pygmt/pygmt/datatypes/header.py
Lines 138 to 143 in f97c3a4
...
Implementation details
Use pyproj.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 geoxarray/geoxarray#21 on whether there should be a common .crs
accessor in some xarray library that can be used across rioxarray/geoxarray/odc-geo/etc.
Are you willing to help implement and maintain this feature?
Yes