[GIS] Unions of polygons (Postgis ST_UNION for Geography type)

geometrypostgis

I am looking for a function that will return the intersection of 2 or more polygons (geography type).

I am aware of ST_UNION, ST_COLLECT but it works only for geometry type.

Best Answer

You can cast to geometry and do the calculation. If your data goes over the poles or date-line that could be problematic. Also if you have long edges, in which the great-circle interpolation line differs from a simple cartesian interpolation. In those cases you might have to create your own aggregate function that re-projects to something reasonable before running the operation.

SELECT ST_Transform(
  ST_Union(ST_Transform(geog::geometry, 26910)),
  4326)::geography 
FROM the_table