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
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityThere 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.
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.
ST_Dump
ing 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.
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
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
polys.shp
is the raw data and boundary.shp
is the required outcome.
– Hugh_Kelley
Aug 1 '19 at 13:07