From 028f6322942aa45883933cf93886ef55365c1cc1 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 12 Aug 2024 09:57:29 +0200 Subject: [PATCH] gdallocationinfo: in -E echo mode, always report input coordinates, not pixel,line --- apps/gdallocationinfo.cpp | 4 +++- autotest/utilities/test_gdallocationinfo.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/gdallocationinfo.cpp b/apps/gdallocationinfo.cpp index e81b08c5e8b8..ff2bf26ccad9 100644 --- a/apps/gdallocationinfo.cpp +++ b/apps/gdallocationinfo.cpp @@ -342,6 +342,8 @@ MAIN_START(argc, argv) while (inputAvailable) { int iPixel, iLine; + const double dfXIn = dfGeoX; + const double dfYIn = dfGeoY; if (hCT) { @@ -411,7 +413,7 @@ MAIN_START(argc, argv) } else if (bEcho) { - printf("%d%s%d%s", iPixel, osFieldSep.c_str(), iLine, + printf("%.15g%s%.15g%s", dfXIn, osFieldSep.c_str(), dfYIn, osFieldSep.c_str()); } diff --git a/autotest/utilities/test_gdallocationinfo.py b/autotest/utilities/test_gdallocationinfo.py index 0b64f4c19333..a24f8f55c1f7 100755 --- a/autotest/utilities/test_gdallocationinfo.py +++ b/autotest/utilities/test_gdallocationinfo.py @@ -255,6 +255,20 @@ def test_gdallocationinfo_echo(gdallocationinfo_path): ) assert "1,2,132" in ret + ret = gdaltest.runexternal( + gdallocationinfo_path + + ' -geoloc -E -valonly -field_sep "," ../gcore/data/byte.tif', + strin="440780.5 3751200.5", + ) + assert "440780.5,3751200.5,132" in ret + + ret = gdaltest.runexternal( + gdallocationinfo_path + + ' -geoloc -E -valonly -field_sep "," ../gcore/data/byte.tif', + strin="440780.5 3751200.5 extra_content", + ) + assert "440780.5,3751200.5,132,extra_content" in ret + ############################################################################### # Test out of raster coordinates