[gdal-dev] Re: Re: Python Scripts

Oz Nahum nahumoz at gmail.com
Sat Jun 6 12:08:36 EDT 2009


Hi Kyle
It might be a little bit of a detour for reaching your goal, but if you're
already using gdal inside python you could use numpy masked arrays to fill
in no data values. I do that for that goal.

here is a snippet from my code:

def ClipPolution(nameOfMask, nameOfPolutionRaster):
    '''This function takes in two rasters, and returns a cliped raster,
    with NULL (-9999) values
    For all points out side of the domain of interest'''
    dataset = gdal.Open(nameOfPolutionRaster, GA_ReadOnly)
    dataSetMask = gdal.Open(nameOfMask, GA_ReadOnly)
    areaOfPolution = gdal_array.DatasetReadAsArray(dataset)
    maska = gdal_array.DatasetReadAsArray(dataSetMask)
    clip = ma.MaskedArray(areaOfPolution, mask=maska)
    cclip=ma.filled(clip,value=-9999)
    WriteRaster('p4masked.asc', cclip)
    print 'Successfuly Cliped polution Raster...'

you can find more stuff here:

http://docs.scipy.org/doc/numpy/reference/maskedarray.html

Hope it helps some how

Oz Nahum
Graduate Student
Center for Applied Geosciences
University of Tuebingen

-- 
----
           Imagine there's no countries
           It isn't hard to do
           Nothing to kill or die for
           And no religion too
           Imagine all the people
           Living life in peace
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090606/ee647306/attachment.html


More information about the gdal-dev mailing list