gdal
gdal copied to clipboard
Invalid nodata value in gdal_rasterize when output is int64
What is the bug?
When converting a shape to a raster using gdal_rasterize, we notice that the wrong nodata value is used if the datatype is int64. The issue did not exist in gdal 3.2.2, and is present in 3.6 ->current master It seems no conincidence that this arrived after the support for int64 as a datatype
Steps to reproduce the issue
The command below returns incorrect nodata value (-9999) when inspecting the file
gdal_rasterize -q -a_nodata -9999.0 -at -a NR -of GTiff -te 250000.0 161520.0 250600.0 161840.0 -tr 20.0 20.0 gdal-testfile.shp output64.tif
The nodata value used inside the grid is 0 instead of -9999 . We expect only one value (1438) in the statistics.
gdalinfo output64.tif -stats
....
Band 1 Block=30x16 Type=Int64, ColorInterp=Gray
Minimum=0.000, Maximum=1438.000, Mean=257.642, StdDev=551.461
NoData Value=-9999
Metadata:
STATISTICS_MINIMUM=0
STATISTICS_MAXIMUM=1438
STATISTICS_MEAN=257.64166666667
STATISTICS_STDDEV=551.46123006417
STATISTICS_VALID_PERCENT=100
Forcing output to be Int32 fixes this:
gdal_rasterize -q -a_nodata -9999.0 -at -a NR -of GTiff -te 250000.0 161520.0 250600.0 161840.0 -tr 20.0 20.0 gdal-testfile.shp output32.tif -ot Int32
[testcase-gdal.zip](https://github.com/user-attachments/files/15984721/testcase-gdal.zip)
gdalinfo output32.tif -stats
Band 1 Block=30x16 Type=Int32, ColorInterp=Gray
Minimum=1438.000, Maximum=1438.000, Mean=1438.000, StdDev=0.000
NoData Value=-9999
Metadata:
STATISTICS_MINIMUM=1438
STATISTICS_MAXIMUM=1438
STATISTICS_MEAN=1438
STATISTICS_STDDEV=0
STATISTICS_VALID_PERCENT=17.92
Versions and provenance
GDAL 3.10.0dev-de5a7f8c70, released 2024/06/25 (debug build)
Additional context
No response
Adding testcase files testcase-gdal.zip
By the documentation https://gdal.org/programs/gdal_rasterize.html the default output type is Float64, not Int64. Forcing the utility to use the default yields correct result. So the issue seems to be limited to Int64 output, and the biggest bug is probably the changed default datatype.
gdal_rasterize -q -a_nodata -9999.0 -at -a NR -of GTiff -te 250000.0 161520.0 250600.0 161840.0 -tr 20.0 20.0 gdal-testfile.shp output64f.tif -ot Float64
I have checked and indeed when running in gdal 3.2.2 (debian bullseye, which was our reference) without any specification we get Type=Float64.