Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5805 closed enhancement (fixed)

Add command-line ability to recalculate raster statistics

Reported by: Mike Taves Owned by: warmerdam
Priority: normal Milestone: 2.0.0
Component: Utilities Version: unspecified
Severity: normal Keywords:
Cc: antonio

Description

If a raster does not have statistics, gdalinfo -stats myfile.tif can be used to calculate and add statistics. However, if values in the raster dataset are modified, further attempts to use gdalinfo -stats myfile.tif do not force recalculation of statistics, since they already exist.

One strategy would be to allow gdalinfo to force recalculation of statistics with either -stats or -approx_stats flags. (However, doesn't the the "info" part of this utility suggests that it is intended to not modify the file? Also, very minor and almost non-ticket-worthy: -approx_stats is missing from usage string in gdalinfo.c)

A second and more intuitive strategy is to add this functionality to gdal_edit. That is, add both -stats and -approx_stats flags to this utility, and call ComputeStatistics(approx_stats). Note that this utility has a related and conflicting -unsetstats option (changeset:27608) which needs to be considered.

Attachments (1)

stats.diff (6.7 KB ) - added by Mike Taves 9 years ago.
git diff --no-prefix 3fcf12b..HEAD > stats.diff

Download all attachments as: .zip

Change History (10)

comment:1 by antonio, 9 years ago

Cc: antonio added

comment:2 by Mike Taves, 9 years ago

Also noteworthy, the gdalinfo -mm flag is documented as "Force computation of the actual min/max values for each band in the dataset" (via GDALComputeRasterMinMax). However, this option does not store the new partial statistics, it only displays the information in the output beside the previously computed and stored statistics. E.g., I modified a "2" pixel to a "3", then gdalinfo -mm:

Band 1 Block=2x2 Type=Byte, ColorInterp=Gray
  Min=2.000 Max=20.000   Computed Min/Max=3.000,20.000
  Minimum=2.000, Maximum=20.000, Mean=11.750, StdDev=6.647
  Metadata:
    STATISTICS_MAXIMUM=20
    STATISTICS_MEAN=11.75
    STATISTICS_MINIMUM=2
    STATISTICS_STDDEV=6.6473679001542

In case it isn't clear, the intentions of this ticket are to calculate and store raster statistics.

comment:3 by Mike Taves, 9 years ago

See pull request for patch https://github.com/OSGeo/gdal/pull/46

comment:4 by Mike Taves, 9 years ago

A correction to a previous comment is that gdalinfo -stats does not modify the GeoTIFF file, but creates an .aux.xml file; see #5807. Unfortunately, the raster statistics do not appear to be updated by ComputeStatistics if the .aux.xml file is present.

by Mike Taves, 9 years ago

Attachment: stats.diff added

git diff --no-prefix 3fcf12b..HEAD > stats.diff

comment:5 by Mike Taves, 9 years ago

Ready for merge to trunk with patch -p0 < stats.diff

comment:6 by Even Rouault, 9 years ago

Milestone: 2.0
Resolution: fixed
Status: newclosed

trunk r28343 "gdal_edit.py: add -stats and -approx_stats flags (patch by mwtoews, #5805)"

comment:7 by Even Rouault, 9 years ago

trunk r28347 "Fix test_gdal_edit_py_5 when gdalnumeric is not available"

Hum I thought this was in a modified version of your patch. Weird.

comment:8 by Mike Taves, 9 years ago

Yes, it was modified, then lost somewhere in subsequent commit in git (where I did git push -f, because I didn't understand other oddities). Thanks!

comment:9 by Even Rouault, 9 years ago

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.