[gdal-dev] satellite image processing in Python
Scott Sinclair
scott.sinclair.za at gmail.com
Fri Apr 17 02:58:49 EDT 2009
> 2009/4/14 Harris, Sarah L <sarah.l.harris at jpl.nasa.gov>:
> I would like to use this code written by Yann Chemin (see Feb 2009 gdal-dev
> archives)
> but I keep getting a memory error. Can anyone help me fix this. I have put
> the entire error below the code.
> Thanks in advance
>
> F=[]
...
> Traceback (most recent call last):
> File "E:\python processing\Landsat_processing.py", line 75, in <module>
> Red = LoadFile('b3_ref.tif')
> File "C:\Python25\lib\site-packages\osgeo\gdal_array.py", line 73, in
> LoadFile
> return DatasetReadAsArray( ds, xoff, yoff, xsize, ysize )
> File "C:\Python25\lib\site-packages\osgeo\gdal_array.py", line 90, in
> DatasetReadAsArray
> return BandReadAsArray( ds.GetRasterBand(1), xoff, yoff, xsize, ysize)
> File "C:\Python25\lib\site-packages\osgeo\gdal_array.py", line 138, in
> BandReadAsArray
> buf_xsize, buf_ysize, datatype )
> File "C:\Python25\Lib\site-packages\osgeo\gdal.py", line 760, in
> ReadRaster
> return _gdal.Band_ReadRaster(*args, **kwargs)
> MemoryError
I guess this is related to a bug in the Python bindings discussed here:
http://lists.osgeo.org/pipermail/gdal-dev/2009-April/020334.html
If you can't rebuild the bindings from SVN, a work-around would be to
modify your Python script to process a single file based on a filename
argument on the command line, then process your data using a batch
file.
i.e. your script could be run from the command line as follows:
C:\> python script.py e:\Imagery\Landsat\Landsat7\L71040036_03620071224_B10.TIF
and your batch file would look something like:
python script.py e:\Imagery\Landsat\Landsat7\L71040036_03620071224_B10.TIF
python script.py e:\Imagery\Landsat\Landsat7\L71040036_03620071224_B20.TIF
etc..
and run as
C:\> my_batch.bat
By processing each file in a new Python process, you'll be sure to
free the memory after processing the file.
Cheers,
Scott
More information about the gdal-dev
mailing list