5

I would like to merge polygons (parcels) which are inside the white road (which is a hole) -- see the picture. The way I'm doing this is certainly a bad way because later, in my script, I have this error: AttributeError: 'GeoSeries' object has no attribute '_geom'

pa_fu = parcelles.unary_union
voirie = commune.difference(pa_fu) # commune is a big polygon which contains all the geometries

public = pd.DataFrame()
public['geometry'] = voirie
public['statut'] = ['public'] * public.size

prive = pd.DataFrame()
prive['geometry'] = pa_fu
prive['statut'] = ['prive'] * prive.size

decoupage = GeoDataFrame(pd.concat([public, prive]))
decoupage.crs=commune.crs # on fixe le système de projection identique à commune
cases_decoupage = overlay(cases, decoupage, how="intersection")

enter image description here

How can I merge these parcels and create a GeoDataFrame containing merged parcels and the white hole as a polygon?

3

I found that

df = gpd.GeoDataFrame(pd.concat([df1, df2], ignore_index=True))

Seems to me that pd.concat strips something from GeoSeries and turns it into pandas Series, so we need to cast it back to GeoSeries (and GeoDataFrame).

1

I encountered the same problem as df1 and df2 has overlapping index, which pd.concat join the geometry into GeoSeries using ignore_index=True does solve the problem

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.