[gdal-dev] Save min/max values in TIFF
Even Rouault
even.rouault at spatialys.com
Fri Nov 11 10:25:32 PST 2022
Le 11/11/2022 à 19:12, Javier Jimenez Shaw a écrit :
> Hi
>
> I am creating a GeoTIFF file with C++. It is a large DSM (one band of
> Float32). Because I am generating it, I already know the min and max
> values.
> I would like to store the min and max values directly in the TIFF, not
> in a sidecar file. Is there any gdal metadata (stored in the TIFF)
> that can be used? That way, when I open it in QGIS, the range of the
> band will be accurate.
yep, see https://gdal.org/user/raster_data_model.html#raster-band
Demo:
$ python
from osgeo import gdal
ds = gdal.GetDriverByName('GTiff').Create('test.tif', 1, 1)
ds.GetRasterBand(1).SetMetadataItem('STATISTICS_MINIMUM', '0')
ds.GetRasterBand(1).SetMetadataItem('STATISTICS_MAXIMUM', '1')
ds.GetRasterBand(1).SetMetadataItem('STATISTICS_MEAN', '2')
ds.GetRasterBand(1).SetMetadataItem('STATISTICS_STDDEV', '3')
$ gdalinfo test.tif
Driver: GTiff/GeoTIFF
Files: test.tif
Size is 1, 1
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 1.0)
Upper Right ( 1.0, 0.0)
Lower Right ( 1.0, 1.0)
Center ( 0.5, 0.5)
Band 1 Block=1x1 Type=Byte, ColorInterp=Gray
Min=0.000 Max=1.000
Minimum=0.000, Maximum=1.000, Mean=2.000, StdDev=3.000
Metadata:
STATISTICS_MAXIMUM=1
STATISTICS_MEAN=2
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=3
$ tiffdump -m 1000 test.tif
test.tif:
Magic: 0x4949 <little-endian> Version: 0x2a <ClassicTIFF>
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) SHORT (3) 1<1>
ImageLength (257) SHORT (3) 1<1>
BitsPerSample (258) SHORT (3) 1<8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<1>
StripOffsets (273) LONG (4) 1<402>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) SHORT (3) 1<1>
StripByteCounts (279) LONG (4) 1<1>
PlanarConfig (284) SHORT (3) 1<1>
SampleFormat (339) SHORT (3) 1<1>
42112 (0xa480) ASCII (2) 244<<GDALMetadata>\n <Item
name="STATISTICS_MAXIMUM" sample="0">1</Item>\n <Item
name="STATISTICS_MEAN" sample="0">2</Item>\n <Item
name="STATISTICS_MINIMUM" sample="0">0</Item>\n <Item
name="STATISTICS_STDDEV" sample="0">3</Item>\n</GDALMetadata>\n\0>
Even
>
> Thanks.
> .___ ._ ..._ .. . ._. .___ .. __ . _. . __.. ... .... ._ .__
> Entre dos pensamientos racionales
> hay infinitos pensamientos irracionales.
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221111/66cb9ebb/attachment.htm>
More information about the gdal-dev
mailing list