r.buffer

9 messages Options
Embed this post
Permalink
Alessandro Bertan

r.buffer

Reply Threaded More More options
Print post
Permalink
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! I have found some code (see
below) that has proved useful, but does not do exactly what I want.
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


#!/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
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Nikos Alexandris

Re: r.buffer

Reply Threaded More More options
Print post
Permalink
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
--%<--

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
hamish-2

Re: r.buffer

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alessandro Bertan
there are some addon scripts listed in the wiki to do this task for you,

http://grass.osgeo.org/wiki/GRASS_AddOns#v.what.rast.buffer

I am pretty sure there is another one too, perhaps already moved into
the main source tree using v.rast.stats or v.what.rast?


see also
 http://grass.osgeo.org/wiki/GRASS_AddOns#g.region.point


??v.sample.buffer?? addon
and fast stats using 3rd party program called starspan (??)


Alessandro:

> 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! I have found some
> code (see
> below) that has proved useful, but does not do exactly what
> I want.
> 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
>
>
> #!/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
> _______________________________________________
> grass-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-user
>



_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Alessandro Bertan

Re: r.buffer

Reply Threaded More More options
Print post
Permalink
Hi!

Thank you for your useful indications! It seems that the addon
v.what.rast.buffer is capable of doing what I want. I am trying to
modify it by substituting r.univar -g with r.stats -anl but I get the
following error message:

Calculating stats for cat  ...
Sorry, <map> is not a valid parameter

ERROR: Required parameter <input> not set:
   (Name of input raster map(s)).

I would greatly appreciate if you give me some suggestions on how me
to solve this problem!

thanks again!

Alessandro
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
FAROUX STEPHANIE

projections

Reply Threaded More More options
Print post
Permalink
In reply to this post by hamish-2
Hello everybody,
I'd like to know how to do with such projections:
Lambert III
United Kingdom
L-EST'92
CS_KKJ24North
They are not available in the list at the creation of a new location.
Thanks
Stéphanie
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
John A Stevenson

Re: projections

Reply Threaded More More options
Print post
Permalink
FAROUX STEPHANIE wrote:
> United Kingdom
Hi Stephanie,

# OSGB 1936 / British National Grid
<27700> +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
+y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs  <>

The EPSG code is 27700.  Beware that old versions of proj (prior to
October 2007) don't have the OSGB36 datum and will plot your data offset
by up to 100 m.

Later

John


--


Dr John Stevenson
Postdoctoral Research Associate
School of Earth, Atmospheric and Environmental Sciences
Williamson Building (Room 2.42)
University of Manchester
Manchester M13 9PL, UK
tel. +44(0)161 306 6585; fax. +44(0)161 306 9361;
[hidden email]

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Alexandre VILLERS

Re: projections

Reply Threaded More More options
Print post
Permalink
In reply to this post by FAROUX STEPHANIE
Hey

Did you look at spatial http://www.spatialreference.org/ for the EPSG
code, which you can then add to the list with the corresponding
parameters...
Best regards

Alex

FAROUX STEPHANIE a écrit :

> Hello everybody,
> I'd like to know how to do with such projections:
> Lambert III
> United Kingdom
> L-EST'92
> CS_KKJ24North
> They are not available in the list at the creation of a new location.
> Thanks
> Stéphanie
> _______________________________________________
> grass-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
>
> __________ Information from ESET Mail Security, version of virus
> signature database 4552 (20091028) __________
>
> The message was checked by ESET Mail Security.
> http://www.eset.com
>
>
>
>
>

--
Alexandre Villers
PhD Candidate
AgriPop
Centre d'Etudes Biologiques de Chizé-CNRS UPR1934
79360 Beauvoir sur Niort

Phone +33 (0)5 49 09 96 13
Fax   +33 (0)5 49 09 65 26




__________ Information from ESET Mail Security, version of virus signature database 4552 (20091028) __________

The message was checked by ESET Mail Security.
http://www.eset.com


_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Vincent Bain

Re: projections

Reply Threaded More More options
Print post
Permalink
In reply to this post by FAROUX STEPHANIE
Hi Stephanie,

concerning the first one, maybe you mean the french Lambert zone III
(available for southern France), whose EPSG code is 27573.

For exotic searches through the EPSG database, perhaps you should have a
look there :
http://www.epsg-registry.org/

If nothing matches your needs, you'll have to create locations by
yourself, which requires to know geodetic definition for each.


Yours,
Vincent.


Le mercredi 28 octobre 2009 à 16:31 +0100, FAROUX STEPHANIE a écrit :

> Hello everybody,
> I'd like to know how to do with such projections:
> Lambert III
> United Kingdom
> L-EST'92
> CS_KKJ24North
> They are not available in the list at the creation of a new location.
> Thanks
> Stéphanie
> _______________________________________________
> grass-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-user
>

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Giovanni Pasini

Re: r.buffer

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alessandro Bertan
Alessandro Bertan ha scritto:

> Hi!
>
> Thank you for your useful indications! It seems that the addon
> v.what.rast.buffer is capable of doing what I want. I am trying to
> modify it by substituting r.univar -g with r.stats -anl but I get the
> following error message:
>
> Calculating stats for cat  ...
> Sorry, <map> is not a valid parameter
>
> ERROR: Required parameter <input> not set:
>    (Name of input raster map(s)).
>
> I would greatly appreciate if you give me some suggestions on how me
> to solve this problem!
>
> thanks again!
>
> Alessandro

Alessandro,
Some mounth ago I have modified the script to have a report for each
point into a text file. Here the code:

#%option
#% key: prefix_stats
#% type: string
#% gisprompt: new_file,file,output
#% key_desc: name
#% description: Name for output prefix stats data (if omitted or "-"
output to stdout)
#% required: no
#%end

[...]

PREFIX_STATS="$GIS_OPT_PREFIX_STATS"

[...]

if [ -e "$PREFIX_STATS" ] ; then
     g.message -e "Output File [$PREFIX_STATS] already exists"
     exit 1
fi

[...]

g.message "  Calculating stats for cat $ID ..."
        echo $ID >> ${PREFIX_STATS}.txt
        r.stats -clN in="$MAP" fs="|" >> ${PREFIX_STATS}.txt
        eval `r.univar -g map="$MAP"`



Hope can help!
Giovanni


> _______________________________________________
> grass-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-user
>

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user