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.

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.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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