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 |
|
Iterate over the simple geometry parts of an OGR geometry. |
|
Iterate over all vertices of an OGR geometry. |
|
Clamp latitude and longitude values to the range [-180, 180] and [-90, 90] respectively. |
|
Compute the center of a (potentially antimeridian-crossing) extent. |
|
Normalize latitude and longitude values to the range [-180, 180] and [-90, 90] respectively. |
|
Get the shortest circular interval containing all longitudes. |
|
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 (
Literal['epsg','opengis','osr','prettyWkt','proj4','wkt']) – the output CRS typewkt_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, void=True, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.Translate()- Parameters:
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.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.iter_geometries(geom)[source]¶
Iterate over the simple geometry parts of an OGR geometry.
Multi-geometries and geometry collections are recursively unpacked. Polygons are treated as atomic geometries, i.e. their exterior and interior rings are not yielded separately.
- spatialist.auxil.iter_points(geom)[source]¶
Iterate over all vertices of an OGR geometry.
Nested geometries such as polygons, multi-geometries, and geometry collections are traversed recursively.
- spatialist.auxil.latlon_clamp(lat=None, lon=None)[source]¶
Clamp latitude and longitude values to the range [-180, 180] and [-90, 90] respectively.
- Parameters:
- Return type:
Examples
>>> latlon_clamp(lon=200) 180.0
- spatialist.auxil.latlon_extent_center(extent)[source]¶
Compute the center of a (potentially antimeridian-crossing) extent.
- spatialist.auxil.latlon_normalize(lat=None, lon=None)[source]¶
Normalize latitude and longitude values to the range [-180, 180] and [-90, 90] respectively.
- Parameters:
- Return type:
Examples
>>> latlon_normalize(lon=200) -160.0
- spatialist.auxil.longitude_shortest_interval(longitudes)[source]¶
Get the shortest circular interval containing all longitudes.
Longitudes are normalized to the range [-180, 180]. If the shortest interval crosses the antimeridian, the returned minimum is greater than the returned maximum.
- Parameters:
- Returns:
The bounds of the shortest circular longitude interval.
- Return type:
- Raises:
ValueError – If longitudes is empty.
Examples
>>> longitude_shortest_interval([170, -170]) (170.0, -170.0)
>>> longitude_shortest_interval([-10, 10]) (-10.0, 10.0)
- spatialist.auxil.ogr2ogr(src, dst, void=True, **kwargs)[source]¶
a simple wrapper for
osgeo.gdal.VectorTranslate()aka ogr2ogr- Parameters:
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.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. In case the reprojected geometry crosses the antimeridian, the coordinates are first shifted to a 0-360° space.
- 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