I regularly create my own GeoTIFF rasters with GDAL in Python, e.g.:
from osgeo import gdal from numpy import random data = random.uniform(0, 10, (300, 200)) driver = gdal.GetDriverByName('GTiff') ds = driver.Create('MyRaster.tif', 200, 300) band = ds.GetRasterBand(1) band.WriteArray(data) ds = band = None # save, close
however when the result is viewed with ArcCatalog/ArcGIS, it looks either black or grey, since it has no statistics. This is solved either by right-clicking the raster and choosing "Calculate Statistics..." in ArcCatalog (there are several other ways to do this), or using gdalinfo in a command prompt:
gdalinfo -stats MyRaster.tif
MyRaster.tif.aux.xml, which is used by ArcGIS to properly scale the raster. The PAM (Persistent Auxiliary Metadata) file contains the statistics, most notably the minimum and maximum values:
<PAMDataset> <PAMRasterBand band="1"> <Metadata> <MDI key="STATISTICS_MINIMUM">0</MDI> <MDI key="STATISTICS_MAXIMUM">10</MDI> <MDI key="STATISTICS_MEAN">5.0189833333333</MDI> <MDI key="STATISTICS_STDDEV">2.9131294111984</MDI> </Metadata> </PAMRasterBand> </PAMDataset>
My question: is there a built-in way of getting GDAL to create a statistics file (other than using the
gdalinfo -stats command)? Or do I need to write my own?