From cb10bae975973a7dce13dd15b1a84be8e020dd71 Mon Sep 17 00:00:00 2001 From: AlexanderJuestel Date: Sun, 28 Jul 2024 12:42:10 +0200 Subject: [PATCH] Format explode_multilinestrings --- gemgis/vector.py | 73 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/gemgis/vector.py b/gemgis/vector.py index f6f80c76..7ab0d9c6 100644 --- a/gemgis/vector.py +++ b/gemgis/vector.py @@ -2799,34 +2799,56 @@ def explode_multilinestrings( drop_level0: bool = True, drop_level1: bool = True, ) -> gpd.geodataframe.GeoDataFrame: - """Exploding Shapely MultiLineStrings stored in a GeoDataFrame to Shapely LineStrings + """Explode Shapely MultiLineStrings stored in a GeoDataFrame to Shapely LineStrings. Parameters ---------- gdf : gpd.geodataframe.GeoDataFrame - GeoDataFrame created from vector data containing elements of geom_type MultiLineString + GeoDataFrame created from vector data containing elements of ``geom_type`` MultiLineString. - reset_index : bool + +----+----------------------------------------+ + | | geometry | + +----+----------------------------------------+ + | 0 | MULTILINESTRING ((0.0 0.0, 1.0 1.0)) | + +----+----------------------------------------+ + | 1 | MULTILINESTRING ((0.0 0.0, 1.0 1.0)) | + +----+----------------------------------------+ + + reset_index : bool, default: ``True`` Variable to reset the index of the resulting GeoDataFrame. - Options include: ``True`` or ``False``, default set to ``True`` + Options include: ``True`` or ``False``, default set to ``True``. - drop_level0 : bool + drop_level0 : bool, default: ``True`` Variable to drop the level_0 column. - Options include: ``True`` or ``False``, default set to ``True`` + Options include: ``True`` or ``False``, default set to ``True``. - drop_level1 : bool + drop_level1 : bool, default: ``True`` Variable to drop the level_1 column. - Options include: ``True`` or ``False``, default set to ``True`` + Options include: ``True`` or ``False``, default set to ``True``. Returns ------- gdf : gpd.geodataframe.GeoDataFrame - GeoDataFrame containing LineStrings + GeoDataFrame containing LineStrings. + + +----+------------------------------+ + | ID | geometry | + +----+------------------------------+ + | 0 | LINESTRING (0.0 0.0, 1.0 1.0)| + +----+------------------------------+ + | 1 | LINESTRING (-1.0 0.0, 1.0 0.0)| + +----+------------------------------+ + | 2 | LINESTRING (0.0 0.0, 1.0 1.0)| + +----+------------------------------+ + | 3 | LINESTRING (-1.0 0.0, 1.0 0.0)| + +----+------------------------------+ .. versionadded:: 1.0.x + .. versionchanged:: 1.2 + Example _______ @@ -2835,26 +2857,39 @@ def explode_multilinestrings( >>> import geopandas as gpd >>> gdf = gpd.read_file(filename='file.shp') >>> gdf - geometry - 0 MULTILINESTRING ((0.0 0.0, 1.0 1.0)) - 1 MULTILINESTRING ((0.0 0.0, 1.0 1.0)) + + +----+----------------------------------------+ + | | geometry | + +----+----------------------------------------+ + | 0 | MULTILINESTRING ((0.0 0.0, 1.0 1.0)) | + +----+----------------------------------------+ + | 1 | MULTILINESTRING ((0.0 0.0, 1.0 1.0)) | + +----+----------------------------------------+ + >>> # Exploding MultiLineStrings into single LineStrings >>> gdf_linestrings = gg.vector.explode_multilinestrings(gdf=gdf, reset_index=True) >>> gdf_linestrings - geometry - 0 LINESTRING (0.0 0.0, 1.0 1.0) - 1 LINESTRING (-1.0 0.0, 1.0 0.0) - 2 LINESTRING (0.0 0.0, 1.0 1.0) - 3 LINESTRING (-1.0 0.0, 1.0 0.0) + + +----+------------------------------+ + | ID | geometry | + +----+------------------------------+ + | 0 | LINESTRING (0.0 0.0, 1.0 1.0)| + +----+------------------------------+ + | 1 | LINESTRING (-1.0 0.0, 1.0 0.0)| + +----+------------------------------+ + | 2 | LINESTRING (0.0 0.0, 1.0 1.0)| + +----+------------------------------+ + | 3 | LINESTRING (-1.0 0.0, 1.0 0.0)| + +----+------------------------------+ + See Also ________ - explode_multilinestring : Exploding a MultiLineString into a list of single LineStrings + explode_multilinestring : Explode a MultiLineString into a list of single LineStrings """ - # Checking that gdf is of type GepDataFrame if not isinstance(gdf, gpd.geodataframe.GeoDataFrame): raise TypeError("Loaded object is not a GeoDataFrame")