mapchete.io.vector module

Functions handling vector data.

mapchete.io.vector.clean_geometry_type(geometry, target_type, allow_multipart=True, raise_exception=True)

Return geometry of a specific type if possible.

Filters and splits up GeometryCollection into target types. This is necessary when after clipping and/or reprojecting the geometry types from source geometries change (i.e. a Polygon becomes a LineString or a LineString becomes Point) in some edge cases.

Parameters
geometryshapely.geometry
target_typestring

target geometry type

allow_multipartbool

allow multipart geometries (default: True)

Returns
cleaned geometryshapely.geometry

returns None if input geometry type differs from target type

Raises
GeometryTypeErrorif geometry type does not match target_type
mapchete.io.vector.multipart_to_singleparts(geom)

Yield single part geometries if geom is multipart, otherwise yield geom.

Parameters
geomshapely geometry
Returns
shapely single part geometries
mapchete.io.vector.reproject_geometry(geometry, src_crs=None, dst_crs=None, clip_to_crs_bounds=True, error_on_clip=False, segmentize_on_clip=False, segmentize=False, segmentize_fraction=100, validity_check=True, antimeridian_cutting=False, retry_with_clip=True)

Reproject a geometry to target CRS.

Also, clips geometry if it lies outside the destination CRS boundary. Supported destination CRSes for clipping: 4326 (WGS84), 3857 (Spherical Mercator) and 3035 (ETRS89 / ETRS-LAEA).

Parameters
geometryshapely.geometry
src_crsrasterio.crs.CRS or EPSG code

CRS of source data

dst_crsrasterio.crs.CRS or EPSG code

target CRS

error_on_clipbool

raises a RuntimeError if a geometry is outside of CRS bounds (default: False)

validity_checkbool

checks if reprojected geometry is valid and throws TopologicalError if invalid (default: True)

clip_to_crs_boundsbool

Always clip geometries to CRS bounds. (default: True)

antimeridian_cuttingbool

cut geometry at Antimeridian; can result in a multipart output geometry

Returns
geometryshapely.geometry
mapchete.io.vector.segmentize_geometry(geometry, segmentize_value)

Segmentize Polygon outer ring by segmentize value.

Just Polygon geometry type supported.

Parameters
geometryshapely.geometry
segmentize_value: float
Returns
geometryshapely.geometry
mapchete.io.vector.to_shape(geom) shapely.geometry.base.BaseGeometry

Convert geometry to shapely geometry if necessary.

Parameters
geomshapely geometry or GeoJSON mapping
Returns
shapely geometry