| in.poly {climdiv} | R Documentation |
tests geographic coordinates in an array for inclusion within a list of polygons.
in.poly(pts, polys)
pts |
Nx2 array of lon and lat values. If there is only one row in pts, you need to make sure pts is a matrix with two dimensions. |
polys |
a polygon list like that returned by Map2poly in maptools. |
tests geographic coordinates in an array for inclusion within a list of polygons.
Returns an array with the coordinates and an index number corresponding to the polygon in polys that contains each coordinate.
If you get errors when pts has only one row, a simple solution is to add a second row with dummy coordinates.
Anthony L. Westerling http://meteora.ucsd.edu/~westerli/westerling.html
in preparation
## The function is currently defined as
function(pts,polys){
n.pts=dim(pts)[1]
n.ply=length(polys)
Z=array(NA,c(n.pts,3))
Z[,1:2]=pts
for(i in 1:n.pts){
j=1
loop=TRUE
while (loop){
test=inout(t(pts[i,]),polys[[j]])
if(test){
Z[i,3]=j
loop=FALSE
}
if(j>=n.ply){loop=FALSE}
j=j+1
}
}
Z
}