[GRASSLIST:7347] v.sample.buffer

Some months ago I mentioned I had written a modified version of v.sample to extract data and calculate basic stats (min,max,mean,mode,diversity,variance,..) within a user specified buffer and append this data into new columns of the vector file's attribute table. It has only been tested with point vector files, but should theoretically work with linear or area features also.

I have finally brought it up to the standard for inclusion on Michael Barton's script exchange and submitted it to him.

I wrote it for my work on grassland habitat selection modeling and found it very helpful once I got it working to quickly and easily extract raster data from my survey sites. Thanks again to Hamish who gave me the suggestion as to how to do it. I hope it is useful to others also.

T
--
Trevor Wiens
twiens@spacelan.ne.jp

The greatest obstacle to discovery is not ignorance - it is the illusion of knowledge.
(Daniel J. Boorstin)

latest from cvs:

[root@localhost r.terraflow]# make
Makefile:78: warning: overriding commands for target `clean'
../../include/Make/Rules.make:35: warning: ignoring old commands for
target `clean'
mkdir -p OBJ.x86_64-unknown-linux-gnu/FLOAT ; true
mkdir -p OBJ.x86_64-unknown-linux-gnu/SHORT ; true
c++ -c -g -O2 -I./IOStream/include -DUSER=\"root\" -DNODATA_FIX
-D_FILE_OFFSET_BITS= 64 -I/dls/grass/grass6/include -DELEV_FLOAT main.cc
-o OBJ.x86_64-unknown-linux-gnu/ FLOAT/main.o
./IOStream/include/replacementHeap.h:155: error: invalid use of
constructor as a tem plate
./IOStream/include/replacementHeap.h:155: note: use ‘ReplacementHeap<T,
Compare>::Re placementHeap’ instead of ‘ReplacementHeap<T,
Compare>::ReplacementHeap<T, Compare>’ to name the constructor in a
qualified name
./IOStream/include/replacementHeapBlock.h:161: error: invalid use of
constructor as a template
./IOStream/include/replacementHeapBlock.h:161: note: use
‘ReplacementHeapBlock<T, Co mpare>::ReplacementHeapBlock’ instead of
‘ReplacementHeapBlock<T, Compare>::Replacem entHeapBlock<T, Compare>’ to
name the constructor in a qualified name
make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1

On Tue, 28 Jun 2005 15:42:06 -0400 (EDT)
"Thomas Colson" <tom_colson@ncsu.edu> wrote:

latest from cvs:

[root@localhost r.terraflow]# make
Makefile:78: warning: overriding commands for target `clean'
../../include/Make/Rules.make:35: warning: ignoring old commands for
target `clean'
mkdir -p OBJ.x86_64-unknown-linux-gnu/FLOAT ; true
mkdir -p OBJ.x86_64-unknown-linux-gnu/SHORT ; true
c++ -c -g -O2 -I./IOStream/include -DUSER=\"root\" -DNODATA_FIX
-D_FILE_OFFSET_BITS= 64 -I/dls/grass/grass6/include -DELEV_FLOAT main.cc
-o OBJ.x86_64-unknown-linux-gnu/ FLOAT/main.o
./IOStream/include/replacementHeap.h:155: error: invalid use of
constructor as a tem plate
./IOStream/include/replacementHeap.h:155: note: use _ReplacementHeap<T,
Compare>::Re placementHeap_ instead of _ReplacementHeap<T,
Compare>::ReplacementHeap<T, Compare>_ to name the constructor in a
qualified name
./IOStream/include/replacementHeapBlock.h:161: error: invalid use of
constructor as a template
./IOStream/include/replacementHeapBlock.h:161: note: use
_ReplacementHeapBlock<T, Co mpare>::ReplacementHeapBlock_ instead of
_ReplacementHeapBlock<T, Compare>::Replacem entHeapBlock<T, Compare>_ to
name the constructor in a qualified name
make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1

I see 64 bitness; is this GCC 4.0?

a patch was already posted:
  
  http://grass.itc.it/pipermail/grass5/2005-June/018638.html

Hamish

How does one apply this (and other) patches?

[root@localhost r.terraflow]# patch IOStream/include/replacementHeap.h
r.terraflow.pat
patching file IOStream/include/replacementHeap.h
Hunk #1 FAILED at 152.
1 out of 1 hunk FAILED -- saving rejects to file
IOStream/include/replacementHeap.h.rej
can't find file to patch at input line 34
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: IOStream/include/replacementHeapBlock.h
|===================================================================
|RCS
file: /grassrepository/grass6/raster/r.terraflow/IOStream/include/replacementHeapBlock.h,v
|retrieving revision 2.0
|diff -u -r2.0 replacementHeapBlock.h
|--- IOStream/include/replacementHeapBlock.h 9 Nov 2004 13:30:45
-0000 2.0
|+++ IOStream/include/replacementHeapBlock.h 15 Jun 2005 12:18:41
-0000

