Skip to content

Get projection/crs from GMT_GRID_HEADER #3470

Open
@weiji14

Description

@weiji14

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 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 #3128 (comment). But ideally we'll need to handle PROJ4/WKT/EPSG:

# Referencing system string in PROJ.4 format
("ProjRefPROJ4", ctp.c_char_p),
# Referencing system string in WKT format
("ProjRefWKT", ctp.c_char_p),
# Referencing system EPSG code
("ProjRefEPSG", ctp.c_int),

...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions