Reputation: 99
I'm trying to figure out, on a theoretical basis, how to find the closest points to a single point. All of these points (75,000+ points) are mapped out with latitude and longitude. The Haversine formula for distance is what I'm using to find the distance between two points, but does this formula scale on the fly?
I'm using a web front end + SQL Server backend. I can't even begin to imagine how to do this... find all distances on the fly then sort them based on distance? Again, I'm wondering if this scales to as many points as I have.
Upvotes: 1
Views: 729
Reputation: 2803
This article goes into detail about this exact subject.
The main optimization is using an index on lat/long. If you know that there must be a point within some distance of your query, you can use that known distance to only check points within that box. Because of the index, the database does a range scan.
Upvotes: 2
Reputation: 4310
I assume you have lat and long in an SQL database.
The best you can do with a problem like this is just to find all distances and sort them by value.
SELECT (haversine formula) as distance FROM table ORDER BY distance ASC
Upvotes: 1