0

I have performed a dissolve but I want to turn it to singlepart.I have searched in the docs but haven't seen something that does it. What do you think?

Actually, I want to make it singlepart and then create a column that will have something like id so later that I will be doing an intersection I will be using this id to remember the polygons that were as one and do a condition that keeps the max area.

The important thing here is how to turn it to singlepart and maybe how to approach the column with the id thinking.

data = dat[dat['TYPE'].str.startswith(('01'))]
dslved=data.dissolve(by=TYPE')

# here needs to be the singlepart process

interscted=gpd.overlay(dslved,file_m,how='intersection')
2

Seems it has been solved by Philipp Schwarz on github :

import geopandas as gp
import pandas as pd

gpdf = gp.read_file('Germany/vg2500_bld.shp')

def multi2single(gpdf):
    gpdf_singlepoly = gpdf[gpdf.geometry.type == 'Polygon']
    gpdf_multipoly = gpdf[gpdf.geometry.type == 'MultiPolygon']

    for i, row in gpdf_multipoly.iterrows():
        Series_geometries = pd.Series(row.geometry)
        df = pd.concat([gp.GeoDataFrame(row, crs=gpdf_multipoly.crs).T]*len(Series_geometries), ignore_index=True)
        df['geometry']  = Series_geometries
        gpdf_singlepoly = pd.concat([gpdf_singlepoly, df])

    gpdf_singlepoly.reset_index(inplace=True, drop=True)
    return gpdf_singlepoly

Ref. : https://github.com/geopandas/geopandas/issues/369

  • I have already seen that but I don't know how to apply it to my data – user122244 Jun 18 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.