Opened 11 years ago

Closed 11 years ago

#4935 closed defect (fixed)

Python Crashes when calling Dataset.ReadAsArray()

Reported by: beck3905 Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 1.9.1
Severity: normal Keywords:
Cc:

Description

I am using Python 2.6.5 (32bit) with Numpy 1.3 and GDAL 1.9.1 on a Windows 7 64bit computer. I am trying to perform some raster math by converting an 800 MB Imagine (.img) file to a Numpy Array using the following code:

from osgeo import gdal

g = gdal.Open(r'path\to\dataset', gdal.GA_Readonly)
b = g.GetRasterBand(1)
data = b.ReadAsArray()

Python.exe crashes after b.ReadAsArray(). I saw a previous ticket with the same issue that was closed due to versions being "too old", but this seems to still be an issue.

Change History (6)

comment:1 by Even Rouault, 11 years ago

And what happens if you try with a small subwindow of the whole raster, with b.ReadAsArray(x, y, win_xsize, win_ysize) ?

comment:2 by beck3905, 11 years ago

I tried b.ReadAsArray(0, 0, 500, 500) and received the same result. There is no error message, just a popup that says "Python.exe has stopped working".

comment:3 by beck3905, 11 years ago

I decided to debug the code in PyDev to try to determine where it is failing. From what I can tell (still not getting any error messages) it is failing on line 22 of gdal_array.py.

_mod = imp.load_module('_gdal_array', fp, pathname, description)

When I step into the line of code above, it brings me into the init.py module of numpy. When I reach the end of the numpy.init.py module, it steps out back to the above line of code. Then, when I hit the step into button, which should bring me to the next line within gdal_array.py, the script just terminates with no error messages or anything.

comment:4 by Even Rouault, 11 years ago

If you have built GDAL yourself, this might be a problem with your build. I can see that the builds at http://www.gisinternals.com/sdk/ pass successfully the GDAL numpy tests ( for example numpy_rw_1 at http://www.gisinternals.com/sdk/build-output/vc7-20121221-4-59-14-56-vc7-stable-1.9-6-2.txt ). Perhaps you could try them ?

comment:5 by beck3905, 11 years ago

The version of GDAL I am using is a build from gisinternals.com. I also tried a build of GDAL 1.9.2 from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Both end in the same result.

comment:6 by beck3905, 11 years ago

Resolution: fixed
Status: newclosed

I am going to close this bug report as I have determined the problem. Apparently I was not attentive enough when installing GDAL and the Python Bindings. I ended up installing GDAL from gisinternals.com and the Python Bindings from another site so there was a mismatch. When I reinstalled GDAL and the Python Bindings from gisinternals, everything worked as expected. Sorry for wasting everyone's time.

Note: See TracTickets for help on using tickets.