[R-sig-Geo] Grids clipped with polygon

Adrian Baddeley adrian at maths.uwa.edu.au
Thu Aug 4 06:01:48 CEST 2005


Susumu Tanimura <stanimura-ngs at umin.ac.jp> writes:

> Grids clipped with polygon is just required for my kriging analysis,
> but I could not succeed so far. 

If your grid points have coordinate vectors xg, yg
and the polygon's vertices have coordinate vectors xp, yp
(in anticlockwise order without repetition)
then the following will work

      library(spatstat)
      g <- ppp(xg,yg, range(xg), range(yg))
      w <- owin(poly=list(x=xp,y=yp))
      gsub <- g[ , w]

Then gsub consists of the grid points within the polygon.
The coordinates can be extracted as gsub$x and gsub$y.

HTH
Adrian Baddeley




More information about the R-sig-Geo mailing list