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?

Luke Lowrey
  • 3,203
  • 3
  • 28
  • 40

1 Answers1

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.

Tomas
  • 3,573
  • 2
  • 20
  • 25