19#define TWOPI M_PI + M_PI
21#define USE_GEOGRAPHICLIB 1
24#ifndef USE_GEOGRAPHICLIB
26 double QbarA, QbarB, QbarC, QbarD;
35 struct geod_geodesic
g;
39static struct state *st = &state;
41#ifndef USE_GEOGRAPHICLIB
42static double Q(
double x)
49 return sinx * (1 + sinx2 * (st->QA + sinx2 * (st->QB + sinx2 * st->QC)));
52static double Qbar(
double x)
61 cosx2 * (st->QbarB + cosx2 * (st->QbarC + cosx2 * st->QbarD)));
77#ifdef USE_GEOGRAPHICLIB
82 f = 1.0 - sqrt(1.0 - e2);
83 geod_init(&st->g, a, f);
92 st->AE = a * a * (1 - e2);
94 st->QA = (2.0 / 3.0) * e2;
95 st->QB = (3.0 / 5.0) * e4;
96 st->QC = (4.0 / 7.0) * e6;
98 st->QbarA = -1.0 - (2.0 / 3.0) * e2 - (3.0 / 5.0) * e4 - (4.0 / 7.0) * e6;
99 st->QbarB = (2.0 / 9.0) * e2 + (2.0 / 5.0) * e4 + (4.0 / 7.0) * e6;
100 st->QbarC = -(3.0 / 25.0) * e4 - (12.0 / 35.0) * e6;
101 st->QbarD = (4.0 / 49.0) * e6;
104 st->E = 4 * M_PI * st->Qp * st->AE;
158#ifdef USE_GEOGRAPHICLIB
160 struct geod_polygon p;
164 geod_polygon_init(&p,
FALSE);
170 geod_polygon_addpoint(&st->g, &p, (
double)lat[i], (
double)lon[i]);
173 geod_polygon_compute(&st->g, &p,
FALSE,
TRUE, &area, &pP);
177 double x1, y1, x2, y2, dx, dy;
180 double thresh = 1e-6;
199 while (x1 - x2 > M_PI)
202 while (x2 - x1 > M_PI)
208 if (fabs(dy) > thresh) {
210 area += dx * (st->Qp - (Qbar2 - Qbar1) / dy);
223 area += dx * (st->Qp - Q((y1 + y2) / 2));
226 if ((area *= st->AE) < 0.0)
236 if (area > st->E / 2)
void G_begin_ellipsoid_polygon_area(double a, double e2)
Begin area calculations.
double G_ellipsoid_polygon_area(const double *lon, const double *lat, int n)
Area of lat-long polygon.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters