I'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'm going to copy the image chunk around using ReadAsArray and WriteArray, doesn't it mean I need to retreive each band in turn? Or have I missed something and there's an easier way to extract a portion of an image and write it out?
Cheers, Graeme On Mon, Nov 28, 2011 at 3:40 PM, Chaitanya kumar CH <[email protected]>wrote: > Graeme, > > You do need to copy all bands. Also, make sure you set the correct number > of bands while creating the destination dataset. > > 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. > > On Mon, Nov 28, 2011 at 6:40 AM, Graeme Merrall <[email protected]>wrote: > >> 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 >> >> from osgeo import gdal >> import numpy >> img = gdal.Open("original.tif") >> geotransform = img.GetGeoTransform() >> band1 = img.GetRasterBand(1) >> >> driver = gdal.GetDriverByName("GTiff) >> # coordinates will be calculated but hardcoded for now >> dst = driver.Create('sliver.tif', 20000, 20000, 1, gdal.GDT_Byte) >> dst.SetProjection(img.GetProjection()) >> scanline1 = band1.ReadAsArray(0, 0, 20000, 20000) >> dst.GetRasterBand(1).WriteArray(scanline1) >> >> Should I be looping through each band and reading/writing to the image? >> I'm assuming yes >> >> Also. band 1 of the original image is red but in the new image the band >> color is grey. I've tried a few variations with >> GDALRasterBand.SetColorInterpretation() with no luck. What have I missed? >> >> Cheers, >> >> _______________________________________________ >> gdal-dev mailing list >> [email protected] >> http://lists.osgeo.org/mailman/listinfo/gdal-dev >> > > > > -- > Best regards, > Chaitanya kumar CH. > > +91-9494447584 > 17.2416N 80.1426E >
_______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
