gemgis.vector.explode_geometry_collections
gemgis.vector.explode_geometry_collections#
- gemgis.vector.explode_geometry_collections(gdf: geopandas.geodataframe.GeoDataFrame, reset_index: bool = True, drop_level0: bool = True, drop_level1: bool = True, remove_points: bool = True) geopandas.geodataframe.GeoDataFrame #
Exploding Shapely Geometry Collections stored in GeoDataFrames to different Shapely Base Geometries
- Parameters
gdf (gpd.geodataframe.GeoDataFrame) – GeoDataFrame created from vector data containing elements of geom_type GeometryCollection
reset_index (bool) – Variable to reset the index of the resulting GeoDataFrame. Options include:
True
orFalse
, default set toTrue
drop_level0 (bool) – Variable to drop the level_0 column. Options include:
True
orFalse
, default set toTrue
drop_level1 (bool) – Variable to drop the level_1 column. Options include:
True
orFalse
, default set toTrue
remove_points (bool) – Variable to remove points from exploded GeoDataFrame. Options include:
True
orFalse
, default set toTrue
- Returns
gdf – GeoDataFrame containing different geometry types
- Return type
gpd.geodataframe.GeoDataFrame
New in version 1.0.x.
Example
>>> # Loading Libraries and creating Geometries >>> import gemgis as gg >>> from shapely.geometry import LineString, Polygon >>> import geopandas as gpd >>> a = LineString([(0, 0), (1, 1), (1,2), (2,2)]) >>> b = LineString([(0, 0), (1, 1), (2,1), (2,2)]) >>> collection = a.intersection(b) >>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10)])
>>> # Creating GeoDataFrame from Base Geometries >>> gdf = gpd.GeoDataFrame(geometry=[a, b, collection, polygon]) >>> gdf geometry 0 LINESTRING (0.00000 0.00000, 1.00000 1.00000, ... 1 LINESTRING (0.00000 0.00000, 1.00000 1.00000, ... 2 GEOMETRYCOLLECTION (POINT (2.00000 2.00000), L... 3 POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1..
>>> # Explode Geometry Collection into single Base Geometries >>> gdf_exploded = gg.vector.explode_geometry_collections(gdf=gdf) >>> gdf_exploded geometry 0 LINESTRING (0.00000 0.00000, 1.00000 1.00000, ... 1 LINESTRING (0.00000 0.00000, 1.00000 1.00000, ... 2 LINESTRING (0.00000 0.00000, 1.00000 1.00000) 3 POLYGON ((0.00000 0.00000, 10.00000 0.00000, 1...
See also
explode_geometry_collection
Exploding a Shapely Geometry Collection Object into a list of Base Geometries