From 613baf982c3d14ab4ebce2e754043f193f0c56fa Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 13 Apr 2016 22:54:36 +0200 Subject: Converted Compact Miller projection --- src/PJ_comill.c | 133 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 31 deletions(-) (limited to 'src/PJ_comill.c') diff --git a/src/PJ_comill.c b/src/PJ_comill.c index ad9914d4..f84f4eb0 100644 --- a/src/PJ_comill.c +++ b/src/PJ_comill.c @@ -1,13 +1,14 @@ /* -The Compact Miller projection was designed by Tom Patterson, US National -Park Service, in 2014. The polynomial equation was developed by Bojan -Savric and Bernhard Jenny, College of Earth, Ocean, and Atmospheric +The Compact Miller projection was designed by Tom Patterson, US National +Park Service, in 2014. The polynomial equation was developed by Bojan +Savric and Bernhard Jenny, College of Earth, Ocean, and Atmospheric Sciences, Oregon State University. Port to PROJ.4 by Bojan Savric, 4 April 2016 */ #define PJ_LIB__ -#include +#include + PROJ_HEAD(comill, "Compact Miller") "\n\tCyl., Sph."; #define K1 0.9902 @@ -19,41 +20,111 @@ PROJ_HEAD(comill, "Compact Miller") "\n\tCyl., Sph."; #define EPS 1e-11 #define MAX_Y (0.6000207669862655 * PI) -FORWARD(s_forward); /* spheroid */ - double lat_sq; - lat_sq = lp.phi * lp.phi; - xy.x = lp.lam; - xy.y = lp.phi * (K1 + lat_sq * (K2 + K3 * lat_sq)); - return (xy); +static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ + XY xy = {0.0,0.0}; + double lat_sq; + + lat_sq = lp.phi * lp.phi; + xy.x = lp.lam; + xy.y = lp.phi * (K1 + lat_sq * (K2 + K3 * lat_sq)); + return xy; } -INVERSE(s_inverse); /* spheroid */ - double yc, tol, y2, y4, f, fder; + + +static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ + LP lp = {0.0,0.0}; + double yc, tol, y2, y4, f, fder; /* 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; - } + if (xy.y > MAX_Y) { + xy.y = MAX_Y; + } else if (xy.y < -MAX_Y) { + xy.y = -MAX_Y; + } /* latitude */ - yc = xy.y; + yc = xy.y; for (;;) { /* Newton-Raphson */ - y2 = yc * yc; - f = (yc * (K1 + y2 * (K2 + K3 * y2))) - xy.y; - fder = C1 + y2 * (C2 + C3 * y2); - yc -= tol = f / fder; - if (fabs(tol) < EPS) { - break; - } - } - lp.phi = yc; + y2 = yc * yc; + f = (yc * (K1 + y2 * (K2 + K3 * y2))) - xy.y; + fder = C1 + y2 * (C2 + C3 * y2); + yc -= tol = f / fder; + if (fabs(tol) < EPS) { + break; + } + } + lp.phi = yc; /* longitude */ - lp.lam = xy.x; + lp.lam = xy.x; + + return lp; +} + +static void *freeup_new (PJ *P) { /* Destructor */ + return pj_dealloc(P); +} + +static void freeup (PJ *P) { + freeup_new (P); + return; +} + + +PJ *PROJECTION(comill) { + P->es = 0; + + P->inv = s_inverse; + P->fwd = s_forward; - return (lp); + P->pfree = freeup; + P->descr = des_comill; + + return P; } -FREEUP; if (P) pj_dalloc(P); } -ENTRY0(comill) P->es = 0; P->inv = s_inverse; P->fwd = s_forward; ENDENTRY(P) + + +#ifdef PJ_OMIT_SELFTEST +int pj_comill_selftest (void) {return 0;} +#else + +int pj_comill_selftest (void) { + double tolerance_lp = 1e-10; + double tolerance_xy = 1e-7; + + char s_args[] = {"+proj=comill +a=6400000 +lat_1=0.5 +lat_2=2"}; + + LP fwd_in[] = { + { 2, 1}, + { 2,-1}, + {-2, 1}, + {-2,-1} + }; + + XY s_fwd_expect[] = { + {223402.144255274179, 110611.859089458536}, + {223402.144255274179, -110611.859089458536}, + {-223402.144255274179, 110611.859089458536}, + {-223402.144255274179, -110611.859089458536}, + }; + + XY inv_in[] = { + { 200, 100}, + { 200,-100}, + {-200, 100}, + {-200,-100} + }; + + LP s_inv_expect[] = { + {0.00179049310978382265, 0.000904106801510605831}, + {0.00179049310978382265, -0.000904106801510605831}, + {-0.00179049310978382265, 0.000904106801510605831}, + {-0.00179049310978382265, -0.000904106801510605831}, + }; + + 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); +} + + +#endif -- cgit v1.2.3 From 2d14c6a55bbc69560d71a42aec44e5cbd597ca7f Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Thu, 14 Apr 2016 20:38:26 +0200 Subject: Removed superfluous declarations in PROJECTION --- src/PJ_comill.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/PJ_comill.c') diff --git a/src/PJ_comill.c b/src/PJ_comill.c index f84f4eb0..1d88dbd5 100644 --- a/src/PJ_comill.c +++ b/src/PJ_comill.c @@ -78,9 +78,6 @@ PJ *PROJECTION(comill) { P->inv = s_inverse; P->fwd = s_forward; - P->pfree = freeup; - P->descr = des_comill; - return P; } -- cgit v1.2.3 From 147885200d7c0474a59b03224848a87b77bef917 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Thu, 14 Apr 2016 21:07:50 +0200 Subject: Minor cleanups of PJ_c... A few cases of mixed declarations and code cleaned up, a few unused parameter warnings eliminated --- src/PJ_comill.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/PJ_comill.c') diff --git a/src/PJ_comill.c b/src/PJ_comill.c index 1d88dbd5..6bccb264 100644 --- a/src/PJ_comill.c +++ b/src/PJ_comill.c @@ -25,6 +25,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ XY xy = {0.0,0.0}; double lat_sq; + (void) P; /* silence unused parameter warnings */ + lat_sq = lp.phi * lp.phi; xy.x = lp.lam; xy.y = lp.phi * (K1 + lat_sq * (K2 + K3 * lat_sq)); @@ -34,7 +36,9 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ LP lp = {0.0,0.0}; - double yc, tol, y2, y4, f, fder; + double yc, tol, y2, f, fder; + + (void) P; /* silence unused parameter warnings */ /* make sure y is inside valid range */ if (xy.y > MAX_Y) { -- cgit v1.2.3