Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Union of polygons

I have a table with a single column of geometry type, containing polygons. How do I get the union of all the polygons in the table?

like image 444
Imp Avatar asked Dec 06 '22 15:12

Imp


1 Answers

In SQL Server 2012:

SELECT geometry::UnionAggregate(geomcolumn) FROM YourTable;

In SQL Server 2008/R2:

DECLARE @g = geometry::STGeomFromText('GEOMETRYCOLLECTION EMPTY', YourSRID);
SELECT @g = @g.STUnion(geomcolum) FROM YourTable;
like image 179
Alastair Aitchison Avatar answered Dec 21 '22 22:12

Alastair Aitchison