grasslist@baylor.edu

On Wed, 2005-06-29 at 15:40 +1200, Hamish wrote:

On Tue, 28 Jun 2005 15:42:06 -0400 (EDT)
"Thomas Colson" <tom_colson@ncsu.edu> wrote:

> latest from cvs:
>
> [root@localhost r.terraflow]# make
> Makefile:78: warning: overriding commands for target `clean'
> ../../include/Make/Rules.make:35: warning: ignoring old commands for
> target `clean'
> mkdir -p OBJ.x86_64-unknown-linux-gnu/FLOAT ; true
> mkdir -p OBJ.x86_64-unknown-linux-gnu/SHORT ; true
> c++ -c -g -O2 -I./IOStream/include -DUSER=\"root\" -DNODATA_FIX
> -D_FILE_OFFSET_BITS= 64 -I/dls/grass/grass6/include -DELEV_FLOAT main.cc
> -o OBJ.x86_64-unknown-linux-gnu/ FLOAT/main.o
> ./IOStream/include/replacementHeap.h:155: error: invalid use of
> constructor as a tem plate
> ./IOStream/include/replacementHeap.h:155: note: use _ReplacementHeap<T,
> Compare>::Re placementHeap_ instead of _ReplacementHeap<T,
> Compare>::ReplacementHeap<T, Compare>_ to name the constructor in a
> qualified name
> ./IOStream/include/replacementHeapBlock.h:161: error: invalid use of
> constructor as a template
> ./IOStream/include/replacementHeapBlock.h:161: note: use
> _ReplacementHeapBlock<T, Co mpare>::ReplacementHeapBlock_ instead of
> _ReplacementHeapBlock<T, Compare>::Replacem entHeapBlock<T, Compare>_ to
> name the constructor in a qualified name
> make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1
>
>

I see 64 bitness; is this GCC 4.0?

a patch was already posted:
  
  http://grass.itc.it/pipermail/grass5/2005-June/018638.html

Hamish

Belay that: cvs update fixed whatever was bothering the patch code.

thanks for the pointer to the patch. is there a list of patches that are
being put out by Brad?

On Wed, 2005-06-29 at 09:19 -0400, Tom Colson wrote:

How does one apply this (and other) patches?

[root@localhost r.terraflow]# patch IOStream/include/replacementHeap.h
r.terraflow.pat
patching file IOStream/include/replacementHeap.h
Hunk #1 FAILED at 152.
1 out of 1 hunk FAILED -- saving rejects to file
IOStream/include/replacementHeap.h.rej
can't find file to patch at input line 34
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: IOStream/include/replacementHeapBlock.h
|===================================================================
|RCS
file: /grassrepository/grass6/raster/r.terraflow/IOStream/include/replacementHeapBlock.h,v
|retrieving revision 2.0
|diff -u -r2.0 replacementHeapBlock.h
|--- IOStream/include/replacementHeapBlock.h 9 Nov 2004 13:30:45
-0000 2.0
|+++ IOStream/include/replacementHeapBlock.h 15 Jun 2005 12:18:41
-0000

grasslist@baylor.edu

On Wed, 2005-06-29 at 15:40 +1200, Hamish wrote:
> On Tue, 28 Jun 2005 15:42:06 -0400 (EDT)
> "Thomas Colson" <tom_colson@ncsu.edu> wrote:
>
> > latest from cvs:
> >
> > [root@localhost r.terraflow]# make
> > Makefile:78: warning: overriding commands for target `clean'
> > ../../include/Make/Rules.make:35: warning: ignoring old commands for
> > target `clean'
> > mkdir -p OBJ.x86_64-unknown-linux-gnu/FLOAT ; true
> > mkdir -p OBJ.x86_64-unknown-linux-gnu/SHORT ; true
> > c++ -c -g -O2 -I./IOStream/include -DUSER=\"root\" -DNODATA_FIX
> > -D_FILE_OFFSET_BITS= 64 -I/dls/grass/grass6/include -DELEV_FLOAT main.cc
> > -o OBJ.x86_64-unknown-linux-gnu/ FLOAT/main.o
> > ./IOStream/include/replacementHeap.h:155: error: invalid use of
> > constructor as a tem plate
> > ./IOStream/include/replacementHeap.h:155: note: use _ReplacementHeap<T,
> > Compare>::Re placementHeap_ instead of _ReplacementHeap<T,
> > Compare>::ReplacementHeap<T, Compare>_ to name the constructor in a
> > qualified name
> > ./IOStream/include/replacementHeapBlock.h:161: error: invalid use of
> > constructor as a template
> > ./IOStream/include/replacementHeapBlock.h:161: note: use
> > _ReplacementHeapBlock<T, Co mpare>::ReplacementHeapBlock_ instead of
> > _ReplacementHeapBlock<T, Compare>::Replacem entHeapBlock<T, Compare>_ to
> > name the constructor in a qualified name
> > make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1
> >
> >
>
> I see 64 bitness; is this GCC 4.0?
>
> a patch was already posted:
>
> http://grass.itc.it/pipermail/grass5/2005-June/018638.html
>
>
>
>
> Hamish

