[gdal-dev] empty Gtiff from Python

Tom van der Putte tom at vdputte.nl
Fri Oct 28 04:23:04 EDT 2011

 I'm trying to save a numpy array to a GTiff, which should be quite
straightforward, considering all the examples available on the web.
However, I get an file that is not readable by Qgis, is regarded by
ArcMap to have only 0 and gdalinfo displays nothing on the values.
 I start with a ndarray, dtype = int32, shape = ( 10,10). It has
integer values between 1 and 10. The code is as follows:
 import numpy as np
 from osgeo import gdal
 from osgeo import osr
 #np array
 a = np.ones((10,10))
 sr_str = 'LOCAL_CS["arbitrary"]'
 sr = osr.SpatialReference( sr_str )
 driver = gdal.GetDriverByName("GTiff")
 ds = driver.Create("D:\temp\output.tif", 10, 10, 1, gdal.GDT_Byte)
 ds.SetProjection( sr_str )
 ds.SetGeoTransform((0, 1, 0,0, 0,1))
 #write and close
 ds = None
 The corresponding gdalinfo is:
 Raster dataset parameters:
   RasterCount: 1
   RasterSize (10,10)
 Using driver GeoTIFF
     0:  AREA_OR_POINT=Area
   Image Structure Metadata:
 Corner Coordinates:
   Upper Left (0, 0)
   Lower Left (0, 10)
   Upper Right (10, 0)
   Lower Right (10, 10)
   Center (5, 5)
 Coordinate System is:
 Band 1 :
    DataType: Byte
    ColorInterpretation: Gray
    Size (10,10)
    BlockSize (10,10)
 I have tried both version 1.6.3 (I'm trying to make a Qgis plugin,
and thus restricted to 1.6.3) as well as 1.8.1. I have also tried ds =
driver.Create("D:\temp\output.tif", 10, 10, 1, gdal.GDT_Int32), but
that didn't make much difference.
 I tried to make a Surfer grid (GSBG), and this somewhat worked: it
gave a nice picture, but the values were off the charts.
 Any clues as to what I'm missing here? Cheers,
 Tom van der Putte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111028/d4d82f44/attachment.html

More information about the gdal-dev mailing list