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:
x (
float) – the X coordinate componenty (
float) – the Y coordinate components_crs (
int|str|SpatialReference) – the source CRS. SeecrsConvert()for options.t_crs (
int|str|SpatialReference) – the target CRS. SeecrsConvert()for options.
- Return type:
- spatialist.auxil.crsConvert(crsIn, crsOut, wkt_format='DEFAULT')[source]¶
convert between different types of spatial reference representations
- Parameters:
crsIn (
int|str|SpatialReference) – the input CRScrsOut (
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
- Return type:
int|str|SpatialReference- Returns:
the output CRS
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:
dst (
str) – the output data set**kwargs (
Any) – Additional parameters passed toosgeo.gdal.Rasterize(). Seeosgeo.gdal.RasterizeOptions().
- Return type:
- spatialist.auxil.gdal_translate(src, dst, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Translate()- Parameters:
dst (
str) – the output data set**kwargs (
Any) – additional parameters passed toosgeo.gdal.Translate(); seeosgeo.gdal.TranslateOptions()
- Return type:
- spatialist.auxil.gdalbuildvrt(src, dst, void=True, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.BuildVRT()- Parameters:
src (
str|Dataset|list[str|Dataset]) – the input data set(s)dst (
str) – the output data setvoid (
bool) – just write the results and don’t return anything? If not, the spatial object is returned**kwargs (
Any) – additional parameters passed toosgeo.gdal.BuildVRT(); seeosgeo.gdal.BuildVRTOptions()
- Return type:
- spatialist.auxil.gdalwarp(src, dst, pbar=False, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Warp()
- 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:
dst (
str) – the output data set**kwargs (
Any) – additional parameters passed toosgeo.gdal.VectorTranslate(); seeosgeo.gdal.VectorTranslateOptions()
- Return type:
- 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|Vector) – a spatial object in an arbitrary CRScrsOut (
str) – the output CRS type; see functioncrsConvert()for options
- Returns:
the output CRS
- Return type:
int|str|SpatialReference