0

I want to calculate max of all cells of a raster, i.e. the result should be a scalar.

Regardless of what I call amax, max, numpy.max(A, axis=0) I always get a raster with the same WxH as the original raster. I suppose I should get a single scalar value. Is this possible with gdal_calc.py?

gdal_calc.py -A 0009.TIF --calc "max(A)" --debug
gdal_calc.py -A 0009.TIF --calc "numpy.max(A, axis=0)" --debug

gdal_calc.py starting calculation numpy.max(A, axis=0)
file A: 0009.TIF, dimensions: 7800, 7900, type: UInt16
Generating output file gdal_calc.tif
output file: gdal_calc.tif, dimensions: 7800, 7900, type: UInt16
using blocksize 7800 x 1
0 .. 10 .. 20 .. 30 .. 40 .. 50 .. 60 .. 70 .. 80 .. 90 .. 100 - Done

gdalinfo gdal_calc.tif
Driver: GTiff/GeoTIFF
Files: gdal_calc.tif
Size is 7800, 7900
Coordinate System is:
PROJCS["WGS 84 / UTM zone 33N",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",15],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","32633"]]
Origin = (271485.000000000000000,4743015.000000000000000)
Pixel Size = (30.000000000000000,-30.000000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  271485.000, 4743015.000) ( 12d12'19.09"E, 42d48'20.13"N)
Lower Left  (  271485.000, 4506015.000) ( 12d17'46.77"E, 40d40'24.15"N)
Upper Right (  505485.000, 4743015.000) ( 15d 4' 1.63"E, 42d50'22.88"N)
Lower Right (  505485.000, 4506015.000) ( 15d 3'53.75"E, 40d42'18.09"N)
Center      (  388485.000, 4624515.000) ( 13d39'30.36"E, 41d45'52.71"N)
Band 1 Block=7800x1 Type=UInt16, ColorInterp=Gray
  NoData Value=65535
  • Thanks. Why gdal_calc does not report that this is not possible? This is a kind of a mismatch with numpy semantics. – Antonio Apr 6 '19 at 9:16
1

No, this is not possible with gdal_calc, use gdalinfo -stats instead and read the max value from the output.

The gdal_calc documentation states "all files must have the same dimensions", this includes the output file.

  • ` "all files must have the same dimensions" this includes the output file.` -- this should be explicitly stated in the docs – Antonio Apr 6 '19 at 9:41

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.