eodal.core.utils.geometry module¶
Utils for working with shapely.geometry and geopandas.GeoDataFrame like objects.
Copyright (C) 2022 Lukas Valentin Graf
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- eodal.core.utils.geometry.check_geometry_types(in_dataset: Path | GeoDataFrame, allowed_geometry_types: List[str], remove_empty_geoms: bool | None = True) GeoDataFrame[source]¶
Checks if a
GeoDataFramecontains allowedshapely.geometrytypes, only. Raises an error if geometry types other than those allowed are found.- Parameters:
allowed_geometry_types – list of allowed geometry types
in_dataset – file with vector geometries (e.g., ESRI shapefile or GEOJSON) or geodataframe to check
remove_empty_geoms – when True (default) removes features with empty (None-type) geometry from
in_datasetbefore carrying out the type checking.
- Returns:
GeoDataFramewith checked (and optionally cleaned) vector features.
- eodal.core.utils.geometry.convert_3D_2D(geometry: GeoSeries) GeoSeries[source]¶
Takes a GeoSeries of 3D Multi/Polygons (has_z) and returns a list of 2D Multi/Polygons. Snippet taken from https://gist.github.com/rmania/8c88377a5c902dfbc134795a7af538d8 (accessed latest Jan 18th 2021)
- Parameters:
geometry –
GeoSeriesfromGeoDataFrame- Returns:
updated
GeoSerieswithout third dimension (z)
- eodal.core.utils.geometry.multi_to_single_points(point_features: GeoDataFrame | Path) GeoDataFrame[source]¶
Casts MultiPoint geometries to single point geometries by calling gpd.GeoDataFrame.explode()
- Parameters:
point_features – point features to cast
- Returns:
casted point features or input if all geometries are already single parted