aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2016-05-01 11:59:58 +0200
committerKristian Evers <kristianevers@gmail.com>2016-05-01 11:59:58 +0200
commit3b41444bef2168f5a109e7fd69676e45a00ccda3 (patch)
treec5d81f85fa9dbf8dd7a26545e148a3dcfef73fca
parent0dc0b3aa66542bf011c85686b7b10d0cf92811a5 (diff)
downloadPROJ-3b41444bef2168f5a109e7fd69676e45a00ccda3.tar.gz
PROJ-3b41444bef2168f5a109e7fd69676e45a00ccda3.zip
Converted natearth
-rw-r--r--src/PJ_aea.c1
-rw-r--r--src/PJ_natearth.c153
2 files changed, 112 insertions, 42 deletions
diff --git a/src/PJ_aea.c b/src/PJ_aea.c
index dd0c0f48..c5480d1e 100644
--- a/src/PJ_aea.c
+++ b/src/PJ_aea.c
@@ -364,7 +364,6 @@ int pj_latlong_selftest (void) {return 10000;}
int pj_lonlat_selftest (void) {return 10000;}
int pj_longlat_selftest (void) {return 10000;}
-int pj_natearth_selftest (void) {return 10000;}
int pj_natearth2_selftest (void) {return 10000;}
int pj_nell_selftest (void) {return 10000;}
int pj_nell_h_selftest (void) {return 10000;}
diff --git a/src/PJ_natearth.c b/src/PJ_natearth.c
index 0f283415..290f8efe 100644
--- a/src/PJ_natearth.c
+++ b/src/PJ_natearth.c
@@ -12,10 +12,11 @@ where they meet the horizontal pole line. This improvement is by intention
and designed in collaboration with Tom Patterson.
Port to PROJ.4 by Bernhard Jenny, 6 June 2011
*/
-
#define PJ_LIB__
-#include <projects.h>
+#include <projects.h>
+
PROJ_HEAD(natearth, "Natural Earth") "\n\tPCyl., Sph.";
+
#define A0 0.8707
#define A1 -0.131979
#define A2 -0.013791
@@ -34,46 +35,116 @@ PROJ_HEAD(natearth, "Natural Earth") "\n\tPCyl., Sph.";
#define EPS 1e-11
#define MAX_Y (0.8707 * 0.52 * PI)
-FORWARD(s_forward); /* spheroid */
- double phi2, phi4;
- (void) P;
- phi2 = lp.phi * lp.phi;
- phi4 = phi2 * phi2;
- xy.x = lp.lam * (A0 + phi2 * (A1 + phi2 * (A2 + phi4 * phi2 * (A3 + phi2 * A4))));
- xy.y = lp.phi * (B0 + phi2 * (B1 + phi4 * (B2 + B3 * phi2 + B4 * phi4)));
- return (xy);
+static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
+ XY xy = {0.0,0.0};
+ double phi2, phi4;
+ (void) P;
+
+ phi2 = lp.phi * lp.phi;
+ phi4 = phi2 * phi2;
+ xy.x = lp.lam * (A0 + phi2 * (A1 + phi2 * (A2 + phi4 * phi2 * (A3 + phi2 * A4))));
+ xy.y = lp.phi * (B0 + phi2 * (B1 + phi4 * (B2 + B3 * phi2 + B4 * phi4)));
+ return xy;
}
-INVERSE(s_inverse); /* spheroid */
- double yc, tol, y2, y4, f, fder;
- (void) P;
-
- /* make sure y is inside valid range */
- if (xy.y > MAX_Y) {
- xy.y = MAX_Y;
- } else if (xy.y < -MAX_Y) {
- xy.y = -MAX_Y;
- }
-
- /* latitude */
- yc = xy.y;
+
+
+static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
+ LP lp = {0.0,0.0};
+ double yc, tol, y2, y4, f, fder;
+ (void) P;
+
+ /* make sure y is inside valid range */
+ if (xy.y > MAX_Y) {
+ xy.y = MAX_Y;
+ } else if (xy.y < -MAX_Y) {
+ xy.y = -MAX_Y;
+ }
+
+ /* latitude */
+ yc = xy.y;
for (;;) { /* Newton-Raphson */
- y2 = yc * yc;
- y4 = y2 * y2;
- f = (yc * (B0 + y2 * (B1 + y4 * (B2 + B3 * y2 + B4 * y4)))) - xy.y;
- fder = C0 + y2 * (C1 + y4 * (C2 + C3 * y2 + C4 * y4));
- yc -= tol = f / fder;
- if (fabs(tol) < EPS) {
- break;
- }
- }
- lp.phi = yc;
-
- /* longitude */
- y2 = yc * yc;
- lp.lam = xy.x / (A0 + y2 * (A1 + y2 * (A2 + y2 * y2 * y2 * (A3 + y2 * A4))));
-
- return (lp);
+ y2 = yc * yc;
+ y4 = y2 * y2;
+ f = (yc * (B0 + y2 * (B1 + y4 * (B2 + B3 * y2 + B4 * y4)))) - xy.y;
+ fder = C0 + y2 * (C1 + y4 * (C2 + C3 * y2 + C4 * y4));
+ yc -= tol = f / fder;
+ if (fabs(tol) < EPS) {
+ break;
+ }
+ }
+ lp.phi = yc;
+
+ /* longitude */
+ y2 = yc * yc;
+ lp.lam = xy.x / (A0 + y2 * (A1 + y2 * (A2 + y2 * y2 * y2 * (A3 + y2 * A4))));
+
+ return lp;
+}
+
+
+static void *freeup_new (PJ *P) { /* Destructor */
+ if (0==P)
+ return 0;
+
+ return pj_dealloc(P);
+}
+
+
+static void freeup (PJ *P) {
+ freeup_new (P);
+ return;
+}
+
+
+PJ *PROJECTION(natearth) {
+ P->es = 0;
+ P->inv = s_inverse;
+ P->fwd = s_forward;
+
+ return P;
+}
+
+#ifdef PJ_OMIT_SELFTEST
+int pj_natearth_selftest (void) {return 0;}
+#else
+
+int pj_natearth_selftest (void) {
+ double tolerance_lp = 1e-10;
+ double tolerance_xy = 1e-7;
+
+ char s_args[] = {"+proj=natearth +a=6400000 +lat_1=0.5 +lat_2=2"};
+
+ LP fwd_in[] = {
+ { 2, 1},
+ { 2,-1},
+ {-2, 1},
+ {-2,-1}
+ };
+
+ XY s_fwd_expect[] = {
+ { 194507.265257889288, 112508.737358294515},
+ { 194507.265257889288, -112508.737358294515},
+ {-194507.265257889288, 112508.737358294515},
+ {-194507.265257889288, -112508.737358294515},
+ };
+
+ XY inv_in[] = {
+ { 200, 100},
+ { 200,-100},
+ {-200, 100},
+ {-200,-100}
+ };
+
+ LP s_inv_expect[] = {
+ { 0.00205638349586440223, 0.000888823913291242177},
+ { 0.00205638349586440223, -0.000888823913291242177},
+ {-0.00205638349586440223, 0.000888823913291242177},
+ {-0.00205638349586440223, -0.000888823913291242177},
+ };
+
+ return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 4, fwd_in, 0, s_fwd_expect, inv_in, 0, s_inv_expect);
}
-FREEUP; if (P) pj_dalloc(P); }
-ENTRY0(natearth) P->es = 0; P->inv = s_inverse; P->fwd = s_forward; ENDENTRY(P)
+
+
+#endif