[gdal-dev] saving numpy array as ascii raster

Oz Nahum oz.nahum at student.uni-tuebingen.de
Thu Mar 5 15:45:24 EST 2009


Hi,
Thanks for your quick reply.
When I edit my code function to be:
def WriteRaster (dst_filename, raster):

        format = "AAIGrid"
        driver = gdal.GetDriverByName( format )
        dst_ds = driver.Create( dst_filename, 71, 73,\
              1,gdal.GDT_Float32,options=["COMPRESS=PACKBITS","TFW=YES"] )

Python complains:

ERROR 6: GDALDriver::Create() ... no create method implemented for this
format.

alsp
>This file must be the .tfw, right?  I expect you created a geotiff file as
>well which is where your data is.

True, a file with the suffix I choose. This file is binary and I can't see
it.

So I would rather use the code supplied to save as text. This however is
still not successful,
Thanks,
Oz.

On Thu, Mar 5, 2009 at 9:28 PM, Bryan Keith <bryan at ideotrope.org> wrote:

> > Hello Again,
> > def WriteRaster (dst_filename, raster):
> >
> >         format = "GTiff"
>
> Oz,
>
> You're creating a geotiff.  Try:
>
> format = "AAIGrid"
>
> >         driver = gdal.GetDriverByName( format )
> >         dst_ds = driver.Create( dst_filename, 71, 73,\
> >                1,gdal.GDT_Float32,options=["COMPRESS=PACKBITS","TFW=YES"]
> > )
>
> These options won't be available for "AAIGrid".
>
> >         dst_ds.SetGeoTransform( [-19.5, 1.0, 0.0, 37.5, 0.0, -1.0] )
> >         srs = osr.SpatialReference()
> >         srs.ImportFromEPSG(4326) #WGS84 lat long.
> >         dst_ds.SetProjection( srs.ExportToWkt() )
> >         dst_ds.GetRasterBand(1).WriteArray( raster )
> >         dst_ds = None
> >
> >
> > c= a+b
> > print c
> > WriteRaster ('raster3.gtiff', c)
> >
> > A file with following content is created:
> >
> > 1.0000000000
> > 0.0000000000
> > 0.0000000000
> > -1.0000000000
> > -19.0000000000
> > 37.0000000000
>
> This file must be the .tfw, right?  I expect you created a geotiff file as
> well which is where your data is.
>
> Bryan
>
>
>


-- 

----
           Imagine there's no countries
           It isn't hard to do
           Nothing to kill or die for
           And no religion too
           Imagine all the people
           Living life in peace
----
          You all must read 'The God Delusion'
          http://en.wikipedia.org/wiki/The_God_Delusion
---
when one person suffers from a delusion it is called insanity. When many
people suffer from a delusion it is called religion."
Robert Pirsig, Zen and the Art of Motorcycle Maintenance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090305/a7656fb2/attachment.html


More information about the gdal-dev mailing list