Error in gdalwarp with -sum resampling method.
What is the bug?
I have a series of GeoTIFF files in 25cm pixel size. I want to create 50cm pixel sizes where the pixel value is equal to the sum of the 4 pixels of 25cm that fall within that 50cm pixel.
But allways there is a vertical line of error. The error has 2 behaviours depending on whether the original 25cm pixels where NoData or they were valued.
1- If the original pixel was NoData, then, in the vertical line we will have very small values.
2- If the original pixels at 25cm has values, on the vertical line we will have values that are sum of only 2 pixels from the 4 pixels of 25cm. Thus, the 50cm pixel value is almost half of what it should be. (Thus, it is darker in the image!)
The strange thing is that the error happens on a vertical line. I tried it with other GeoTiff files, and sometimes instead of vertical line we have vertical band of multiple erroneous pixels.
I always have the same error but the width of it changes.
Other Geotiff files are also producing the same vertical error. If you want I can share more Geotiff files.
25e062331765_0025_density.tiff
Steps to reproduce the issue
1- Method 1
I ran this very simple command using the image of 3.10.3:
`
sudo docker run --rm
-v "/home/mmoradi/Desktop/Exported_Geotiff/density_Files:/data"
-w /data
--user $(id -u):$(id -g)
ghcr.io/osgeo/gdal:ubuntu-small-3.10.3
gdalwarp
-overwrite
-r sum
-tr 0.5 0.5
"25e062331765_0025_density.tiff"
"/data/abc__density__0.5.tiff"
`
2- Method 2
Also I tried this full command:
`
sudo docker run --rm
-v "/home/mmoradi/Desktop/Exported_Geotiff/density_Files:/data"
-w /data
--user $(id -u):$(id -g)
ghcr.io/osgeo/gdal:ubuntu-small-3.10.3
gdalwarp
-overwrite
-r sum
-tr 0.5 0.5
-et 0
-ovr NONE
-co TILED=YES
-co PREDICTOR=2
-co COMPRESS=DEFLATE
"25e062331765_0025_density.tiff"
"/data/abc__density__0.5.tiff"
`
3- method 3
I also tried tried changing the coordinate system with -tap and then resample it:
command to tap and reproject:
`
sudo docker run --rm
-v "/home/mmoradi/Desktop/Exported_Geotiff/density_Files:/data"
-w /data
--user $(id -u):$(id -g)
ghcr.io/osgeo/gdal:ubuntu-small-3.10.3
gdalwarp
-overwrite
-t_srs EPSG:3979
-r near
-tr 0.25 0.25
-tap
-et 0
-ovr NONE
-ot Float32
-co TILED=YES
-co PREDICTOR=2
-co COMPRESS=DEFLATE
"25e062331765_0025_density.tiff"
"/data/abc__density__0.25.tiff"
`
command to resample:
`
sudo docker run --rm
-v "/home/mmoradi/Desktop/Exported_Geotiff/density_Files:/data"
-w /data
--user $(id -u):$(id -g)
ghcr.io/osgeo/gdal:ubuntu-small-3.10.3
gdalwarp
-overwrite
-t_srs EPSG:3979
-r sum
-tr 0.5 0.5
-tap
-et 0
-ovr NONE
-ot Float32
-co TILED=YES
-co PREDICTOR=2
-co COMPRESS=DEFLATE
"/data/abc__density__0.25.tiff"
"/data/abc__density__0.5.tiff"
`
All of these commands produce a vertical line or area of error!
Versions and provenance
I did it on Ubuntu 24.04.03 and I visualized the result in QGIS 3.44.1 I used the following versions:
I tried with gdal 3.8.4 that was installed using Ubuntu official repository. In addition, I tried it with the image of gdal 3.13 dev and also with gdal 3.10.3.
Additional context
This is the result of method 3 after clicking on the black vertical area that should have been NoData:
This is the result of method 2:
This is the result of method 1:
on the vertical line, valued pixel is just sum of 2 of pixels instead of 4 of them !!
Fix in #13541. You can workaround the issue by increasing the warp memory limit, to limit chunking, e.g. by adding "-wm 500"