0

I have a raster containing NULL values in which I'd like filled

To do so, I have interpolated the raster via IDW in GDAL, and then used the QGIS raster calculator to perform the following calculation

(Original = 0) * Interpolated + (Original != 0) * Original

Basically, where there are data values of 0 in the original raster, replace them with the interpolated values. But if the the original rasters data values are anything other than 0 then keep the original value.

This runs perfectly in QGIS with no complaints and creates my new raster. So I decided to try it in GDAL using gdal_calc

gdal_calc -A original.tif -B interpolated.tif --outfile newraster.tif --calc="(-a = 0) * -b + (-a != 0) * -a"

However, I keep getting the error Error! Dimensions of file interpolated.tif (4138, 4902) are different from other files (7347, 8705). Cannot proceed

Even with adding the --extent=ignore flag it wont work

1 Answer 1

0

See the documentation https://gdal.org/programs/gdal_calc.html

Note that all files must have the same dimensions (unless extent option is used), but no projection checking is performed (unless projectionCheck option is used).

and

--extent= New in version 3.3.

This option determines how to handle rasters with different extents. This option is mutually exclusive with the projwin option, which is used for providing a custom extent.

For all the options below the pixel size (resolution) and SRS (Spatial Reference System) of all the input rasters must be the same.

ignore (default) - only the dimensions of the rasters are compared. if the dimensions do not agree the operation will fail.

fail - the dimensions and the extent (bounds) of the rasters must agree, otherwise the operation will fail.

union - the extent (bounds) of the output will be the minimal rectangle that contains all the input extents.

intersect - the extent (bounds) of the output will be the maximal rectangle that is contained in all the input extents.

So the option --extent ignore is the default behavior and because 4138, 4902 is not equal to 7347, 8705 then gdal_calc will not run.

What options you have depends on the coordinate system and pixel size of your original files. Could you add that info into your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.