I've a database (MySQL) of geographic (lat, long) points and I need to query a list of points from one rectangle (which have 2 coordinates for each vertex). Is there any query or algorithm to resolve this problem fast.
Thanks.
I've a database (MySQL) of geographic (lat, long) points and I need to query a list of points from one rectangle (which have 2 coordinates for each vertex). Is there any query or algorithm to resolve this problem fast.
Thanks.
assuming that your lat/long points are indexed, then any SQL query will be pretty fast
SELECT point.lat, point.long FROM point where rect1.lat <= point.lat and point.lat <= rect2.lat and rect1.long <= point.long and point.long <= rect2.long
rect1.lat/rect1.long and rect2.lat/rect2.long are the lat/long of the north western most and south eastern most location.
I am hoping that you are storing lat/long for both your Points and rectangles as positive and negative (rather than E/W N/S) - if you have then as E/W and N/S the query will be much more complicated.
This also assumes that the rectangle is such that the entire edge track along a line of lattitude/longtitude.
To be honest this one is so simple I guess I am missing something....