[gdal-dev] output of geotiff from numPy array

William Hudspeth bhudspeth at edac.unm.edu
Mon Jul 16 14:23:53 PDT 2012


Hello,

I am trying to write a two-dimensional numPy float array to a Geotiff
using the Python GDAL bindings. I use code similar to

format="GTiff"
dst_driver=GetDriverByName(format)
srs=osr.SpatialReference()
srs.ImportFromEPSG(4326)

dust_abs=dst_driver.Create(dst_filename,pream_array_columns,pream_array_rows,1,GDT_Byte)
dust_abs.SetGeoTransform(pream_geotransform)			
dust_abs.SetProjection(srs.ExportToWkt())
dust_abs.GetRasterBand(1).WriteArray(input_array)

My output tiff is of type float, but the values are stretched from 0 to
255. How do I get an output tiff with the original array float values?


Ex. 
gdalinfo -stats file.tif

.....
Band 1 Block=149x54 Type=Byte, ColorInterp=Gray
  Min=0.000 Max=255.000 
  Minimum=0.000, Maximum=255.000, Mean=77.244, StdDev=117.178
  Metadata:
    STATISTICS_MINIMUM=0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=77.244174647462
    STATISTICS_STDDEV=117.17765153021
..........


Thanks



More information about the gdal-dev mailing list