snippetsqlMinor
How can I search for all points with a specific range (radius) of another point?
Viewed 0 times
cansearchallwithpointsrangepointradiusforanother
Problem
The syntax I use to query for polygons in range of other Points
But, to query points of interests, I use a radius and I'm using this.
Is there a better way to write this? Can the queries be improved?
SELECT *
FROM dbo.myTable
INNER JOIN
dbo.myPOI ON myTable.geog.STIntersects(myPOI.geog) = 1But, to query points of interests, I use a radius and I'm using this.
SELECT *
FROM dbo.myTable
INNER JOIN
dbo.myPOI2 ON myTable.geog.STDistance(myPOI2.geog) <= POI2.Point_RadiusIs there a better way to write this? Can the queries be improved?
Solution
Can the queries themselves be improved?
Yes. That's going to be slow. You could massively improve that query by buffering the point and finding the
You can make this even better in your case because the radius is provided on the row, rather than in the query. You can store the geometery returned by
Other implementations
As a side note, this type of query is done with
...
dbo.myPOI2 ON myTable.geog.STDistance(myPOI2.geog) <= POI2.Point_RadiusYes. That's going to be slow. You could massively improve that query by buffering the point and finding the
intersects:ON myTable.geog.STIntersects(myPOI.geog.STBuffer(PP.Point_Radius)) = 1You can make this even better in your case because the radius is provided on the row, rather than in the query. You can store the geometery returned by
STBuffer on the table instead of the point. If you ever want to to find the center point (which you'll probably never need), you can use the GIS function STCentroid.Other implementations
As a side note, this type of query is done with
ST_DWithin in PostGIS and will run on the index.Code Snippets
...
dbo.myPOI2 ON myTable.geog.STDistance(myPOI2.geog) <= POI2.Point_RadiusON myTable.geog.STIntersects(myPOI.geog.STBuffer(PP.Point_Radius)) = 1Context
StackExchange Database Administrators Q#220585, answer score: 2
Revisions (0)
No revisions yet.