Re: [gdal-dev] satellite image processing in Python

Lucena, Ivan ivan.lucena at pmldnet.com
Fri Apr 17 08:26:34 EDT 2009


Hi there,

The problem that reported is gone. I just need to update from trunk and rebuild the python binder with swig. Scott 
is right, you can get around that problem by running your script image by image. In my case I was running the script 
on a cgi-bin environment, querying the same pixel location through out hundreds and hundreds of bands on a big-
geotiff. In that case there was no detectable memory leak because on a cgi-bin the Python interpreter is loaded and 
unloaded each time a webapp calls the script. But later I change my script to Apache/mod_python and in that case 
the Python interpreter is cached in memory with all the 'import' extensions and dependent libraries. That was when 
the problem begins, or like I reported on the previous message, when you are exploring the data on Python 
command line.

Anyway, everything is working nice and smoth now.

My best regards,

Ivan

>  -------Original Message-------
>  From: Scott Sinclair <scott.sinclair.za at gmail.com>
>  Subject: Re: [gdal-dev] satellite image processing in Python
>  Sent: Apr 17 '09 06:58
>  
>  > 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
>  _______________________________________________
>  gdal-dev mailing list
>  gdal-dev at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/gdal-dev
>  



More information about the gdal-dev mailing list