[R-sig-Geo] Extract values in spsample()

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sat Nov 19 20:56:25 CET 2011



On 11/19/2011 04:03 PM, ASANTOS wrote:
> Dear colleges,
> 
>     I need to create a object wit the coordinates of a grid and the
> values in the point sampled, using the meuse.grid example:
> 
> ## regular sampling over a grid
> library(sp)
> data(meuse.grid)
> gridded(meuse.grid) = ~x+y
> image(meuse.grid["dist"])
> points(spsample(meuse.grid,n=1000,type="regular"), pch=3, cex=.4)
> 
> but here I don't how I can find the value in the image associated with
> the grid, there are any suggestion?

> pts = spsample(meuse.grid,n=1000,type="regular")
> over(pts, meuse.grid)[1:10,]
   part.a part.b      dist soil ffreq
1       0      1 0.0000000    1     1
2       0      1 0.0000000    1     1
3       0      1 0.0054321    1     1
4       0      1 0.0000000    1     1
5       0      1 0.0000000    1     2
6       0      1 0.0000000    1     2
7       0      1 0.0000000    1     1
8       0      1 0.0264645    1     1
9       0      1 0.0537778    1     1
10      0      1 0.0593610    1     1
> dim(over(pts, meuse.grid))
[1] 1012    5
> class(over(pts, meuse.grid))
[1] "data.frame"

see also http://cran.r-project.org/web/packages/sp/vignettes/over.pdf

Hth,
-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list