[Gdal-dev] gdal_array.SaveArray problem

Vincent Schut schut at sarvision.nl
Tue Jun 5 06:14:13 EDT 2007


Hi folks,

the ngpython gdal_array.SaveArray method does something picky with my
arrays... When I try to access the array I have saved, I get a segfault.
When saving a copy of the array, everything goes fine.

This code segfaults:

#!/usr/bin/python

import gdal, gdal_array, numpy

a = numpy.arange(3*100*150, dtype=numpy.uint16).reshape((3, 100, 150))
gdal_array.SaveArray(a, "gdalSaveArrayTest.tif")
print a[0,0,0] # segfaults here.

And this code does not segfault:

#!/usr/bin/python

import gdal, gdal_array, numpy

a = numpy.arange(3*100*150, dtype=numpy.uint16).reshape((3, 100, 150))
gdal_array.SaveArray(a.copy(), "gdalSaveArrayTest.tif")
print a[0,0,0] # OK


Apparently it has something to do with refcounts; try this in a python
interpreter (a is a numpy array):
>>> gdal_array.SaveArray(a, "test.tif")
<gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' at
0xb57fa0> >
>>> a
<refcnt -4294967291 at 0x9648c0>


This is with gdal from recent svn, and numpy too.



More information about the Gdal-dev mailing list