There are several answers for this question on GIS stackexchange but none using open/free software.

How can someone without access to the Esri suite remove interior holes from a polygon?

Example data is available here


so i took the data given by Hugh_Kelley and i was able to find a good postgis solution.

I imported both shapefiles in PostgresSql and used this query.

I expected to find a lot of polygons with holes but it was mainly multi geometry as you can see on the picture.

CREATE TABLE public.result_union as (
SELECT St_SetSrid( ST_MakePolygon (St_ExteriorRing( St_union( (polys.geom)))),27700) AS poly_boundary
from polys)

With this query, I found the same geometry as the boundary shapefile given by Hugh.

enter image description here

The St_exteriorRing function only accept polygon, so you can not just St_Collect them.

You really need to do a St_Union to dissolve the boundary and if it gives back a MultiGeometrie which is possible, you will have to dump it with St_Dump and do a St_ExteriorRing on each part.

The performance here was ok , 13 secondes , but with the union involved, I suspect it can be hard to use this on a very high number of geometry.

  • This is great, I think ST_Dumping the multipolygon and calling ST_ExteriorRing on each part was where I switched to QGIS. I'll apply it to the ~4500 polygons in the entirety of London and see how performance is. – Hugh_Kelley Aug 3 '19 at 12:13

This may be possible to do in PostGIS using ST_Dump but when I tried I got an error saying:

Can't resolve struct type geometry_dump

A search for the error seemed to indicate that this meant that PostGIS wasn't installed correctly, but that seems unlikely in my case. I never resolved this error.

Instead I used QGIS, which is easily connected to a PostgreSQL database.

There is a Delete Holes function you can find by searching in the processing toolbox.

processing toolbox search

  • 2
    I would suggest you to look into Postgis Function and a combo of St_ExteriorRing with St_polygonize may do the trick. i'll try to make an answer with it later – Maximilien jaffrès Aug 1 '19 at 8:25
  • yeah I explored that combination yesterday actually, because it's supposed to do exactly that, but ST_ExteriorRing just returned NULL. Looking at the docs, maybe this was because the geometry was a multipolygon rather than a polygon. Then given the trouble converting to type polygon with ST_Dump a solution didn't seem likely. – Hugh_Kelley Aug 1 '19 at 8:53
  • 2
    polygon isn't a PostGIS type. It's the native (and moderately useless) geometry type. Your Answer is a Question in disguise. I suggest you rewrite the question to focus on this issue so it can be answered. – Vince Aug 1 '19 at 11:30
  • 1
    Can you share your data ? i will give it a shot if you can share it – Maximilien jaffrès Aug 1 '19 at 12:21
  • fair enough, QGIS works perfectly well and it's available to all but happy to help find a solution in postgis too. Added a link to a folder with the data. polys.shp is the raw data and boundary.shp is the required outcome. – Hugh_Kelley Aug 1 '19 at 13: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.