[Gdal-dev] gdaldataset writeraster
William Hughes
whughes at nb.sympatico.ca
Mon Jan 22 18:21:54 EST 2007
Gong, Shawn wrote:
>Hi list,
>
>I open a gdaldataset, have done manipulation to r,g,b and nir bands.
>Now I'd like to save the 4 bands back to original gdaldataset or a new
>dataset.
>Can't seem to get gdaldataset's WriteRaster() working, or is it the
>right method?
>Please help.
>
> fname1 = 'file3.tif'
> msi_dataset = gdal.Open(fname1)
> msi_array = msi_dataset.ReadAsArray()
>
> r = msi_array[:][:][0]
> g = msi_array[:][:][1]
> b = msi_array[:][:][2]
> nir = msi_array[:][:][3]
>
> row = msi_dataset.RasterYSize
> col = msi_dataset.RasterXSize
>
>the following I am not sure:
> msi_dataset.WriteRaster(0, 0, col, row, r, col, row,
>Numeric.Float16, [0])
> msi_dataset.WriteRaster(0, 0, col, row, g, col, row,
>Numeric.Float16, [1])
> msi_dataset.WriteRaster(0, 0, col, row, b, col, row,
>Numeric.Float16, [2])
> msi_dataset.WriteRaster(0, 0, col, row, nir, col, row,
>Numeric.Float16, [3])
>
>Thanks,
>Shawn Gong
>
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Gdal-dev mailing list
>Gdal-dev at lists.maptools.org
>http://lists.maptools.org/mailman/listinfo/gdal-dev
>
Untested, and as usual take with a grain of salt.
I think this is what is happening
The member function .ReadAsArray() returns an
array. As far as I can tell the function WriteRaster() takes a string
as the forth
argument and does not understand Numeric Types.
The function .BandWriteArray() in gdalnumeric.py takes
care of both these problems.
- William Hughes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070122/cb3344df/attachment.html
More information about the Gdal-dev
mailing list