C library for Geodesics 2.2
Loading...
Searching...
No Matches
proj-example.c
Go to the documentation of this file.
1/**
2 * @file proj-example.c
3 * @brief An example of computing geodesics with the PROJ library
4 **********************************************************************/
5
6#include <stdio.h>
7#include <proj.h>
8#include <geodesic.h>
9
10int main (void) {
11 /* Compute approximately equally spaced way points between LAX, 33.94N
12 118.41W, and CHC, 43.49S 172.53E. */
13 double a, invf;
14 struct geod_geodesic g;
15 struct geod_geodesicline l;
16 const int n = 30;
17 double lat[n+1], lon[n+1], azi[n+1];
18 int i;
19 {
20 /* Use PROJ to get the ellipsoid parameters */
21 PJ_CONTEXT* C = proj_context_create();
22 char* argv[3] = {"type=crs", "proj=longlat", "ellps=WGS84"};
23 PJ* P = proj_create_argv(C, 3, argv);
24 if (P == 0) {
25 fprintf(stderr, "Failed to create transformation object.\n");
26 return 1;
27 }
28 proj_ellipsoid_get_parameters(C, proj_get_ellipsoid(C, P),
29 &a, 0, 0, &invf);
30 proj_destroy(P);
31 proj_context_destroy(C);
32 }
33 /* Initialize geodesic */
34 geod_init(&g, a, invf != 0 ? 1/invf : 0);
35 /* Don't need GEOD_DISTANCE_IN if using GEOD_ARCMODE */
36 geod_inverseline(&l, &g, 33.94, -118.41, -43.49, 172.53,
38 printf("latitude longitude azimuth\n");
39 for (i = 0; i <= n; ++i) {
40 /* Use GEOD_LONG_UNROLL so longitude varies continuously */
42 i * l.a13 / n, lat + i, lon + i, azi + i, 0, 0, 0, 0, 0);
43 printf("%.5f %.5f %.5f\n", lat[i], lon[i], azi[i]);
44 }
45 return 0;
46}
API for the geodesic routines in C.
@ GEOD_LONG_UNROLL
Definition geodesic.h:830
@ GEOD_ARCMODE
Definition geodesic.h:829
@ GEOD_AZIMUTH
Definition geodesic.h:814
@ GEOD_LONGITUDE
Definition geodesic.h:813
@ GEOD_LATITUDE
Definition geodesic.h:812
void GEOD_DLL geod_init(struct geod_geodesic *g, double a, double f)
double GEOD_DLL geod_genposition(const struct geod_geodesicline *l, unsigned flags, double s12_a12, double *plat2, double *plon2, double *pazi2, double *ps12, double *pm12, double *pM12, double *pM21, double *pS12)
void GEOD_DLL geod_inverseline(struct geod_geodesicline *l, const struct geod_geodesic *g, double lat1, double lon1, double lat2, double lon2, unsigned caps)
int main(void)