开发者

Zip Code Radius Search

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?


@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 ?


If you accept that the Earth is a perfect sphere, you can obtain the spatial coordinates of a point by

x = R.cos(Lat).cos(Long)
y = R.cos(Lat).sin(Long)
z = R.sin(Lat)

Now, take two points and compute the angle they form with the center of the Earth (using a dot product):

cos(Phi) = (x'.x" + y'.y" + z'.z") / R²

(the value of R gets simplified).

In your case, the angular distance, Phi, equals 2Pi.D/R. (R=6 378.1 km).

A point P" is inside the ground distance (D) of P' when the dot product is larger than cos(Phi).

CAUTION: all angles must be in radians.


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