Thanks Even, <div><br></div><div>I had (sort of) come to that conclusion myself, as I started looking into what blocksize actually meant. I'll modify to work in row order.</div><div><br></div><div>Thanks!</div><div><br>
</div><div>Jamie<br><br><div class="gmail_quote">On Fri, Mar 26, 2010 at 2:10 PM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Jamie,<br>
<br>
I'm not sure why it slowdowns after the first 2 bands, but I can say your way<br>
of proceeding is very inefficient and you can achieve the same results by<br>
processing by rows instead of columns. As your input file is scanline<br>
oriented (block size is 20000x1 - which is pretty standard), reading a column<br>
will cause the whole file to be read at each time !<br>
<br>
Try instead the following version which read line by line and horizontally<br>
flip the buffer : it should complete in a few minutes.<br>
<div class="im"><br>
for band in range(1, indataset.RasterCount + 1):<br>
## Print the current band<br>
print 'Band %s' % band<br>
<br>
inband = indataset.GetRasterBand(band)<br>
outband = outdataset.GetRasterBand(band)<br>
<br>
count = 0<br>
print count<br>
<br>
</div> for i in range(inband.YSize):<br>
<div class="im"><br>
## print the current interval of 1k lines<br>
new_count = int(i / 1000)<br>
if new_count > count:<br>
print new_count<br>
count = new_count<br>
<br>
</div> inline = inband.ReadAsArray(0, i, inband.XSize, 1)<br>
flipline = numpy.fliplr(inline)<br>
outband.WriteArray(flipline, 0, i)<br>
<div class="im"><br>
inline = None<br>
<br>
inband = None<br>
outband = None<br>
<br>
</div>Best regards,<br>
<br>
Even<br>
<br>
Le Friday 26 March 2010 21:22:54 Jamie Adams, vous avez écrit :<br>
<div><div></div><div class="h5">> I've written some simple Python code to flip a raster in relation to the<br>
> y-axis. The raster is 20000x19459 and has 4 bands of type Byte, and is<br>
> written east to west (I have no idea why). The script proceeds normally<br>
> for the first 2 bands, but slows way down after starting band 3. I let it<br>
> run overnight, and it had processed less than 1000 columnsin band 3,<br>
> whereas the previous pace for bands 1&2 was around 1000 columns every 10<br>
> seconds. Here is the relevant code with a few debugging statements<br>
> followed by the gdalinfo output. The only thing I'm noticing is that the<br>
> input image is INTERLEAVED=BAND whereas the output is INTERLEAVED=PIXEL.<br>
> Any help is appreciated.<br>
><br>
> ---------------------------------------------------------------------------<br>
>--- for band in range(1, indataset.RasterCount + 1):<br>
> ## Print the current band<br>
> print 'Band %s' % band<br>
><br>
> inband = indataset.GetRasterBand(band)<br>
> outband = outdataset.GetRasterBand(band)<br>
><br>
> count = 0<br>
> print count<br>
><br>
> for i in range(inband.XSize):<br>
><br>
> ## print the current interval of 1k lines<br>
> new_count = int(i / 1000)<br>
> if new_count > count:<br>
> print new_count<br>
> count = new_count<br>
><br>
> inline = inband.ReadAsArray(i, 0, 1, inband.YSize)<br>
><br>
> outband.WriteArray(inline, inband.XSize - i - 1, 0)<br>
><br>
> inline = None<br>
><br>
> inband = None<br>
> outband = None<br>
><br>
> ---------------------------------------------------------------------------<br>
>--- Driver: GTiff/GeoTIFF<br>
> Files: test.tif<br>
> Size is 20000, 19459<br>
> Coordinate System is:<br>
> GEOGCS["WGS 84",<br>
> DATUM["WGS_1984",<br>
> SPHEROID["WGS 84",6378137,298.257223563,<br>
> AUTHORITY["EPSG","7030"]],<br>
> AUTHORITY["EPSG","6326"]],<br>
> PRIMEM["Greenwich",0],<br>
> UNIT["degree",0.0174532925199433],<br>
> AUTHORITY["EPSG","4326"]]<br>
> Origin = (-175.536864949200321,33.666235092496755)<br>
> Pixel Size = (-0.000062579160220,-0.000054370391310)<br>
> Metadata:<br>
> AREA_OR_POINT=Area<br>
> Image Structure Metadata:<br>
> INTERLEAVE=BAND<br>
> Corner Coordinates:<br>
> Upper Left (-175.5368649, 33.6662351) (175d32'12.71"W, 33d39'58.45"N)<br>
> Lower Left (-175.5368649, 32.6082416) (175d32'12.71"W, 32d36'29.67"N)<br>
> Upper Right (-176.7884482, 33.6662351) (176d47'18.41"W, 33d39'58.45"N)<br>
> Lower Right (-176.7884482, 32.6082416) (176d47'18.41"W, 32d36'29.67"N)<br>
> Center (-176.1626566, 33.1372384) (176d 9'45.56"W, 33d 8'14.06"N)<br>
> Band 1 Block=20000x1 Type=Byte, ColorInterp=Red<br>
> Mask Flags: PER_DATASET ALPHA<br>
> Band 2 Block=20000x1 Type=Byte, ColorInterp=Green<br>
> Mask Flags: PER_DATASET ALPHA<br>
> Band 3 Block=20000x1 Type=Byte, ColorInterp=Blue<br>
> Mask Flags: PER_DATASET ALPHA<br>
> Band 4 Block=20000x1 Type=Byte, ColorInterp=Alpha<br>
<br>
<br>
</div></div></blockquote></div><br></div>