From 1c743de193f43f818635235d60330e78dbd4cd96 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 5 Sep 2017 13:13:52 +0200 Subject: proj: Do rad->deg conversion if output units warrants it. With the introduction of transformation pipelines it is possible to create a pipeline that has degrees as it's output unit. If that is the case the output coordinate will be in radians internally. This commit makes sure that a conversion to degrees is applied before printing to stdout. --- src/proj.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/proj.c b/src/proj.c index 70ca4033..aa0f07c0 100644 --- a/src/proj.c +++ b/src/proj.c @@ -143,10 +143,17 @@ static void process(FILE *fid) { putchar('\t'); (void)fputs(rtodms(pline, data.v, 'N', 'S'), stdout); } - } else { /* x-y or decimal degree ascii output */ + } else { /* x-y or decimal degree ascii output, scale if warranted by output units */ if (inverse) { - data.v *= RAD_TO_DEG; - data.u *= RAD_TO_DEG; + if (Proj->left == PJ_IO_UNITS_RADIANS || Proj->left == PJ_IO_UNITS_CLASSIC) { + data.v *= RAD_TO_DEG; + data.u *= RAD_TO_DEG; + } + } else { + if (Proj->right == PJ_IO_UNITS_RADIANS) { + data.v *= RAD_TO_DEG; + data.u *= RAD_TO_DEG; + } } if (reverseout) { @@ -177,6 +184,7 @@ static void vprocess(FILE *fid) { projUV dat_ll, dat_xy, temp; int linvers; + if (!oform) oform = "%.3f"; @@ -247,6 +255,12 @@ static void vprocess(FILE *fid) { if (postscale) { dat_xy.u *= fscale; dat_xy.v *= fscale; } } + /* apply rad->deg scaling in case the output from a pipeline has degrees as units */ + if (!inverse && Proj->right == PJ_IO_UNITS_RADIANS) { + dat_xy.u *= RAD_TO_DEG; + dat_xy.v *= RAD_TO_DEG; + } + /* For some reason pj_errno does not work as expected in some */ /* versions of Visual Studio, so using pj_get_errno_ref instead */ if (*pj_get_errno_ref()) { -- cgit v1.2.3