gisutils.projection module¶
Functions for working with coordinate reference systems and projections.
- gisutils.projection.get_authority_crs(crs)[source]¶
Try to get the authority representation for a CRS, for more robust comparison with other CRS objects.
- Parameters
- crsobj
A Python int, dict, str, or pyproj.crs.CRS instance passed to the pyproj.crs.from_user_input See http://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_user_input. Can be any of:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
- Returns
- authority_crspyproj.crs.CRS instance
CRS instance initiallized with the name and authority code (e.g. epsg: 5070) produced by
pyproj.crs.CRS.to_authority()
Notes
pyproj.crs.CRS.to_authority()
will return None if a matching authority name and code can’t be found. In this case, the input crs instance will be returned.References
- gisutils.projection.get_proj_str(prjfile)[source]¶
Get the PROJ string from the well-known text in an ESRI projection file.
- Parameters
- prjfilestring (filepath)
ESRI Shapefile or projection file
- Returns
- proj_strstring (http://trac.osgeo.org/proj/)
Notes
PROJ strings can be lossy and are no longer recommended as a way to store coordinate reference system (CRS) information. The pyproj
CRS
class provides an improved way to represent CRS in memory; the gisutilsget_authority_crs()
andget_shapefile_crs()
functions return pyprojCRS
instances and are therefore preferred over this function.References
https://pyproj4.github.io/pyproj/dev/api/crs/crs.html#pyproj.crs.CRS https://pyproj4.github.io/pyproj/dev/gotchas.html#what-are-the-best-formats-to-store-the-crs-information
- gisutils.projection.get_rasterio_crs(crs)[source]¶
Returns a rasterio.crs.CRS representation of the input coordinate reference system.
- Parameters
- crsobj
A Python int, dict, str, or pyproj.crs.CRS instance passed to the pyproj.crs.from_user_input See http://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_user_input. Can be any of:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
- Returns
- rasterio_crsrasterio.crs.CRS instance
- gisutils.projection.get_shapefile_crs(shapefile)[source]¶
Get the coordinate reference system for a shapefile.
- Parameters
- shapefilestr
Path to a shapefile
- Returns
- crspyproj.CRS instance
- gisutils.projection.project(geom, projection1, projection2)[source]¶
Reproject shapely geometry object(s) or scalar coodrinates to new coordinate system
- Parameters
- geom: shapely geometry object, list of shapely geometry objects,
list of (x, y) tuples, or (x, y) tuple.
- projection1: string
Proj4 string specifying source projection
- projection2: string
Proj4 string specifying destination projection
- gisutils.projection.project_raster(source_raster, dest_raster, dest_crs, resampling=1, resolution=None, num_threads=2, driver='GTiff', **kwargs)[source]¶
Reproject a raster from one coordinate system to another using Rasterio code from: https://github.com/mapbox/rasterio/blob/master/docs/reproject.rst
- Parameters
- source_rasterstr
Filename of source raster.
- dest_rasterstr
Filename of reprojected (destination) raster. Extension of filename should match the driver (e.g., ‘.tif’ for GeoTIFF)
- dest_crsobj
A Python int, dict, str, or pyproj.crs.CRS instance passed to the pyproj.crs.from_user_input See http://pyproj4.github.io/pyproj/stable/api/crs/crs.html#pyproj.crs.CRS.from_user_input. Can be any of:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
- resamplingint
Type of resampling to use when reprojecting the raster (see rasterio source code: https://github.com/mapbox/rasterio/blob/master/rasterio/enums.py) nearest = 0 bilinear = 1 cubic = 2 cubic_spline = 3 lanczos = 4 average = 5 mode = 6 gauss = 7 max = 8 min = 9 med = 10 q1 = 11 q3 = 12
- resolutiontuple of floats (len 2)
cell size of the output raster (x resolution, y resolution)
- driverstr
GDAL driver/format to use for writing dst_raster. Default is GeoTIFF.
- **kwargsdict
Keyword arguments to
rasterio.open()
for writing the output raster.