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?

Martin F
  • 8,948
  • 36
  • 58
Apatride
  • 51
  • 1
  • 2

2 Answers2

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).

j08lue
  • 289
  • 1
  • 3
  • 9
yosukesabai
  • 468
  • 3
  • 10
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

Deo Leung
  • 201
  • 1
  • 4