Skip to content

Instantly share code, notes, and snippets.

@mdiener21
Last active March 1, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdiener21/cdd3d08cd2d939e61f3202ea59cbc61c to your computer and use it in GitHub Desktop.
Save mdiener21/cdd3d08cd2d939e61f3202ea59cbc61c to your computer and use it in GitHub Desktop.
Postgis remove all rings from all polygons
UPDATE multipoly_table_with_rings AS myrings
SET geom = noring.geom
FROM (
SELECT id, ST_Collect(ST_MakePolygon(geom)) AS geom
FROM (
SELECT id, ST_NRings(geom) AS nrings,
ST_ExteriorRing((ST_Dump(geom)).geom) AS geom
FROM multipoly_table_with_rings
WHERE ST_NRings(geom) > 1
) AS foo
GROUP BY gid, nrings
HAVING nrings > COUNT(id)
) AS noring
WHERE myrings.id = noring.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment