[Proj] geod C library?

Evan Miller emmiller at gmail.com
Tue Nov 30 15:58:14 EST 2010


Thanks for the ideas. I ended up using libproject:

http://home.comcast.net/~gevenden56/proj/

The geodesic functions are not very well documented, but code like
this did the trick for a distance calculation:

	#import <project.h>

	/* WGS84 */
	PROJ_ELLIPS E;
	E.a = 6378137.0;
	E.f = 1/298.257223563;
	E.es = (2 - E.f) * E.f;
	E.one_es = 1 - E.es;
	
	PROJ_PT_LPH src_pt, dst_pt;
	src_pt.h = 0.0;
	dst_pt.h = 0.0;
	
	PROJ_LINE L;
	L.E = &E;
	L.pt1 = &src_pt;
	L.pt2 = &dst_pt;

	src_pt.lam = /* longitude in radians */;
	src_pt.phi = /* latitude in radians */;

	dst_pt.lam = /* longitude in radians */;
	dst_pt.phi = /* latitude in radians */;

	proj_ginverse(&L);

	/* Distance now in L.S, azimuths in L.az12 and L.az21 */

On Tue, Nov 30, 2010 at 2:46 PM, Karney, Charles <ckarney at sarnoff.com> wrote:
>
> > From: Evan Miller [emmiller at gmail.com]
> > Sent: Tuesday, November 30, 2010 10:26
> >
> > I am looking for the functionality provided by "geod" and "invgeod"
> > (great circle calculations) wrapped up in a plain C library. I found
> > Charles Karney's Geographic Library, but that's C++.
>
> I'm not sure whether this will help you...  However a C wrapper to
> GeographicLib is a possibility.  For example:
>
> interface.cpp:
> ================================================================
> #include "GeographicLib/Geodesic.hpp"
>
> extern "C"
> void GeodInverse(double lat1, double lon1, double lat2, double lon2,
>                 double *s12, double *azi1, double *azi2) {
>    GeographicLib::Geodesic::WGS84.Inverse(lat1, lon1, lat2, lon2,
>                                           *s12, *azi1, *azi2);
>    return;
> }
> ================================================================
>
> main.c
> ================================================================
> #include <stdio.h>
>
> void GeodInverse(double lat1, double lon1, double lat2, double lon2,
>                 double *s12, double *azi1, double *azi2);
>
> int main() {
>  double lat1, lon1, lat2, lon2;
>  double s12, azi1, azi2;
>  scanf("%lf %lf %lf %lf\n", &lat1, &lon1, &lat2, &lon2);
>  GeodInverse(lat1, lon1, lat2, lon2, &s12, &azi1, &azi2);
>  printf("%.8f %.8f %.3f\n", azi1, azi2, s12);
> }
> ================================================================
>
> Makefile
> ================================================================
> test: main.o interface.o
>        g++ -o $@ $^ -lGeographic -Wl,--rpath -Wl,/usr/local/lib
> main.o: main.c
>        gcc -c $^
> interface.o: interface.cpp
>        g++ -c $^
> ================================================================
>
> make test
> echo 1 2 3 4 | ./test
> 45.14416881 45.21398561 313705.445
>
> --
> Charles Karney <ckarney at sarnoff.com>
> Sarnoff Corporation, Princeton, NJ 08543-5300
>
> Tel: +1 609 734 2312
> Fax: +1 609 734 2662
>
>
>
> This message (and any attachments) contains Sarnoff proprietary information. Such information may be subject to the terms of confidentiality or other agreements. If you are not the named addressee, you should not disseminate, distribute, or copy this email. If you have received this email by mistake, please notify the sender immediately by email and delete this email from your system. If you are not the intended recipient, you are notified that disclosing, copying, distributing, or taking any action in reliance on the contents of this information is strictly prohibited.



--
Evan Miller
http://www.evanmiller.org/


More information about the Proj mailing list