Tom,

Move the patch file to the IOStream/include directory and then run

patch < r.terraflow.pat

Larger patches are typically applied higher up in the source tree, but
this one was pretty local. If it still doesn't work, the patch is small
enough that you can make the edits manually. In replacementHeap.h line
152, take out the second occurrence of <T, Compare> in the constructor,
before the "(size_t ..)". You need to do a similar thing for
replacementHeapBlock.h line 157.

-Andy

On Wed, 2005-06-29 at 09:19 -0400, Tom Colson wrote:

How does one apply this (and other) patches?

[root@localhost r.terraflow]# patch IOStream/include/replacementHeap.h
r.terraflow.pat
patching file IOStream/include/replacementHeap.h
Hunk #1 FAILED at 152.
1 out of 1 hunk FAILED -- saving rejects to file
IOStream/include/replacementHeap.h.rej
can't find file to patch at input line 34
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|Index: IOStream/include/replacementHeapBlock.h
|===================================================================
|RCS
file: /grassrepository/grass6/raster/r.terraflow/IOStream/include/replacementHeapBlock.h,v
|retrieving revision 2.0
|diff -u -r2.0 replacementHeapBlock.h
|--- IOStream/include/replacementHeapBlock.h 9 Nov 2004 13:30:45
-0000 2.0
|+++ IOStream/include/replacementHeapBlock.h 15 Jun 2005 12:18:41
-0000

grasslist@baylor.edu

On Wed, 2005-06-29 at 15:40 +1200, Hamish wrote:
> On Tue, 28 Jun 2005 15:42:06 -0400 (EDT)
> "Thomas Colson" <tom_colson@ncsu.edu> wrote:
>
> > latest from cvs:
> >
> > [root@localhost r.terraflow]# make
> > Makefile:78: warning: overriding commands for target `clean'
> > ../../include/Make/Rules.make:35: warning: ignoring old commands for
> > target `clean'
> > mkdir -p OBJ.x86_64-unknown-linux-gnu/FLOAT ; true
> > mkdir -p OBJ.x86_64-unknown-linux-gnu/SHORT ; true
> > c++ -c -g -O2 -I./IOStream/include -DUSER=\"root\" -DNODATA_FIX
> > -D_FILE_OFFSET_BITS= 64 -I/dls/grass/grass6/include -DELEV_FLOAT main.cc
> > -o OBJ.x86_64-unknown-linux-gnu/ FLOAT/main.o
> > ./IOStream/include/replacementHeap.h:155: error: invalid use of
> > constructor as a tem plate
> > ./IOStream/include/replacementHeap.h:155: note: use _ReplacementHeap<T,
> > Compare>::Re placementHeap_ instead of _ReplacementHeap<T,
> > Compare>::ReplacementHeap<T, Compare>_ to name the constructor in a
> > qualified name
> > ./IOStream/include/replacementHeapBlock.h:161: error: invalid use of
> > constructor as a template
> > ./IOStream/include/replacementHeapBlock.h:161: note: use
> > _ReplacementHeapBlock<T, Co mpare>::ReplacementHeapBlock_ instead of
> > _ReplacementHeapBlock<T, Compare>::Replacem entHeapBlock<T, Compare>_ to
> > name the constructor in a qualified name
> > make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1
> >
> >
>
> I see 64 bitness; is this GCC 4.0?
>
> a patch was already posted:
>
> http://grass.itc.it/pipermail/grass5/2005-June/018638.html
>
>
>
>
> Hamish

I managed to get R compiled and all the packages talking to grass as it
should, and all the "demos" seem to work. There is a neat tutorial on
working with DEM (grass raster) in R
http://grass.itc.it/statsgrass/learning_r2.html#Working_with_elevation

