[gdal-dev] output of geotiff from numPy array

Travis Kirstine traviskirstine at gmail.com
Tue Jul 17 11:48:25 PDT 2012


It appears that you are creating a 8-bit unsigned integer as the
output (GDT_Byte).  Try switch it to GDT_Float32

http://www.gdal.org/gdal_8h.html#a22e22ce0a55036a96f652765793fb7a4

Regards

On 16 July 2012 17:23, William Hudspeth <bhudspeth at edac.unm.edu> wrote:
> 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
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list