Assesses whether points are inside a boundary. The boundary must enclose the domain, but may include islands.
This should have two equal length columns with names matching whatever is
x co-ordinates of points to be tested.
y co-ordinates of points to be tested.
Segments of boundary are separated by
NAs, or are in separate list elements.
The boundary co-ordinates are taken to define nodes which are joined by straight line segments in
order to create the boundary. Each segment is assumed to
define a closed loop, and the last point in a segment will be assumed to be
joined to the first. Loops must not intersect (no test is made for
The method used is to count how many times a line, in the y-direction from a point, crosses a boundary segment. An odd number of crossings defines an interior point. Hence in geographic applications it would be usual to have an outer boundary loop, possibly with some inner ‘islands’ completely enclosed in the outer loop.
The routine calls compiled C code and operates by an exhaustive search for
each point in
The function returns a logical array of the same dimension as
TRUE indicates that the corresponding
x, y point lies
inside the boundary.
Simon N. Wood email@example.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14
require(mgcv) m <- 300;n <- 150 xm <- seq(-1,4,length=m);yn<-seq(-1,1,length=n) x <- rep(xm,n);y<-rep(yn,rep(m,n)) er <- matrix(fs.test(x,y),m,n) bnd <- fs.boundary() in.bnd <- inSide(bnd,x,y) plot(x,y,col=as.numeric(in.bnd)+1,pch=".") lines(bnd$x,bnd$y,col=3) points(x,y,col=as.numeric(in.bnd)+1,pch=".") ## check boundary details ... plot(x,y,col=as.numeric(in.bnd)+1,pch=".",ylim=c(-1,0),xlim=c(3,3.5)) lines(bnd$x,bnd$y,col=3) points(x,y,col=as.numeric(in.bnd)+1,pch=".")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.