[Gdal-dev] gdaldataset writeraster
Gong, Shawn
Shawn.Gong at drdc-rddc.gc.ca
Tue Jan 23 13:14:33 EST 2007
Thank you, William.
I used your clue as follows and it worked.
gdalnumeric.BandWriteArray(msi_dataset.GetRasterBand(1), r)
......
gdal.GetDriverByName("GTiff").CreateCopy(outfile_name, msi_dataset)
Shawn Gong
________________________________________
From: William Hughes [mailto:whughes at nb.sympatico.ca]
Sent: Monday, January 22, 2007 6:22 PM
To: Gong, Shawn
Cc: gdal-dev at lists.maptools.org
Subject: Re: [Gdal-dev] gdaldataset writeraster
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
More information about the Gdal-dev
mailing list