[GRASSLIST:547] Re: [GRASS5] collecting into a vector polygons statistics of raster pixels
Matthew Perry
perrygeo at gmail.com
Mon Apr 3 02:47:57 EDT 2006
An ideal tool for this job is starspan (http://starspan.casil.ucdavis.edu/)
If you build starspan on top of GDAL compiled with GRASS support, you
can easily summarize GRASS rasters by a shapefile vector polygon
layer:
starspan --raster /grass/location/mapset/cellhd/rastername --vector
/path/to/shp --stats output.csv min max median stdev avg
if you;re looking for a pure GRASS solution, there is the v.rast.stats
script that should be in recent GRASS distributions.
I have found the fastest way to do this sort of analysis is to use
tiled GeotTIffs and shapefiles with starspan.
matt
On 4/2/06, Hamish <hamish_nospam at yahoo.com> wrote:
> > How to collect raster pixels statistics (mean, min, max, stdev,
> > etc...) into polygons of a vector? I have been asked if this is
> > possible within GRASS GIS, but was unable to find a tool for that. In
> > Erdas, it is called "Zonal Attributes".
> > Anybody could please suggest a way,
>
> [cc grasslist as this is probably more suited for that list]
>
> [I'm assuming GRASS 6.1-cvs]
>
> v.what.rast will do values at vector points.
> r.what will query at given x,y.
> v.to.db will upload vector feature info (area,etc).
>
>
> for full vector area stats from a raster, you would need to do it
> using a series of grass commands to calculate the values then upload
> them to the vector's tables. The following is untested, but you should
> be able to adapt it to make it work...
>
>
> g.region rast=query_map
> v.to.rast use=attr
>
> #add new coulumns
> v.db.addcol columns=min,max,mean,stdev
>
> then use values from `r.describe -q1` to give to r.mapcalc in a loop,
>
> for VALUE in `r.describe -q1 v_to_rast_map` ; do
> echo "Processing $VALUE ..."
> # set mask to just the polygon of interest
> r.mapcalc "MASK=if(v_to_rast_map == $VALUE)"
> # calc stats on that
> eval `r.univar -g query_map`
> if [ $? -ne 0 ] ; echo "error on val $VALUE" ; exit 1 ; fi
> # upload values to vector map
> echo "UPDATE vect_map SET min=$min WHERE cat=$VALUE" | db.execute
> echo "UPDATE vect_map SET max=$max WHERE cat=$VALUE" | db.execute
> g.remove MASK
> done
>
> # faster: save UPDATES to a file then run db.execute on that file when done
>
> This could be added to v.what.rast I guess. I am more interested in
> stats from a raster around a given buffer from each vector point..
>
>
>
> Hamish
>
>
--
Matt Perry
perrygeo at gmail.com
http://www.perrygeo.net
More information about the grass-user
mailing list