General Spatial Tools¶
convert a matplotlib color table to a GDAL representation. |
|
reproject a coordinate from one CRS to another |
|
convert between different types of spatial reference representations |
|
a simple wrapper for |
|
a simple wrapper for |
|
a simple wrapper for |
|
a simple wrapper for |
|
compute the distance in meters between two points in latlon |
|
a simple wrapper for |
|
get the UTM CRS for a spatial object |
- spatialist.auxil.cmap_mpl2gdal(mplcolor, values)[source]¶
convert a matplotlib color table to a GDAL representation.
- Parameters:
- Returns:
the color table in GDAL format
- Return type:
Note
This function is currently only developed for handling discrete integer data values in an 8 Bit file. Colors are thus scaled between 0 and 255.
Examples
>>> from osgeo import gdal >>> from spatialist.auxil import cmap_mpl2gdal >>> values = list(range(0, 100)) >>> cmap = cmap_mpl2gdal(mplcolor='YlGnBu', values=values) >>> print(isinstance(cmap, gdal.ColorTable)) True
- spatialist.auxil.coordinate_reproject(x, y, s_crs, t_crs)[source]¶
reproject a coordinate from one CRS to another
- Parameters:
s_crs (int, str or osgeo.osr.SpatialReference) – the source CRS. See
crsConvert()
for options.t_crs (int, str or osgeo.osr.SpatialReference) – the target CRS. See
crsConvert()
for options.
- Return type:
- spatialist.auxil.crsConvert(crsIn, crsOut, wkt_format='DEFAULT')[source]¶
convert between different types of spatial reference representations
- Parameters:
crsIn (int or str or osgeo.osr.SpatialReference) – the input CRS
crsOut (str) –
the output CRS type; supported options:
epsg
opengis
osr
prettyWkt
proj4
wkt
wkt_format (str) – the format of the wkt string. See here for options: https://gdal.org/api/ogrspatialref.html#_CPPv4NK19OGRSpatialReference11exportToWktEPPcPPCKc
- Returns:
the output CRS
- Return type:
int or str or osgeo.osr.SpatialReference
Examples
convert an integer EPSG code to PROJ.4:
>>> crsConvert(4326, 'proj4') '+proj=longlat +datum=WGS84 +no_defs '
convert the opengis URL back to EPSG:
>>> crsConvert('https://www.opengis.net/def/crs/EPSG/0/4326', 'epsg') 4326
convert an EPSG compound CRS (WGS84 horizontal + EGM96 vertical) to PROJ.4
>>> crsConvert('EPSG:4326+5773', 'proj4') '+proj=longlat +datum=WGS84 +geoidgrids=us_nga_egm96_15.tif +vunits=m +no_defs'
- spatialist.auxil.gdal_rasterize(src, dst, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Rasterize()
- Parameters:
src (str or osgeo.ogr.DataSource) – the input data set
dst (str) – the output data set
**kwargs – additional parameters passed to
osgeo.gdal.Rasterize()
; seeosgeo.gdal.RasterizeOptions()
- spatialist.auxil.gdal_translate(src, dst, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Translate()
- Parameters:
src (str, osgeo.ogr.DataSource or osgeo.gdal.Dataset) – the input data set
dst (str) – the output data set
**kwargs – additional parameters passed to
osgeo.gdal.Translate()
; seeosgeo.gdal.TranslateOptions()
- spatialist.auxil.gdalbuildvrt(src, dst, void=True, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.BuildVRT()
- Parameters:
src (str, list,
osgeo.ogr.DataSource
orosgeo.gdal.Dataset
) – the input data set(s)dst (str) – the output data set
void (bool) – just write the results and don’t return anything? If not, the spatial object is returned
**kwargs – additional parameters passed to
osgeo.gdal.BuildVRT()
; seeosgeo.gdal.BuildVRTOptions()
- spatialist.auxil.gdalwarp(src, dst, pbar=False, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Warp()
- Parameters:
src (str or osgeo.ogr.DataSource or osgeo.gdal.Dataset or list[str or osgeo.ogr.DataSource or osgeo.gdal.Dataset]) – the input data set
dst (str) – the output data set
pbar (bool) – add a progressbar?
**kwargs – additional parameters passed to
osgeo.gdal.Warp()
; seeosgeo.gdal.WarpOptions()
- spatialist.auxil.haversine(lat1, lon1, lat2, lon2)[source]¶
compute the distance in meters between two points in latlon
- spatialist.auxil.ogr2ogr(src, dst, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.VectorTranslate()
aka ogr2ogr- Parameters:
src (str or osgeo.ogr.DataSource) – the input data set
dst (str) – the output data set
**kwargs – additional parameters passed to
osgeo.gdal.VectorTranslate()
; seeosgeo.gdal.VectorTranslateOptions()
- spatialist.auxil.utm_autodetect(spatial, crsOut)[source]¶
get the UTM CRS for a spatial object
The bounding box of the object is extracted, reprojected to EPSG:4326 and its center coordinate used for computing the best UTM zone fit.
- Parameters:
spatial (Raster or Vector) – a spatial object in an arbitrary CRS
crsOut (str) – the output CRS type; see function
crsConvert()
for options
- Returns:
the output CRS
- Return type:
int or str or osgeo.osr.SpatialReference