Opened 14 years ago

Closed 14 years ago

#3542 closed defect (fixed)

WriteArray() does not support slices properly

Reported by: warmerdam Owned by: Even Rouault
Priority: normal Milestone: 1.7.2
Component: PythonBindings Version: 1.7.0
Severity: normal Keywords:
Cc: hobu

Description

This script:

#!/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.

Change History (2)

comment:1 by Even Rouault, 14 years ago

Cc: hobu added
Owner: changed from hobu to Even Rouault

Taking care of this as I introduced it during while restructuring in 1.7, but this checking appears to be unnecessary as the various parameters (buffer size, pixel offset and line stride) should always be deduced from the numpy dataset and never passed explicetly to BandRasterIONumPy()

comment:2 by Even Rouault, 14 years ago

Milestone: 1.7.2
Resolution: fixed
Status: newclosed
Version: unspecified1.7.0

r19478 /trunk/gdal/swig/include/gdal_array.i: NumPy : remove useless & incorrect test on buffer size to handle slices (#3542)

r19479 /trunk/gdal/swig/python/ (extensions/gdal_array_wrap.cpp osgeo/gdal_array.py): Refresh python bindings

r19480 /trunk/autotest/gcore/numpy_rw.py: Add test for fix of #3542

r19481 /branches/1.7/gdal/swig/include/gdal_array.i: NumPy : remove useless & incorrect test on buffer size to handle slices (#3542)

r19482 /branches/1.7/gdal/swig/python/ (extensions/gdal_array_wrap.cpp osgeo/gdal_array.py): Refresh python bindings (#3542)

Note: See TracTickets for help on using tickets.