views:

65

answers:

3

I'm wondering if it's possible to find all points by longitude and latitude within X radius of one point?

So, if I provide a latitude/longitude of -76.0000, 38.0000, is it possible to simply find all the possible coordinates within (for example) a 10 mile radius of that?

I know that there's a way to calculate the distance between two points, which is why I'm not clear as to whether this is possible... Because, it seems like you need to know the center coordinates (-76 and 38 in this case) as well as the coordinates of every other point in order to determine whether it falls within the specified radius... Is that right?

A: 

Depending on the precision, the data set of points within a certain distance may be extremely large or even infinite (impossible). In a given area of a circle with a positive radius you will have infinitely many points. Thus, it is trivial to determine if a point falls within a circle, however to enumerate over all the points is impossible.

If you do set a fixed precision (such as a single digit), you can loop over all possible latitude and longitude combinations and perform the distance test.

Kevin Sylvestre
Ok... thanks for clarifying!
TwixxyKit
A: 

Kevin is correct. There is no reason to calculate every possible coordinate-pair in the radius.

If you start at the centerpoint pC = Point(-76.0000, 38.0000) and are testing to find out if arbitrary point pA = Point(Ax, Ay) is within a 10 mile radius... use the Pythagorean theorem:

xDist = abs( pCx - Ax )
yDist = abs ( pCy - Ay )
r^2 = (xDist)^2 + (yDist)^2

A reasonable approximation is to only query the points where

pAx >= (-76.0000 - 10.0000) && pAx <= (-76.0000 + 10.0000)
pAy >= ( 38.0000 - 10.0000) && pAy <= ( 38.0000 + 10.0000)

then perform the more intensive calculation above.

David
-1: the calculations are horribly confused, @David is adding (or subtracting) miles from degrees.
High Performance Mark
A: 

@David's strategy is correct, his implementation is seriously flawed. I suggest that before you perform the calculations you transform your lat,long pair to UTM coordinates and work in distance, not angular, measurements. If you are not familiar with Universal Transverse Mercator, hit Google or Wikipedia.

I reckon that your point (-76,38) is at UTM 37C 472995 (Easting) 1564346 (Northing). So you want to do your calculations of distance from that point. You'll find it easier, working with UTM, to work in metres, so your distance is (if you are using statute miles of 5280 feet) 16040 metres.

Incidentally, (-76,38) is well outside the contintental US -- does the US Post Office define zip codes for Antarctica ?

High Performance Mark