[Proj] geod C library?

Karney, Charles ckarney at Sarnoff.com
Tue Nov 30 11:45:29 EST 2010


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


More information about the Proj mailing list