In executing gdalwarp on an RGB TIFF to clip out an extent, the output TIFF changes values of 0 within a band to NoData. I cannot find anything explicitly referencing this scenario. Is there a flag to keep the 0's?

gdal_warp_str = '{gdalwarp_path}.exe ' \
                '-dstnodata -9999 ' \
                '-wo NUM_THREADS=ALL_CPUS ' \
                '-co NUM_THREADS=ALL_CPUS ' \
                '-q -te {georeferenced_extents} ' \
                '{input_raster_path} {output_raster_path}'

1 Answer 1


Since the TIFF is RGB, its data type is probably Byte, that is, it only accepts integer pixel values between 0 and 255.

Since you are not changing the data type of the output, that would be the reason why your -dstnodata -9999 parameter is not taken into account.

The solution for the nodata tag not being set to zeros could be to specify a value between 1 and 255 as nodata for the output bands, but since they all will be valid color combinations, there will always be one color that becomes transparent.

The best way to resolve transparency in RGB images is to define a fourth band that works as a transparency band, which is called an alpha band. This is achieved using the parameter -dstalpha.

In addition to using the -dstalpha parameter you should either remove the -dstnodata -9999 parameter or include -dstnodata None.

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.