Use as a standalone library (original) (raw)
The PROJ library (especially as provided as part of a Linux distribution) may lag behind the code documented here by about a year.
Download the source code from as a tarball from
or check out the source code from
Build the code with cmake
cmake -B BUILD -S . cd BUILD make make test
possibly including some options via -D
:
CONVERT_WARNINGS_TO_ERRORS
warnings are fatal (default ON)BUILD_DOCUMENTATION
look for doxgen and build documentation (default ON)BUILD_SHARED_LIBS
make a shared (instead of static) library (default ON)
CMake code to install the library is not provided.
The library consists of two files geodesic.c and geodesic.h.
Licensed under the MIT/X11 License; see LICENSE.txt.
Also included are 3 small test programs:
- direct.c is a simple command line utility for solving the direct geodesic problem;
- inverse.c is a simple command line utility for solving the inverse geodesic problem;
- planimeter.c is a simple command line utility for computing the area of a geodesic polygon given its vertices.
Here, for example, is inverse.c
#include <stdio.h>
#if defined(_MSC_VER)
# pragma warning (disable: 4996)
#endif
double a = 6378137, f = 1/298.257223563;
double lat1, lon1, azi1, lat2, lon2, azi2, s12;
while (scanf("%lf %lf %lf %lf", &lat1, &lon1, &lat2, &lon2) == 4) {
geod_inverse(&g, lat1, lon1, lat2, lon2, &s12, &azi1, &azi2);
printf("%.15f %.15f %.10f\n", azi1, azi2, s12);
}
return 0;
}
API for the geodesic routines in C.
void GEOD_DLL geod_init(struct geod_geodesic *g, double a, double f)
void GEOD_DLL geod_inverse(const struct geod_geodesic *g, double lat1, double lon1, double lat2, double lon2, double *ps12, double *pazi1, double *pazi2)
Use inverse, for example, with
echo -30 0 29.5 179.5 | ./tools/inverse