[GRASSLIST:5403] Re: Script to 'sample' several grids with result saved to text output?

Dylan Beaudette dylan at iici.no-ip.org
Mon Jan 17 18:40:45 EST 2005


On Monday 17 January 2005 06:59 am, Sander Oom wrote:
> Dear R-geo and GRASS users,
>
> -Before trying to reinvent the wheel I would like to check whether
> someone has tried this before.-
>
> I have several rasters with environmental data. I also have point data,
> representing animal locations (collected with GPS collars).
>
> I would like to use GRASS to 'sample' (apologies for the ArcInfo AML
> terminology, but it might help people to get what I need) the rasters
> with the point data and save the results in a text file for further
> analysis with R.
>
> The resulting text file should contain a field/attribute of my choice
> from the points data file (some sort of ID for each point) and a
> field/attribute for each of the sampled rasters.
>
> Preferably I would use an R script that calls GRASS, as both point data
> collection and further analysis is done within R. However a GRASS script
> working on input and output text files might also be sufficient.
>
> Any help would be much appreciated,
>
> Sander Oom.
>
> PS: I am a total novice with GRASS.

In the past I have used 's.sample' in GRASS54 to "sample" many rasters at 
given site locations...

here is some sample code:

#export digitized gras57 vectors as sites (from GRASS57):
s.out.ascii input=b_sites > b_sites.xy

#load exported grass57 vector sites (GRASS53):
s.in.ascii sites=beam_sample_sites input=b_sites.xy

#sample the rasters in a for loop!
for x in `seq 1 364`; do a=`s.sample input=beam_sample_sites \
rast=beam$x -q -C | awk -F"%" '{ORS = " "}{print $2}'`; echo $x $a \
; done > data.out

Cheers

-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341




More information about the grass-user mailing list