<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gong, Shawn wrote:
<blockquote
cite="mid2E58C246F17003499C141D334794D049D587CC@ottawaex02.Ottawa.drdc-rddc.gc.ca"
type="cite">
<pre wrap="">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
</pre>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Gdal-dev@lists.maptools.org">Gdal-dev@lists.maptools.org</a>
<a class="moz-txt-link-freetext" href="http://lists.maptools.org/mailman/listinfo/gdal-dev">http://lists.maptools.org/mailman/listinfo/gdal-dev</a></pre>
</blockquote>
<br>
Untested, and as usual take with a grain of salt.<br>
I think this is what is happening<br>
<br>
The member function .ReadAsArray() returns an<br>
array. As far as I can tell the function WriteRaster() takes a string
as the forth<br>
argument and does not understand Numeric Types.<br>
The function .BandWriteArray() in gdalnumeric.py takes<br>
care of both these problems. <br>
<br>
- William Hughes<br>
</body>
</html>