WriteArray() does not support slices properly
|Reported by:||warmerdam||Owned by:||Even Rouault|
#!/usr/bin/env python import sys import string from osgeo import gdal import numpy big = numpy.ones((100,100)) drv = gdal.GetDriverByName( 'GTiff' ) ds = drv.Create( 'out.tif', 50, 100, 1, gdal.GDT_Byte ) slice = big[:,50:] #slice = slice * 1.0 print slice.shape ds.GetRasterBand(1).WriteArray( slice ) ds = None
fails with the error:
ERROR 1: Buffer too small, need 79600, have 40000.
but if the #slice = slice*1.0 line is uncommented it works. The problem seems to be this code in gdal_array.i:
int min_buf_size = ComputeBandRasterIOSize (nxsize, nysize, GDALGetDataTypeSize( ntype ) / 8, pixel_space, line_space, FALSE );
The buffer size is computed based on line_space which is the stride for the whole "big" array in the case of a slice. It would desirable,and quite practical, to make this work properly with slices with some careful adjustments.