Tutorial works great with the sample data provided...yet I can't figure
out how to get "current" raster dems in my mapset/location into a format
that is acceptable to R...re: the tutorial syntax. Been looking through
all the man pages, but there doesn't seem to be any documentation on
raster import that would allow one to go through that tutorial using
one's own data....

thanks.

> > [root@localhost r.terraflow]# make

As a general rule it's probably a bad idea to run "make" as root..
if something goes nuts during the build process you can do all sorts of
damage. Only need to be root for "make install".

...

> > ./IOStream/include/replacementHeap.h:155: error: invalid use of
> > constructor as a tem plate
> > ./IOStream/include/replacementHeap.h:155: note: use _ReplacementHeap<T,
> > Compare>::Re placementHeap_ instead of _ReplacementHeap<T,
> > Compare>::ReplacementHeap<T, Compare>_ to name the constructor in a
> > qualified name

...

> I see 64 bitness; is this GCC 4.0?
>
> a patch was already posted:
>
> http://grass.itc.it/pipermail/grass5/2005-June/018638.html

..

How does one apply this (and other) patches?

[root@localhost r.terraflow]# patch IOStream/include/replacementHeap.h
r.terraflow.pat
patching file IOStream/include/replacementHeap.h
Hunk #1 FAILED at 152.
1 out of 1 hunk FAILED -- saving rejects to file
IOStream/include/replacementHeap.h.rej
can't find file to patch at input line 34
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------

Method 1:
If it is small and you are an accurate type, just make the change by
hand in a text editor. Negative lines are what's removed, positive
is what needs to be added.

Method 2:
You need to get the -p level correct. Study the "patch" man page or if
you are an experimentalist just try -p levels 0-5 and see if one works.

general method:

patch -p0 < r.terraflow.patch

It gets the files to patch from inside the patch itself so you only have
to pipe in the "from" diff file.

bonus hint 1:

You make patches with the "diff -u" command, e.g.:

diff -u oldfile.txt newfile.txt > patch.diff

or if it's from a CVS snapshot & you've already logged in (anonymously),

cvs diff changed_file.txt > patch.diff

bonus hint 2:

make a ~/.cvsrc file containing the following:
-z3
diff -u
update -dP

This will take care of adding the -u when you do a cvs diff and other
helpful things.

Hamish

At least in GRASS 5.4 an R, there was a rast.get() function.

Carlos

On 6/29/05, Tom Colson <tom_colson@ncsu.edu> wrote:

I managed to get R compiled and all the packages talking to grass as it
should, and all the "demos" seem to work. There is a neat tutorial on
working with DEM (grass raster) in R
http://grass.itc.it/statsgrass/learning_r2.html#Working_with_elevation

Tutorial works great with the sample data provided...yet I can't figure
out how to get "current" raster dems in my mapset/location into a format
that is acceptable to R...re: the tutorial syntax. Been looking through
all the man pages, but there doesn't seem to be any documentation on
raster import that would allow one to go through that tutorial using
one's own data....

thanks.

--
+-----------------------------------------------------------+
              Carlos Henrique Grohmann - Guano
  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
Linux User #89721 - carlos dot grohmann at gmail dot com
+-----------------------------------------------------------+

To answer my own question...

start R from within Grass...

library(spgrass6)
G <-gmeta6()
dem <-readFLOAT6sp("timb_elev")
dem.def = as.data.frame(dem)
plot(ecdf(dem.def[["timb_elev"]]))
plot(density(dem.def[["timb_elev"]]))
lines(density(dem.def[["timb_elev"]],bw=2),col="green")
lines(density(dem.def[["timb_elev"]],bw=4),col="cyan")
lines(density(dem.def[["timb_elev"]],bw=8),col="red")
lines(density(dem.def[["timb_elev"]],bw=12),col="yellow")

legend(locator(), legend=c("bw=0","bw=2","bw=4","bw=8","bw=12"),
col=c("black","green","red","cyan","yellow"), lty=1)

On Wed, 2005-06-29 at 10:05 -0400, Tom Colson wrote:

I managed to get R compiled and all the packages talking to grass as it
should, and all the "demos" seem to work. There is a neat tutorial on
working with DEM (grass raster) in R
http://grass.itc.it/statsgrass/learning_r2.html#Working_with_elevation

Tutorial works great with the sample data provided...yet I can't figure
out how to get "current" raster dems in my mapset/location into a format
that is acceptable to R...re: the tutorial syntax. Been looking through
all the man pages, but there doesn't seem to be any documentation on
raster import that would allow one to go through that tutorial using
one's own data....

thanks.