sql >> Base de Datos >  >> RDS >> PostgreSQL

PostGIS equivalente de ArcMap Union

Aquí hay una consulta de trabajo basada en esta respuesta de gis.stackexchange :

Léalo de a) a d):

-- d) Extract the path number and the geom from the geometry dump
SELECT
  (dump).path[1] id,
  (dump).geom
FROM
(
  -- c) Polygonize the unioned rings (returns a GEOMETRYCOLLECTION)
  --    Dump them to return individual geometries
  SELECT
    ST_Dump(ST_Polygonize(geom)) dump
  FROM
  (
    -- b) Union all rings in one big geometry
    SELECT
      ST_Union(geom) geom
    FROM
    (
      -- a) First get the exterior ring from all geoms
      SELECT
        ST_ExteriorRing(geom) geom
      FROM
        rectangles
    ) a
  ) b
) c

Resultado: