diff options
| author | Houder <74594217+Houder@users.noreply.github.com> | 2020-11-28 13:45:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-28 13:45:06 +0100 |
| commit | 24c74a4d1cead8df41a7f22c8f28b1bf9e884de9 (patch) | |
| tree | 623a84d60ae247acb48d72cd5b8d674a3342a98a /src/apps | |
| parent | 5283d926f7c6a255c9046bc9ffbd6a48fce1600c (diff) | |
| download | PROJ-24c74a4d1cead8df41a7f22c8f28b1bf9e884de9.tar.gz PROJ-24c74a4d1cead8df41a7f22c8f28b1bf9e884de9.zip | |
Use same arguments to printf format string for both radians and degrees in output by cct (#2453)
Currently the output of the cct utility is different between radians
and degrees (as expected by cct), because of a bug in cct:
$ printf "1 2\n" | cct -z 0 -t 0 +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad
1.0000000000 2.0000000000 0.0000 0.0000
$ printf "1 2\n" | cct -z 0 -t 0 +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=deg
1.0000 2.0000 0.0000 0.0000
The arguments to the printf format string are as follows:
* radians: width 14, precision 10
* degrees: width 13, precision 4 (this is by mistake. bug!)
After the suggested fix has been applied, output will be the same for
both radians and degrees:
$ printf "1 2\n" | cct -z 0 -t 0 +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad
1.0000000000 2.0000000000 0.0000 0.0000
$ printf "1 2\n" | cct -z 0 -t 0 +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=deg
1.0000000000 2.0000000000 0.0000 0.0000
The cause of the bug is that cct does test if it "has radians to output",
but "neglects" to test if it "has degrees to output", resulting in using
different arguments to the printf format string in the latter case.
The fix makes cct test if it "has either radians or degrees to output".
Diffstat (limited to 'src/apps')
| -rw-r--r-- | src/apps/cct.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index ebfa6a23..4f21f10a 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -458,9 +458,14 @@ int main(int argc, char **argv) { comment_delimiter = (comment && *comment) ? whitespace : blank_comment; /* Time to print the result */ - if (proj_angular_output (P, direction)) { - point.lpzt.lam = proj_todeg (point.lpzt.lam); - point.lpzt.phi = proj_todeg (point.lpzt.phi); + /* use same arguments to printf format string for both radians and + degrees; convert radians to degrees before printing */ + if (proj_angular_output (P, direction) || + proj_degree_output (P, direction)) { + if (proj_angular_output (P, direction)) { + point.lpzt.lam = proj_todeg (point.lpzt.lam); + point.lpzt.phi = proj_todeg (point.lpzt.phi); + } print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f%s%s", decimals_angles, point.xyzt.x, decimals_angles, point.xyzt.y, |
