[gdal-dev] Creating Geotiff with WriteArray in Python

Frank Warmerdam warmerdam at pobox.com
Mon Mar 24 13:18:36 EDT 2008


Matt Fearon wrote:
> Hi Chris and others,
> 
> Thank you all for your help, especially Chris for the detailed
> explanations. I finally got my script working with WriteArray.
> 
> Just a follow up question in regard to metadata and ENVI file format
> in python/GDAL. If the dat file I read in has an ENVI .hdr file
> associated with it - how could I unpack/access the metadata from the
> .hdr file so that I could use it when writing my GeoTiff? I know I
> could easily read the .hdr file, but it seems like GDAL already knows
> the header information when I read the dat file? For example, I read
> my dat file the following way;
> 
> file = "IMG-HH-ALPSRP021230580-H1.5GUA"
> gd=gdal.Open(file)
> array=gd.ReadAsArray()
> 
> Next, I would like to access the .hdr information associated with this
> dat file? There is a .hdr file named
> "IMG-HH-ALPSRP021230580-H1.5GUA.HDR".

Matt,

Some stuff can be accessed through the gdal.Dataset object (gd in
your case).  Things like georeferencing and coordinate system.  You
should really review the GDAL API tutorial and reference for more
information on what is available.

Some information in the .HDR will *not* be exposed in this way.  If
you need that, you may need to directly parse it.

You may find it helpful to pass your source dataset into SaveArray()
(as the "prototype" argument) if you want to write out a derived
dataset with the same georeferencing as the source dataset.

eg.

gdal_array.SaveArray( array, 'out.tif', prototype = gd )

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list