<div dir="ltr"><table cellpadding="0" class="" style="width:440.909088134766px;font-family:arial,sans-serif;font-size:12.7272720336914px;white-space:nowrap"><tbody><tr><td>Even Rouault, Thank you! Now the program is working.</td></tr></tbody></table></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 2:15 AM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le dimanche 23 novembre 2014 17:04:05, Simen Langseth a écrit :<br>
<span class="">> import gdal, numpy as np<br>
> from gdalconst import *<br>
><br>
> infile = r"D:\given.tif"<br>
> inraster = gdal.Open(infile, GA_ReadOnly)<br>
> x_total,y_total=refraster.RasterXSize,refraster.RasterYSize<br>
> n_chunks=10<br>
> x_offsets=np.linspace(0,x_total,n_chunks).astype(int)<br>
> x_offsets=zip(x_offsets[:-1],x_offsets[1:])<br>
> y_offsets=np.linspace(0,y_total,n_chunks).astype(int)<br>
> y_offsets=zip(y_offsets[:-1],y_offsets[1:])<br>
><br>
> outfile = r"D:\result.tif"<br>
> outraster =<br>
> gdal.GetDriverByName('GTiff').Create(outfile,y_total,x_total,1,gdal.GDT_Flo<br>
</span>> at32) for x1,x2 in x_offsets:<br>
<span class="">> for y1,y2 in y_offsets:<br>
> values = refraster.GetRasterBand(1).ReadAsArray(x1,y1,x2-x1,y2-y1)<br>
> outraster.GetRasterBand(1).WriteArray(values, x1, y1)<br>
> inraster, outraster = None, None<br>
><br>
> I got the following error:<br>
><br>
> Traceback (most recent call last):<br>
> File "D:\test.py", line 20, in <module><br>
> outraster.GetRasterBand(1).WriteArray(values, x1, y1)<br>
> File "C:\Python27\lib\site-packages\osgeo\gdal.py", line 1167, in<br>
> WriteArray<br>
> return gdalnumeric.BandWriteArray( self, array, xoff, yoff )<br>
> File "C:\Python27\lib\site-packages\osgeo\gdal_array.py", line 304, in<br>
> BandWriteArray<br>
> raise ValueError("array larger than output file, or offset off edge")<br>
> ValueError: array larger than output file, or offset off edge<br>
><br>
> How can I correct the writeArray?<br>
<br>
</span>Presumably outraster dimensions are not big enough.<br>
Create(outfile,y_total,x_total,....) is wrong. That should rather be<br>
Create(outfile,x_total,y_total,....)<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Spatialys - Geospatial professional services<br>
<a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a><br>
</font></span></blockquote></div><br></div>