I am confused with the results of using a condition in gdal_calc. Initially I thought that gdal_calc was setting pixels to nodata where a condition is not met. In the documentation (http://www.gdal.org/gdal_calc.html) it is said that the following command sets values of zero and below to null.

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0

If I try this command:

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=-9999

The pixels where the condition is not met are set to zero.

Should I understand that the term null used in the documentation actually refers to pixels with a value of zero?

1 Answer 1


You should understand the example so that


makes all pixels with value zero or below into zero, and after that


sets the metadata to tell that zero means nodata. With you modified command the zeroes are set as before but you are telling that pixels with value -9999 are nodata, thus zeroes are not nodata. I am not sure but I suppose that if input data had originally nodata set to something else than -9999 then both the metadata and those nodata pixels would be converted into -9999.

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.