I have a large GeoDataFrame with over 1 million polygons. Many of these polygons are of a small size and I want to merge them to one of the neighboring polygons (to the one with the greater area). I want to replicate eliminate (like in ArcGIS or QGIS). I have managed to select them bur I was not able to find a way how to merge them correctly. The code that I have used is as follows:

small_area_ids = gpd_poly.loc[gpd_poly.geometry.area < 2000]['ID']
  • 1
    Can one small polygon have only small neighbors? So you will have to repeat the merging until there are no small polygons left?
    – BERA
    Dec 9, 2021 at 6:15
  • 1
    Yes this is the case... but in Qgis and in ArcGIS the results (not the same) but are satisfactory. I am trying to find a way to do this without interrupting the workflow with a desktop application.
    – Antonis
    Dec 9, 2021 at 6:22
  • Maybe something like this could be a start: gis.stackexchange.com/questions/281652/… . Then add a group attribute and dissolve
    – BERA
    Dec 9, 2021 at 7:53

1 Answer 1


I had a similar problem, and the same idea to use GeoPandas to solve it, so I did.

It was a mistake. It was more complex than I thought it would be, and it was not as fast as I had hoped it would be. You may find it useful if you are patient:


I used sjoin with the touches predicate to pair all the polygons to be deleted with adjacent polygons which they may have their geometry merged into. This is computationally expensive.

Then iterated the result to determine which of those pairings is the actual best for each particular polygon, and tagged them together in a column created for that purpose. This is complicated by the fact that polygons to be deleted can also be the best match for merging the geometry of other polygons to be deleted, so they all must be included in the same group.

Then called dissolve to perform the actual merging, using that grouping column as the by parameter, and using the aggfunc callback to find and carry the row data of the surviving polygon that eats the others into the new row that replaces them.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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