<div dir="ltr"><br><br>On Wed, Jun 13, 2018 at 11:03 PM, Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> wrote:<br>><br>> On mercredi 13 juin 2018 22:14:07 CEST Markus Metz wrote:<br>> > Many raster bands contain nodata, therefore it would be helpful if the<br>> > number of non-nodata grid cells could be reported by gdalinfo in some way.<br>> ><br>> > The number of non-nodata grid cells is not available through<br>> > GDALGetRasterStatistics() / GDALRasterBand::GetStatistics(), probably<br>> > because approximations can be stored as raster band statistics, and the<br>> > number of non-nodata grid cells is unknown in case of approximations.<br>> ><br>> > Therefore I suggest to report the number of non-nodata grid cells only if<br>> > all grid cells are evaluated, i.e. with<br>> ><br>> > *gdalinfo -mm* Force computation of the actual min/max values for each band<br>> > in the dataset.<br>> ><br>> > The number of non-nodata grid cells would be a small piece of quite useful<br>> > information to quickly evaluate the usefulness of a raster band.<br>> ><br>> > Asking for the possibility to enhance a bit the output of gdalinfo,<br>><br>> Markus,<br>><br>> That would be more something triggered by -stats since this number of non-<br>> nondata cells is an intermediate result of GDALRasterBand::ComputeStatistics()<br>> in gcore/gdalrasterband.cpp. To make it sensical even in the case of<br>> approximate statistics, why not computing a percentage instead ? That would<br>> need to be saved in a metadata item, let's say STATISTICS_VALID_RATIO (between<br><div>> 0 and 1) ?</div><div><br></div><div>Considering approximate statistics, something like  STATISTICS_VALID_RATIO would make sense.</div><div><br></div><div>However, I am not interested in approximate statistics, therefore my suggestion to tie it to -mm.<br></div><div><br></div><div>> Wanna take a crack at implementing this ?</div><div><br></div><div>Too many API changes required, starting with GDALGetRasterStatistics(), GDALComputeRasterStatistics() and all else following. There must be an easier solution. But thanks for your offer:-)<br></div><div><br></div><div>My workaround is to use GRASS r.external to get correct raster band statistics.<br></div><div><br></div><div>> Otherwise file an</div>> enhancement ticket about that.<br>> By the way, since GDAL 2.3.0, there's a STATISTICS_APPROXIMATE=YES metadata<br>> item so as to know if the stats have been computed in an approx way or not<br><div><br></div><div>Enhancement request: set STATISTICS_APPROXIMATE=UNKNOWN if it is unknown. I checked with some externally provided sample data and GDAL 2.3.0 does not report STATISTICS_APPROXIMATE.</div><div><br></div><div>I understand that GDAL has to cater for approximate statistics and should not override metadata provided with raster bands created by other software. It would help if STATISTICS_APPROXIMATE is always set to NO|YES|UNKNOWN.<br></div><div><br></div><div>Markus<br></div><br></div>