I&#39;ve discovered that he bands are determined by the args to driver.Create() that is if I create a 4 band image then the bands are correct, however if I&#39;m going to copy the image chunk around using ReadAsArray and WriteArray, doesn&#39;t it mean I need to retreive each band in turn?<div>
Or have I missed something and there&#39;s an easier way to extract a portion of an image and write it out?</div><div><br></div><div>Cheers,</div><div> Graeme<br><br><div class="gmail_quote">On Mon, Nov 28, 2011 at 3:40 PM, Chaitanya kumar CH <span dir="ltr">&lt;<a href="mailto:chaitanya.ch@gmail.com">chaitanya.ch@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Graeme,<br><br>You do need to copy all bands. Also, make sure you set the correct number of bands while creating the destination dataset.<br>
<br>Color interpretation is useful when you have multiple bands. If you want to show your image in red, set it to GCI_PaletteIndex and set a colortable.<br>
<br><div class="gmail_quote"><div><div class="h5">On Mon, Nov 28, 2011 at 6:40 AM, Graeme Merrall <span dir="ltr">&lt;<a href="mailto:graeme@inetix.com.au" target="_blank">graeme@inetix.com.au</a>&gt;</span> wrote:<br></div>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
<div>The smallest almost working code chunk I have right now is below.  This is taaking a 40k by 40k and pulling out the top left quarter.  The original has 4 bands - RGBA</div>
<div><br></div><div>
<div>from osgeo import gdal</div><div>import numpy</div><div>img = gdal.Open(&quot;original.tif&quot;)</div><div>geotransform = img.GetGeoTransform()</div><div>band1 = img.GetRasterBand(1)</div><div><br></div><div>driver = gdal.GetDriverByName(&quot;GTiff)</div>


<div># coordinates will be calculated but hardcoded for now</div><div>dst = driver.Create(&#39;sliver.tif&#39;, 20000, 20000, 1, gdal.GDT_Byte)</div><div>dst.SetProjection(img.GetProjection())</div><div>scanline1 = band1.ReadAsArray(0, 0,  20000, 20000)</div>


<div>dst.GetRasterBand(1).WriteArray(scanline1)</div><div><br></div><div>Should I be looping through each band and reading/writing to the image? I&#39;m assuming yes</div><div><br></div><div>Also. band 1 of the original image is red but in the new image the band color is grey. I&#39;ve tried a few variations with GDALRasterBand.SetColorInterpretation() with no luck.  What have I missed?</div>


<div><br></div><div>Cheers,</div></div>
<br></div></div>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br>
<br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br>
<br><a href="tel:%2B91-9494447584" value="+919494447584" target="_blank">+91-9494447584</a><br>17.2416N 80.1426E<br>
</font></span></blockquote></div><br></div>