[R-sig-Geo] SpatialPoints, SpatialGrid and related terminology
Tom Gottfried
tom.gottfried at o2mail.de
Thu Jun 28 13:52:49 CEST 2012
Gabriele,
it would be surely very useful for you to read the ASDAR-book:
Bivand, Roger S., Edzer J. Pebesma, und Virgilio Gómez-Rubio. Applied
spatial data analysis with R. Use R! New York: Springer, 2008.
http://www.asdar-book.org/;
http://www.springerlink.com/content/978-0-387-78170-9.
Besides this, your approach with using over on point data seems the way
you have to go. In grid cells with a size of 2500 m over would find more
than one point from your finer grid.
HTH,
Tom
Am 28.06.2012 12:32, schrieb Gabriele Cozzi:
> Dear list,
> apologize for the unusual question. I am new and I have some problems with
> some of the terminology.
> I had my codes running but only after trial and error rather than with a
> full understanding of what is what and this does not entirely satisfy me.
>
> I have a data frame (call it grid1) containing X, Y coordinates along with
> other variables
> Locations are spaced 500 m apart on on a grid. Here an example with random
> data:
>
> ##-------------
> X1<- rep(seq(0,20000, by=500)
> , each=45)
> Y1<- rep(seq(0,20000, by=500)
> , 45)
> grid1<- data.frame(X1,Y1,
> value=rep("val", length(X1)))
> plot(grid1$X1,grid1$Y1, cex=0.1)
> ##--------------
>
>
> I want to extract from grid 1 only those locations, and relative values,
> that are spaced 2500 m apart, so basically those locations that overlap
> with a second data frame (call it grid2). In other words those locations
> where dots overlap with circles (cfr. the plot in the codes below)
>
> ##--------------
> X2<- rep(seq(0,20000, by=2500)
> , each=9)
> Y2<- rep(seq(0,20000, by=2500)
> , 9)
> grid2<- data.frame(X2,Y2)
> points(grid2$X2,grid2$Y2)
> ##----------------
>
>
> I believe this can be easily achieved with the over() function in {sp} :
>
> ##----------------
> over(grid2,grid1)
> ##---------------
>
> But I see that arguments of the form "data.frame" cannot be passed to
> over() that instead accept arguments of the form SpatialPoints,
> SpatialGridsDataFrame and so on.
>
> I passed the arguments in the form SpatialPoints and SpatialPointsDataFrame
> yet I do not fully grasp the difference with (say) SpatialGrid.
>
>
> ##-------------
> over(SpatialPoints(coords=coordinates(grid2)),
> SpatialPointsDataFrame(coords=grid1[c("X1", "Y1")], data=grid1))
> ##-------------
>
> I am reading: http://cran.r-project.org/web/packages/sp/sp.pdf
> but still I am struggling to fully understand.
>
> Any comments on the terminology and the best approach to solve my problem
> would be appreciated.
> Hopefully this will be of any use for other list members.
>
> Gabriele
>
>
>
>
More information about the R-sig-Geo
mailing list