aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHouder <74594217+Houder@users.noreply.github.com>2020-11-28 13:45:06 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-11-28 13:47:57 +0100
commit54616dbd346518e5718e3b5b2fd31f23f9a9468a (patch)
tree9e0162e0ce0e68c59dd1b3ebcc12071ab3d0f0a7 /src
parentf0ef1b95e3207d0e81b88529e42ce65c8b4bd764 (diff)
downloadPROJ-54616dbd346518e5718e3b5b2fd31f23f9a9468a.tar.gz
PROJ-54616dbd346518e5718e3b5b2fd31f23f9a9468a.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')
-rw-r--r--src/apps/cct.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp
index acd89404..d76ab60a 100644
--- a/src/apps/cct.cpp
+++ b/src/apps/cct.cpp
@@ -393,9 +393,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,