Given a database of GPS points, a center GPS location, and a radius R (in meters), how can I find all points in the database that are within a distance of R of the center point? Will the distance iso-lines be an ellipse?
-
2By definition, distance isolines are circles. In the sense that all circles are special cases of ellipses, the answer to your last question is "yes." More significantly, these isolines may appear as ellipses (or even more distorted shapes) when drawn on a map, depending on the projection and the magnitudes of the distances. For smallish distances (often 1000 km or less), the isolines will be extremely close to circular on any map using a conformal projection.– whuberCommented Feb 29, 2012 at 16:48
-
1Please consider indicating (by means of a tag or within the question itself or both) what software you intend to use.– whuberCommented Feb 29, 2012 at 16:49
-
2@whuber the queries would be over small distances (likely in the range: 10m - 10km). I'm implementing my own software, so I'd like to understand the specific equations I'd need in order to compute distances and convert distances in 'meters' (from a given location) back into GPS coordinates.– NickCommented Feb 29, 2012 at 16:56
-
1Nick, how accurate do the formulas need to be and in what coordinates are the GPS points recorded? How many points are involved? What database is being used? Unless you have unusual needs, it is possible your question is already answered on this site. A search on distance and formula might do the trick.– whuberCommented Feb 29, 2012 at 17:03
-
1Nick, The fist step for this problem is to perform the conversion (projection) between coordinate systems (lat/lon <-> m). Are you sure that you want to implement that yourself? There are good libraries available that do that for you and the distance calculation also, see OGR/GDAL.– PabloCommented Feb 29, 2012 at 18:46
3 Answers
For such short distances and since you are doing the coding yourself, the flat earth equations would probably be a good enough approximation but it depends on your accuracy requirements.
Compute the distance from latp,lonp to lat1/lon1 via the equirectangular projection:
p1 = (lonp - lon1) cos ( 0.5*(latp+lat1) ) //convert lat/lon to radians
p2 = (latp - lat1)
distance = EarthRadius * sqrt( p1*p1 + p2*p2)
use EarthRadius = 6371000 meters and your distance will be in meters
Latp/Lonp will be your reference lat/lon (in radians!). Lat1/Lon1 will be the point you are testing. Once you have distance, it is an easy test to determine if the point lies within your circle.
Reference: section Equirectangular approximation at the site: http://www.movable-type.co.uk/scripts/latlong.html
Vincenty's formulae devised by Thaddeus Vincenty is also worth it.
You can head to the page entitled Vincenty formula for distance between two Latitude/Longitude points.
Other implementations:
For a spherical earth I have found that the formulas in the Aviation Formulary. For the distances you are working these distance calculations are more than adequate.
Unless of course your GIS package includes these calculations, or tools to select by buffering and intersecting.