I have to do a bilinear interpolation on an image with two no data values, using the utility gdalwarp of GDAL (http://www.gdal.org/gdalwarp.html), so these two values shouldn't be considered in interpolation. How can I do this? I evaluated the gdalwarp options "-srcnodata" and "-dstnodata", but they specify several no data values, with each value corresponding to one band. The case of my image is different, because I have only one band with multiple no data values.

2 Answers 2


If disk space and processing time aren't a major concern, then you could use gdal_calc.py to pre-process your data before gdalwarp. Create an intermediate file that has only one no-data value by converting one of the two no-data values to be the same as the other.

Suppose, for example, that your no-data values are 0 and 17. Then you might do something like this:

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A!=17)"

Whenever the pixel value is 17, the expression A!=17 is 0, so those values get set to 0. Otherwise it's 1, so it'll leave the other values alone.

If 0 is not a no-data value in your dataset, you'll have to be a bit more clever with your calc expression.


I have recently came across the same issue. For example, in one raster data, I have two nodata values: 1.7976931348623157e+308 3.4028234663852886e+38

I used gdalwarp to set them to a unified nodata value: gdalwarp -srcnodata 3.4028234663852886e+38 -dstnodata 1.7976931348623157e+308 input.tif output.tif

Similarly, you can reset multiple nodata values (e.g. a, b, and c) to one unified nodata value (c) by running gdalwarp multiple times:

gdalwarp -srcnodata a -dstnodata c input.tif intermediate.tif gdalwarp -srcnodata b -dstnodata c intermediate.tif output.tif


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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