gemgis.vector.explode_multilinestrings#

gemgis.vector.explode_multilinestrings(gdf: geopandas.geodataframe.GeoDataFrame, reset_index: bool = True, drop_level0: bool = True, drop_level1: bool = True) geopandas.geodataframe.GeoDataFrame#

Exploding 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

  • reset_index (bool) – Variable to reset the index of the resulting GeoDataFrame. Options include: True or False, default set to True

  • drop_level0 (bool) – Variable to drop the level_0 column. Options include: True or False, default set to True

  • drop_level1 (bool) – Variable to drop the level_1 column. Options include: True or False, default set to True

Returns

gdf – GeoDataFrame containing LineStrings

Return type

gpd.geodataframe.GeoDataFrame

New in version 1.0.x.

Example

>>> # Loading Libraries and File
>>> import gemgis as gg
>>> 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))
>>> # 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)

See also

explode_multilinestring

Exploding a MultiLineString into a list of single LineStrings