[gdal-dev] empty Gtiff from Python

Tom van der Putte tom at vdputte.nl
Fri Oct 28 05:43:08 EDT 2011


Hi
Chris,
 Thanks for checking. I tried it on a linux machine here also and it
seems to work. Probably something wrong with either the GDAL
instalations or QGIS on my windows machine. I'll try reinstalling it
all.
 Cheers!
 Tom
 On Fri 28/10/11 11:10 , "Chris Yesson" Chris.Yesson at ioz.ac.uk sent:
 Tom,
 I have just run your code exactly as you sent it (except for output
 path), with python 2.5.2 ang gdal 1.8.1.  The ouput file appears in
 order (gdalinfo output below).  The file opens and displays normally
in
 qgis trunk v 1.8.
 - Chris
 Gdalinfo output
 Driver: GTiff/GeoTIFF
 Files: output.tif
        output.tif.aux.xml
 Size is 10, 10
 Coordinate System is:
 LOCAL_CS["arbitrary",
     UNIT["metre",1,
         AUTHORITY["EPSG","9001"]]]
 Metadata:
   AREA_OR_POINT=Area
 Image Structure Metadata:
   INTERLEAVE=BAND
 Corner Coordinates:
 Upper Left  (    0.0,    0.0)
 Lower Left  (    0.0,   10.0)
 Upper Right (   10.0,    0.0)
 Lower Right (   10.0,   10.0)
 Center      (    5.0,    5.0)
 Band 1 Block=10x10 Type=Byte, ColorInterp=Gray
   Min=1.000 Max=1.000
   Minimum=1.000, Maximum=1.000, Mean=1.000, StdDev=0.000
   Metadata:
     STATISTICS_MINIMUM=1
     STATISTICS_MAXIMUM=1
     STATISTICS_MEAN=1
     STATISTICS_STDDEV=0
 Date: Fri, 28 Oct 2011 10:23:04 +0200
 From: Tom van der Putte 
 Subject: [gdal-dev] empty Gtiff from Python
 To: 
 Message-ID: 
 Content-Type: text/plain; charset="utf-8"
 Hi
 List,
  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))
  #coord-system
  sr_str = 'LOCAL_CS["arbitrary"]'
  sr = osr.SpatialReference( sr_str )
  #driver
  driver = gdal.GetDriverByName("GTiff")
  #dataset
  ds = driver.Create("D:tempoutput.tif", 10, 10, 1, gdal.GDT_Byte)
  ds.SetProjection( sr_str )
  ds.SetGeoTransform((0, 1, 0,0, 0,1))
  #write and close
  ds.GetRasterBand(1).WriteArray(a)
  ds = None
  The corresponding gdalinfo is:
  *********
  Raster dataset parameters:
    Projection:
 LOCAL_CS["arbitrary",UNIT["metre",1,AUTHORITY["EPSG","9001"]]]
    RasterCount: 1
    RasterSize (10,10)
  Using driver GeoTIFF
    Metadata:
      0:  AREA_OR_POINT=Area
    Image Structure Metadata:
      0:  INTERLEAVE=BAND
  Corner Coordinates:
    Upper Left (0, 0)
    Lower Left (0, 10)
    Upper Right (10, 0)
    Lower Right (10, 10)
    Center (5, 5)
  Coordinate System is:
  LOCAL_CS["arbitrary",
      UNIT["metre",1,
          AUTHORITY["EPSG","9001"]]]
  Band 1 :
     DataType: Byte
     ColorInterpretation: Gray
     Description:
     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:tempoutput.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-0001.html
 ------------------------------
 _______________________________________________
 gdal-dev mailing list
 http://lists.osgeo.org/mailman/listinfo/gdal-dev
 End of gdal-dev Digest, Vol 89, Issue 71
 ****************************************
 This message has been scanned for viruses by MailControl -
 www.mailcontrol.com
 Click
 https://www.mailcontrol.com/sr/wQw0zmjPoHdJTZGyOCrrhg==
 oTJhgA1yNPXUJ0FMnJ7X3MJaL!eAyER2lygvJyt6ermNw==  to report this
email as
 spam.
 The Zoological Society of London is incorporated by Royal Charter
 Principal Office England. Company Number RC000749
 Registered address: 
 Regent's Park, London, England NW1 4RY
 Registered Charity in England and Wales no. 208728 

_________________________________________________________________________
 This e-mail has been sent in confidence to the named addressee(s).
 If you are not the intended recipient, you must not disclose or
distribute
 it in any form, and you are asked to contact the sender immediately.
 Views or opinions expressed in this communication may not be those
 of The Zoological Society of London and, therefore, The Zoological
 Society of London does not accept legal responsibility for the
contents
 of this message. The recipient(s) must be aware that e-mail is not a
 secure communication medium and that the contents of this mail may
 have been altered by a third party in transit.
 If you have any issues regarding this mail please contact:
 .

___________________________________________________________________________
 This message has been scanned for viruses by MailControl, a service
from BlackSpider Technologies.
 

Links:
------
[5] http://www.mailcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111028/466c878a/attachment-0001.html


More information about the gdal-dev mailing list