[gdal-dev] GetStatistics and signed 8-bit IMGs and GeoTIFFs

Jason Roberts jason.roberts at duke.edu
Wed Sep 23 15:11:16 EDT 2009


Is band.GetStatistics() supposed to work with signed 8-bit integer rasters
with the HFA or GTiff driver?

 

With GDAL 1.6.0, I can successfully create a signed 8-bit raster with the
HFA or GTiff driver using the PIXELTYPE=SIGNEDBYTE option:

 

>>> a = numpy.array([[-128, -1, 0, 1, 127]], dtype='int8')

>>> a

array([[-128,   -1,    0,    1,  127]], dtype=int8)

>>> b = numpy.cast['uint8'](a)

>>> print b

[[128 255   0   1 127]]

>>> 

>>> gdal.UseExceptions()

>>> driver = gdal.GetDriverByName('HFA')

>>> dataset = driver.Create(r'C:\Temp\test_int8.img', 5, 1, 1,
gdal.GDT_Byte, ['PIXELTYPE=SIGNEDBYTE'])

>>> band = dataset.GetRasterBand(1)

>>> band.WriteArray(b)

0

>>> del band, dataset, driver

 

When I look at that raster with ArcGIS, it shows it is signed 8-bit integer
and the five values show up properly. But when I open it with GDAL and call
band.GetStatistics(), it looks like the calculation is performed using
unsigned 8-bit integers:

 

>>> dataset = gdal.Open(r'C:\Temp\test_int8.img', gdalconst.GA_ReadOnly)

>>> band = dataset.GetRasterBand(1)

>>> band.GetStatistics(False, True)

[0.0, 255.0, 102.2, 95.199579831005551]

 

I am wondering if this is a bug or by design. If by design, is there any way
my application can tell through GDAL that it is a signed 8-bit file rather
than an unsigned 8-bit file?

 

Thanks very much for your help,

 

Jason

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090923/2263c2c4/attachment.html


More information about the gdal-dev mailing list