SQL Server – Spatial Query for Enclosing Radius/Polygon

aggregatespatialsql server

Is it possible in SQL to run a query of spatial data, and then just return a single polygon, or a radius, that encloses, aggregates, all of the spatial data that was in that query into one feature?

Best Answer

Yes, using SQL Server's

You essentially have three options

  • ConvexHull: returns a polygon that essentially wraps the input with a rubber band,
  • EnvelopeAggregate: returns a bounding box (polygon) that encapsulates the input (box = lines in a cartesian project, arc segments in a 3d/spheroid/geographic projection)
  • UnionAggregate: takes all of the inputs and composes them into a single complex-polygon

Note: you mention radius, a radius is a buffer over an input in GIS.

If you need more features, you should check out the free PostgreSQL and PostGIS which supports even more GIS functionality.