I am looking for a free geo data class library. I need to convert different formats of Latitude / Longitude values (e.g as here), get distances between lat/lng values, coordinates in range, etc.
Google shows me several single methods / functions in C++, this is not the issue. Examples
What I am looking for is a more complete / sophisticated class library with some documentation and examples. Any hints?
-- Edit --
LatLong is such a library in Javascript: http://www.movable-type.co.uk/scripts/latlong.html
Will also check (C++): http://geographiclib.sourceforge.net/html/annotated.html
-- Edit 2 --
The transformation approach below is a good starter, however, if there are other great libs please let me know. Thanks to all who have contributed.
159): dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqrt(a), sqrt(1-a)) d = R * c will give mathematically and computationally exact results. The intermediate result c is the great circle distance in radians.
proj4 is what you're looking for. It's a serious mapping tool, mature and well respected projection api. It's predominantly popular for doing forward and backward conversion between geographical coordinates (lat/lng) and planar (x,y). Coordinate geometry with planar coordinates is much simpler than with geographical.
Documentation is not the best. Because it can also be used as a stand-alone program, I'd start off reading the man page to get an introduction. The command-line switches are the same parameters used to initialise the structure when using the api. Then read the api docs - the function calls listed under Basic API functions may very well be all you need.
Edit with what started off as a comment to OP: Projecting to planar coordinates is attractive for many reasons: Coordinate comparisons are then in linear units rather than angular. Distance becomes a trivial hypotenuse calculation. Axis-aligned rectangles are intuitive to work with. Elementary right-angled trigonometry can be used to calculate new points, e.g. midway, offset, etc. This is all provided the extents of the region is not massive, e.g. of continental scale - If your dataset is within say a degree square (that's still large) you'll be fine with this approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With