[GRASS-user] r.buffer

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Tue Oct 27 19:55:40 EDT 2009


Hi Alessandro!

Some ideas below...

On Tue, 2009-10-27 at 23:24 +0100, Alessandro Bertan wrote:
> Dear GRASS users,
> 
> I am a GRASS newbie, so I apologise in advance for the simplicity of
> my question. I have a set of sites and I would like to create a series
> of circular buffers around each site and then use r.stats to extract
> some information from each buffer in combination with a land cover
> map. My problem is that if I simply use the v.to.rast and r.buffer
> commands to obtain the buffers, many of these will clash into each
> other because  the sites are too close. I was wondering whether there
> is any script out there capable of creating buffers one at the time
> starting from a set of sites and then using the r.stats command to
> extract info from data layer. If not, I would be really happy if you
> could point me in the right direction!

Just an (untested) idea: why not create all buffers as separate, unique
raster (with r.buffer) or vector (with v.buffer) maps and loop over
them? Are the sites _too_ many?



> I have found some code (see
> below) that has proved useful, but does not do exactly what I want.

I think the code below will give stats based on the queried map _and_
only within the defined geographic region (g.region -p).

Better to use r.statistics, for example the command (within the loop
over the sites) could look like:
r.statistics base=BUFFER cover=LANDCOVER method=diversity



> Basically, by starting from a set coordinates, the script is capable
> of zooming into a region around each site and extracting the relevant
> information using the r.stats command. Unfortunately I have no clue on
> how to create the individual buffers. Any help would be appreciated!
> 
> thanks!
> 
> Alessandro

Best regards, Nikos



--%<--
> #!/bin/sh
> 
> #replace 'foo' with name of input file (easting and northing)
> #replace 'outfile' with name of output file
> #replace 'LCM2000a' with the name of the map from where you want to
> extract some information
> 
> 
> numSites=`wc -l foo | awk '{print $1}'`
> 
> winSize=500
> 
> for (( site=1 ; site <= $numSites ; site++ ));
>   do
>   cent_e=`awk '{if(NR=='$site') printf("%.0f", $1)}' foo`
>   cent_n=`awk '{if(NR=='$site') printf("%.0f", $2)}' foo`
> 
>   echo POINT $site e=$cent_e n=$cent_n
> 
>   nrth=`expr $cent_n + $winSize`
>   soth=`expr $cent_n - $winSize`
>   east=`expr $cent_e + $winSize`
>   west=`expr $cent_e - $winSize`
> 
>   echo SITE $site n=$nrth s=$soth e=$east w=$west
> 
>   g.region n=$nrth s=$soth e=$east w=$west res=25
>   d.erase
>   d.rast LCM2000a
> 
>   r.stats -cn LCM2000a > hab.temp
>   awk '{print '$site', $0,$1}' hab.temp >> outfile
> 
>   done
> 
> #g.region rast=LCM2000a
--%<--



More information about the grass-user mailing list