I have database tables containing many (70,000+) GEOGRAPHY
polygons. (The polygons are property parcels.) We need to perform a number of calculations on the aggregate shape (a MULTIPOLYGON
) which consists of the geographic union of all of these parcels, such as "what percentage of the convex hull is covered by these polygons"? (Note: this isn't as simple as it sounds. Overlapping parcels do occur, and we don't want to double-count them, so we can't simply add up the area of the parcels.)
In order to perform these calculations, we want to generate a new shape which represents the geographic union of all of the polygons. Based on the answer to this question, I tried the following query:
DECLARE @Shape GEOGRAPHY
SET @Shape = GEOGRAPHY::STGeomFromText('MULTIPOLYGON EMPTY', 4326)
SELECT @Shape = @Shape.STUnion(Shape)
FROM Parcel
But the query takes forever (60 minutes and counting, so far; no answer yet). I'm wondering what other techniques others can think of which are more efficient. This query doesn't ever need to be a real-time query, but 60+ minutes isn't going to work either.