Search code examples
geopandasr-sfmultilinestring

Convert each multilinestring to one linestring only


In this shapefile, the geometry column is linestring apart from 4 stream reaches (8168547, 8171738, 8170616 ,8169920) that are multilinestring.

enter image description here

I need to convert each multilinestring to one linestring only . I have tried many things but none worked. For example, I tried st_cast in sf package in R. However, it increased the number of the rows (it converts each multilinestring to several linestrings).

How can I convert each multilinestring to one linestring only?


Solution

  • in geopandas, this can be done with explode:

    import geopandas as gpd
    gdf = gpd.read_file(filepath)
    exploded = gdf.explode()