Coverage for stems/gis/convert.py : 92%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
""" GIS variable conversion library
Functions here are convenient ways of going from various representations of GIS information used in this stack (e.g., WKT) to the following representations:
* Coordinate Reference System * :py:class:`rasterio.crs.CRS` * Geotransform * :py:class:`affine.Affine` * Bounding Box * :py:class:`rasterio.coords.BoundingBox` * Bounds * :py:class:`shapely.geom.Polygon`
"""
register_multi_singledispatch)
# XARRAY_TYPE = (xr.Dataset, xr.DataArray)
# ============================================================================ # Affine geotransform """ Convert input into an :py:class:`affine.Affine` transform
Parameters ---------- value : Affine or iterable 6 numbers representing affine transform from_gdal : bool, optional If `value` is a tuple or list, specifies if transform is GDAL variety (True) or rasterio/affine (False)
Returns ------- affine.Affine Affine transform """ raise _CANT_CONVERT(value)
else:
# ============================================================================ # CRS # TODO: Dispatch function for Cartopy def to_crs(value): """ Convert a CRS representation to a :py:class:`rasterio.crs.CRS`
Parameters ---------- value : str, int, dict, or osr.SpatialReference Coordinate reference system as WKT, Proj.4 string, EPSG code, rasterio-compatible proj4 attributes in a dict, or OSR definition
Returns ------- rasterio.crs.CRS CRS """ raise _CANT_CONVERT(value)
def _to_crs_crs(value):
def _to_crs_str(value): # After rasterio=1.0.14 WKT is backbone so try it first 'either WKT or Proj4')
def _to_crs_epsg(value):
def _to_crs_dict(value):
def _to_crs_osr(value):
# ============================================================================ # BoundingBox def to_bounds(value): """ Convert input to a :py:class:`rasterio.coords.BoundingBox`
Parameters ---------- value : iterable, or Polygon Input containing some geographic information
Returns ------- BoundingBox Bounding box (left, bottom, right, top). Also described as (minx, miny, maxx, maxy) """ raise _CANT_CONVERT(value)
def _to_bounds_bounds(value):
def _to_bounds_iter(value):
def _to_bounds_geom(value):
# ============================================================================ # Polygon def to_bbox(value): """ Convert input a bounding box :py:class:`shapely.geometry.Polygon`
Parameters ---------- value : BoundingBox Object representing a bounding box, or an xarray object with coords we can use to calculate one from
Returns ------- shapely.geometry.Polygon BoundingBox as a polygon """ raise _CANT_CONVERT(value)
def _to_bbox_geom(value):
def _to_bbox_bounds(value):
# ============================================================================ # UTILITIES return TypeError(f"Don't know how to convert this type: {type(obj)}") |