Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdalwarp -ovr {absolute_value} doesn't influence choice of output resolution #10174

Closed
rouault opened this issue Jun 10, 2024 · 4 comments · Fixed by #10193
Closed

gdalwarp -ovr {absolute_value} doesn't influence choice of output resolution #10174

rouault opened this issue Jun 10, 2024 · 4 comments · Fixed by #10193
Assignees

Comments

@rouault
Copy link
Member

rouault commented Jun 10, 2024

Cf https://lists.osgeo.org/pipermail/gdal-dev/2024-June/059079.html

gdalwarp -ovr 0 -overwrite input.tif output.tif should take into account the resolution of the 1st overview level of the input dataset to compute the output dataset

@jratike80
Copy link
Collaborator

Probably only when -ts or -tr are not defined, like in the example command.

@rouault
Copy link
Member Author

rouault commented Jun 10, 2024

Probably only when -ts or -tr are not defined, like in the example command.

yes

@elpaso elpaso self-assigned this Jun 11, 2024
@elpaso
Copy link
Collaborator

elpaso commented Jun 11, 2024

I had a look to the issue, first of all there here is a failing test case:

diff --git a/autotest/utilities/test_gdalwarp.py b/autotest/utilities/test_gdalwarp.py
index df8cb2d65b..d9c6cf9f1f 100755
--- a/autotest/utilities/test_gdalwarp.py
+++ b/autotest/utilities/test_gdalwarp.py
@@ -1113,6 +1113,14 @@ def test_gdalwarp_40(gdalwarp_path, tmp_path):
     assert ds.GetRasterBand(1).Checksum() == cs_ov0
     ds = None
 
+    # Should select overview 0
+    gdaltest.runexternal(f"{gdalwarp_path} {src_tif} {dst_tif} -overwrite -ovr 0")
+
+    ds = gdal.Open(dst_tif)
+    assert ds.GetRasterBand(1).Checksum() == cs_ov0
+    ds = None
+
+

What happens here is that the output raster resolution is calculated from the input raster without taking care of the specified overview (this does not happen with -oo OVERVIEW_LEVEL=0 because in that case the overview level is applied to the input raster before entering the logic that tries to calculate the output resolution, so what the internal function "sees" is already the resolution of the selected overview.

Now I am struggling to find what is the best solution without breaking the API (GDALSuggestedWarpOutput2 is exposed) and without duplicating a lot of code.

The logic which determines the resolution based on the overview level is deep inside GDALWarpDirect and it would need to be replicated for the input raster in the main function of the binary or the overview level should be passed as an additional argument to GDALSuggestedWarpOutput2.

@rouault
Copy link
Member Author

rouault commented Jun 11, 2024

isn't it a matter of moving code a bit inside GDALWarpDirect() so that the call to CreateOutput() done at line 2507 works on the poSrcOvrDS compute at line 2854 instead of the original pahSrcDS[] ?
Or perhaps simpler, in CreateOutput(), if psOptions->nOvLevel >= 0, use the result of GDALCreateOverviewDataset(pahSrcDS[i], psOptions->nOvLevel, /* bThisLevelOnly = */ true) instead of pahSrcDS[i] ?

elpaso added a commit to elpaso/gdal that referenced this issue Jun 11, 2024
Fix OSGeo#10174 -ovr {absolute_value} doesn't influence choice of output resolution
elpaso added a commit to elpaso/gdal that referenced this issue Jun 12, 2024
Fix OSGeo#10174 -ovr {absolute_value} doesn't influence choice of output resolution
elpaso added a commit to elpaso/gdal that referenced this issue Jun 12, 2024
Fix OSGeo#10174 -ovr {absolute_value} doesn't influence choice of output resolution
elpaso added a commit to elpaso/gdal that referenced this issue Jun 12, 2024
Fix OSGeo#10174 -ovr {absolute_value} doesn't influence choice of output resolution
elpaso added a commit to elpaso/gdal that referenced this issue Jun 12, 2024
Fix OSGeo#10174 -ovr {absolute_value} doesn't influence choice of output resolution
rouault pushed a commit that referenced this issue Jun 12, 2024
Fix #10174 -ovr {absolute_value} doesn't influence choice of output resolution
rouault pushed a commit that referenced this issue Jun 12, 2024
Fix #10174 -ovr {absolute_value} doesn't influence choice of output resolution
rouault added a commit that referenced this issue Jun 12, 2024
Fix #10174 -ovr {absolute_value} doesn't influence choice of output resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants