Search code examples
sql-serversqlgeometry

All shapes with X miles or meters using SqlGeometery


My table uses a SqlGeometery in SRID 3857.

Given a point, how would I find all shapes within a X miles or meters radius?


Solution

  • Put a Buffer around the point and run STIntersects to get all intersection shapes. Just make sure you put an index on the Geometry column otherwise it could get slow. Note that x is in meters (eg 10m).

    SELECT *
    FROM MyTable
    WHERE MyGeometryShapesColumn.STIntersects(@MyGeometryPoint.STBuffer(10)) = 1;