Quantcast

SpatialPoints, SpatialGrid and related terminology

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

SpatialPoints, SpatialGrid and related terminology

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




--
Botswana Predator Conservation Trust
Gabriel Cozzi
Private Bag 13
Maun - Botswana
E-mail: [hidden email]
Mobile: +26774259312


Institute of Environmental Sciences
Gabriel Cozzi
Zurich University
Winterthurerstr. 190
8057 Zurich - Switzerland
E-mail: [hidden email]
Phone: ++4(0)446355204
Fax: ++41(0)16355711
http://www.uzh.ch/uwinst
http://african-carnivores.com

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SpatialPoints, SpatialGrid and related terminology

Tom Gottfried-3
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
>
>
>
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SpatialPoints, SpatialGrid and related terminology

Giuseppe Calamita
In reply to this post by Gabriele Cozzi
Ciao Gabriele,
you can find a shorter yet very useful descriptions of how spatial classes work in one of the vignettes of the sp-package.

To visualize that, simply write on R terminal
> vignette("intro_sp")
this will open a pdf.
You can also download it directly from http://cran.r-project.org/web/packages/sp/vignettes/intro_sp.pdf

If you use
> vignette(package= "sp")
you'll see all the available vignette in that package, whereas if you use
> vignette()
you'll see ALL the available vignette in all the installed package (this may take a long time).

Hope this helps
Giuseppe
Giusepep Calamita
PhD italian National Council of Research - Institute of Methodologies for Environmental Research CNR - IMAA
85050 Tito Scalo - Potenza - Italy
Loading...