stems.gis.projections module

Projection handling - OSGEO/Rasterio, CF/NetCDF, and Cartopy

stems.gis.projections.CF_ELLIPSOID_DEFS = (('semi_major_axis', 'GetSemiMajor'), ('semi_minor_axis', 'GetSemiMinor'), ('inverse_flattening', 'GetInvFlattening'))

mapping from CF ellipsoid parameter to SpatialReference method calls

Type

tuple

stems.gis.projections.CF_PROJECTION_DEFS = {'albers_conic_equal_area': (('latitude_of_projection_origin', 'latitude_of_center'), ('longitude_of_central_meridian', 'longitude_of_center'), ('standard_parallel', ('standard_parallel_1', 'standard_parallel_2')), ('false_easting', 'false_easting'), ('false_northing', 'false_northing')), 'lambert_azimuthal_equal_area': (('longitude_of_projection_origin', 'longitude_of_center'), ('latitude_of_projection_origin', 'latitude_of_center'), ('false_easting', 'false_easting'), ('false_northing', 'false_northing')), 'latitude_longitude': (), 'sinusoidal': (('longitude_of_central_meridian', 'central_meridian'), ('false_northing', 'false_northing'), ('false_easting', 'false_easting')), 'transverse_mercator': (('latitude_of_projection_origin', 'latitude_of_origin'), ('longitude_of_central_meridian', 'central_meridian'), ('scale_factor_at_central_meridian', 'scale_factor'), ('false_easting', 'false_easting'), ('false_northing', 'false_northing')), 'universal_transverse_mercator': ('utm_zone_number', 'utm_zone_number')}

Mapping between CF <-> OGC WKT projection parameters for projections

Type

dict

stems.gis.projections.CF_PROJECTION_NAMES = {'Albers_Conic_Equal_Area': 'albers_conic_equal_area', 'Azimuthal_Equidistant': 'azimuthal_equidistant', 'Lambert_Azimuthal_Equal_Area': 'lambert_azimuthal_equal_area', 'Sinusoidal': 'sinusoidal', 'Transverse_Mercator': 'transverse_mercator'}

Mapping between OGC WKT <-> CF projection names

Type

dict

stems.gis.projections.cf_crs_attrs(crs)[source]

Return CF-compliant CRS info to prevent “unknown” CRS/Ellipse/Geoid

Parameters

crs (rasterio.crs.CRS) – CRS

Returns

CF attributes

Return type

OrderedDict

References

1

https://cf-pcmdi.llnl.gov/trac/wiki/Cf2CrsWkt#Table2-FutureCF-1.7CFGridMappingAttributes

Examples

>>> cf_crs_attrs(CRS.from_epsg(4326))  # WGS84
OrderedDict([('geographic_coordinate_system_name', 'WGS 84'),
         ('horizontal_datum_name', 'WGS_1984'),
         ('reference_ellipsoid_name', 'WGS 84'),
         ('prime_meridian_name', 'Greenwich')])
>>> cf_crs_attrs(CRS.from_epsg(32619))  # UTM19N
OrderedDict([('projected_coordinate_system_name', 'WGS 84 / UTM zone 19N'),
             ('horizontal_datum_name', 'WGS_1984'),
             ('reference_ellipsoid_name', 'WGS 84'),
             ('prime_meridian_name', 'Greenwich')])
stems.gis.projections.cf_crs_name(crs)[source]

Return CF name of a CRS projection

Parameters

crs (rasterio.crs.CRS) – CRS

Returns

Lowercase projection name (see keys of CF_PROJECTION_DEFS)

Return type

str

Examples

>>> cf_crs_attrs(CRS.from_epsg(4326))  # WGS84
'latitude_longitude'
>>> cf_crs_attrs(CRS.from_epsg(32619))  # UTM19N
'transverse_mercator'
stems.gis.projections.cf_ellps_params(crs)[source]

Return ellipsoid parameters for a CRS

Parameters

crs (rasterio.crs.CRS) – CRS

Returns

Ellipsoid parameters and values

Return type

OrderedDict

Examples

>>> cf_crs_attrs(CRS.from_epsg(4326))  # WGS84
OrderedDict([('semi_major_axis', 6378137.0),
             ('semi_minor_axis', 6356752.314245179),
             ('inverse_flattening', 298.257223563)])
>>> cf_crs_attrs(CRS.from_epsg(32619))  # UTM19N
OrderedDict([('semi_major_axis', 6378137.0),
             ('semi_minor_axis', 6356752.314245179),
             ('inverse_flattening', 298.257223563)])
stems.gis.projections.cf_proj_params(crs)[source]

Return projection parameters for a CRS

Parameters

crs (rasterio.crs.CRS) – CRS

Returns

CRS parameters and values

Return type

OrderedDict

Raises

stems.errors.TODO – Raise if CRS isn’t supported yet

Examples

>>> cf_crs_attrs(CRS.from_epsg(4326))  # WGS84
OrderedDict()
>>> cf_crs_attrs(CRS.from_epsg(32619))  # UTM19N
OrderedDict([('latitude_of_projection_origin', 0.0),
             ('longitude_of_central_meridian', -69.0),
             ('scale_factor_at_central_meridian', 0.9996),
             ('false_easting', 500000.0),
             ('false_northing', 0.0)])
stems.gis.projections.cf_xy_coord_names(crs)[source]

Returns appropriate names for coordinates given CRS

Parameters

crs (rasterio.crs.CRS) – Coordinate reference system

Returns

  • str (x_coord_name) – X coordinate name

  • str (y_coord_name) – Y coordinate name

Examples

>>> cf_crs_attrs(CRS.from_epsg(4326))  # WGS84
('longitude', 'latitude')
>>> cf_crs_attrs(CRS.from_epsg(32619))  # UTM19N
('x', 'y')
stems.gis.projections.crs_longname(crs)[source]

Return name of a CRS / ellipsoid pair

Parameters

crs (rasterio.crs.CRS) – CRS

Returns

Lowercase projection name (see keys of CF_PROJECTION_DEFS)

Return type

str

Examples

>>> crs_longname(CRS.from_epsg(3857))  # Web Mercator
'WGS 84 / Pseudo-Mercator'
>>> crs_longname(CRS.from_epsg(32619))  # UTM19N
'WGS 84 / UTM zone 19N'
stems.gis.projections.epsg_code(crs)[source]

Return EPSG code for a CRS

Parameters

crs (CRS or osr.SpatialReference) – Coordinate reference system defined by an EPSG code

Returns

EPSG code string

Return type

str

Raises

ValueError – Raised if projection does not correspond to an EPSG code