-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 overview selection issue due to numerical instability #10873
Comments
I cannot judge if your suggestion is good, but if you want to be sure about what overview level gdalwarp takes it is best to define it with |
I confirm I get a consistent result if I pass the overview to use with |
…views Fixes OSGeo#10873 Uniformize logic with the one of GDALBandGetBestOverviewLevel2()
…views Fixes #10873 Uniformize logic with the one of GDALBandGetBestOverviewLevel2()
What is the bug?
Summary
When reprojecting a file using
gdalwarp
, the overview selected can unexpectedly change by slightly shifting the output window. This results in visible differences in the output image, as lower resolution overviews might be chosen.Example
Consider the following example, where the same input file produces different output with a small shift in the target extent
gdalwarp -of PNG -ts 256 256 -t_srs "+proj=eqc +a=2439700 +b=2439700 +lon_0=0.000000 +lat_0=0.000000 +no_defs +x_0=0 +y_0=0" -te -3481372.584110 1173100.739750 -2713372.607150 1941100.716710 -overwrite test.tif out1.png
This selects the second overview.

shifting a little bit the extent
gdalwarp -of PNG -ts 256 256 -t_srs "+proj=eqc +a=2439700 +b=2439700 +lon_0=0.000000 +lat_0=0.000000 +no_defs +x_0=0 +y_0=0" -te -3484372.584010 1173100.739750 -2716372.607050 1941100.716710 -overwrite test.tif out2.png
This selects the first, higher resolution overview

Source problem and suggested fix
Upon debugging, I found the problem is due to numeric instability when checking ratio between the desired resolution and the available overviews. Specifically in the
GDALWarpDirect
there is a comparison for selecting the right overview.Relevant lines of code: GDALWarpDirect
Using an epsilon to stabilize the ratio checks seems to fix the issue. For example
You can reproduce the issue using the following test file: https://files.actgate.com/temp/test.tif
Steps to reproduce the issue
gdalwarp -of PNG -ts 256 256 -t_srs "+proj=eqc +a=2439700 +b=2439700 +lon_0=0.000000 +lat_0=0.000000 +no_defs +x_0=0 +y_0=0" -te -3481372.584110 1173100.739750 -2713372.607150 1941100.716710 -overwrite test.tif out1.png
gdalwarp -of PNG -ts 256 256 -t_srs "+proj=eqc +a=2439700 +b=2439700 +lon_0=0.000000 +lat_0=0.000000 +no_defs +x_0=0 +y_0=0" -te -3484372.584010 1173100.739750 -2716372.607050 1941100.716710 -overwrite test.tif out2.png
Versions and provenance
3.9.2
Additional context
No response
The text was updated successfully, but these errors were encountered: