Most efficient way to get points within radius of a point with sql server spatial
Asked Answered
A

1

6

I am trying to work out the most efficient query to get points within a radius of a given point. The results do not have to be very accurate so I would favor speed over accuracy.

We have tried using a where clause comparing distance of points using STDistance like this (where @point and v.GeoPoint are geography types):

WHERE v.GeoPoint.STDistance(@point) <= @radius

Also one using STIntersects similar to this:

WHERE @point.STBuffer(@radius).STIntersects(v.GeoPoint) = 1

Are either of these queries preferred or is there another function that I have missed?

Appliance answered 16/6, 2011 at 12:13 Comment(0)
A
4

If accuracy is not paramount then using the Filter function might be a good idea: http://msdn.microsoft.com/en-us/library/cc627367.aspx

This can i many cases be orders of magnitude faster because it does not do the check to see if your match was exact. In the index the data is stored in a grid pattern, so how viable this approach is probably depends on your spatial index options.

Also, if you don't have to many matches then doing a filter first, and then doing a full intersect might be viable.

Ardin answered 20/6, 2011 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.