[gdal-dev] calculate raster values within a vector

Dylan Beaudette debeaudette at ucdavis.edu
Wed Aug 26 11:42:57 EDT 2009

On Wednesday 26 August 2009, Emilio Mayorga wrote:
> Jose,
> Thanks for your pointer to your web site. Looks like you have some
> very interesting and useful code there. I've been trying to do
> something similar, though I use raster "zone" grids rather than vector
> layers; I'd be happy to share that code, but it's too messy at this
> point. I'll write a blog post about it eventually. Having Python
> functionality that replicates "zonalstats" would be great, with
> histogram extractions thrown in.
> Dylan, Starspan has always looked very promising, but last time I
> checked it looked abandoned. When I tried to use it over a year ago,
> it choked on my shapefiles and said they had many invalid geometries
> (it had been exported from an arc coverage using the old command-line
> ArcInfo), so I gave up after trying to identify the problems. Still,
> having Starspan functionality within Python would be great.

Hi Emilio,

Indeed. The current (C++) version of Starspan is more or less unsupported. I 
tend to use an older, stabler, version-- but have become frustrated with it 
in recent studies. I think that the current maintainer Jon Greenberg is 
working on an R implementation-- however I am not certain that this will 
scale well to very large rasters. A Python incantation would be more flexible 
than the current C++ version, but perhaps at a speed cost. The current 
version is blazing fast, but there aren't any C++ programmers working on it 
now. If there is sufficient interest, I would like to get it into OSGeo so 
that a more skilled programmer (than myself) can have a look at it. 

If you are doing raster-on-raster zonal stats, then GRASS is fairly good at 
that too.


> Cheers,
> -Emilio Mayorga
> Applied Physics Laboratory
> University of Washington
> Box 355640
> Seattle, WA 98105-6698  USA
> http://staff.washington.edu/emiliom/
> On Wed, Aug 26, 2009 at 7:13 AM, Jose Gomez-Dans<jgomezdans at gmail.com> 
> > Hi,
> >
> > 2009/8/20 questions anon <questions.anon at gmail.com>
> >
> >> Can anyone get me started on a script that can -
> >>
> >>  -Open a shapefile
> >>
> >>  -Open many rasters
> >>
> >>  -Calculate the mean and standard deviation of those rasters within the
> >> shapefile region, but is able to ignore areas of zeros or NoData
> >>
> >>  -Output the mean and standard deviation to a table
> >
> > i've done a similar example to what you want here:
> > <
> > http://sites.google.com/site/spatialpython/aggregating-data-to-grid-cells
> >> Only difference is that I calculate the histogram, rather than just the
> > mean and std dev. It is trivial to modify this for your own purposes. In
> > fact, when I get some time, I'll throw in a full "zonal stats" class, but
> > for now this should get you started.
> >
> > J
> >
> > _______________________________________________
> > gdal-dev mailing list
> > gdal-dev at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/gdal-dev
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

Dylan Beaudette
Soil Resource Laboratory
University of California at Davis

More information about the gdal-dev mailing list