I would like to dissolve a shapefile regardless of attribute content using geopandas. The regular dissolve can be accomplished with something like this:

import geopandas    
all = geopandas.read_file(r'Inputs\All.shp')    
all = all.dissolve(by='topology')    
all.to_file(driver = 'ESRI Shapefile', filename = r'Intermediate\All_dissolved.shp')

But the above is using the 'topology' field to aggregate. I have also noticed that the all.dissolve() function exits with an error, indicating that the by parameter is required.

How can I dissolve regardless of the attribute in GeoPandas?

  • does it work with an empty string or a True as value for by maybe? Sep 21 '18 at 13:09

You will lose all attributes but unary_union will return one big multipolygon which you can turn into singleparts with .geoms:

import geopandas as gpd
df = gpd.read_file(r"C:\Test\New_Shapefile.shp")

enter image description here

df2 = gpd.geoseries.GeoSeries([geom for geom in df.unary_union.geoms])

enter image description here

(You can also add a column, fill with some value and then dissolve by

df['dissolvefield'] = 1
df2 = df.dissolve(by='dissolvefield')
df3 = gpd.geoseries.GeoSeries([geom for geom in df2.geometry.iloc[0].geoms])



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.