From a8e73a544ca446fe3579f2b300ee398bef59da28 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Thu, 20 Oct 2016 21:56:06 +0200 Subject: Fixes #138 (spherical tmerc with negative northing gives inverted latitude) --- src/PJ_tmerc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/PJ_tmerc.c b/src/PJ_tmerc.c index 0ae683bf..793f1e95 100644 --- a/src/PJ_tmerc.c +++ b/src/PJ_tmerc.c @@ -1,12 +1,12 @@ #define PJ_LIB__ -#include +#include PROJ_HEAD(tmerc, "Transverse Mercator") "\n\tCyl, Sph&Ell"; struct pj_opaque { - double esp; \ - double ml0; \ + double esp; + double ml0; double *en; }; @@ -146,7 +146,10 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ g = .5 * (h - 1. / h); h = cos (P->phi0 + xy.y / P->opaque->esp); lp.phi = asin(sqrt((1. - h * h) / (1. + g * g))); - if (xy.y < 0.) lp.phi = -lp.phi; + + /* Make sure that phi is on the correct hemisphere when false northing is used */ + if (xy.y < 0. && -lp.phi+P->phi0 < 0.0) lp.phi = -lp.phi; + lp.lam = (g || h) ? atan2 (g, h) : 0.; return lp; } -- cgit v1.2.3