I have in input a single band 2 axis tif raster (float32 values). Using gdal_calc I need to produce an output raster (same dimensions of input) that contains in every pixel the mean value of the whole input raster (to be used in other calculation) - basically a "uniform" raster. To do this I use:

gdal_calc.py    --calc="mean(A,dtype=float64)"  --type="Float32"    --overwrite --NoDataValue=-32768    --outfile   output.tif  -A  input.tif

Based on

gdalinfo -stats input.tif

I get a mean of 0.45 approx. So I was expecting an output.tif with this value for every pixel, but what I get is a different image (constant horizontally but different values vertically). I tried several numpy.mean parameters (axis, keepdims) but nothing changed.

Any suggestion or work around?

  • 1
    this is probably due to streaming (memory handling per stripe). A workaround would be to use computestatistics and create a new band using the python wrapping of GDAL. – radouxju Jun 20 '18 at 10:24

try --calc="mean(A,dtype=float64,axis=0)"

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.