in.poly {climdiv}R Documentation

internal function called by in.climdiv

Description

tests geographic coordinates in an array for inclusion within a list of polygons.

Usage

in.poly(pts, polys)

Arguments

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.

Details

tests geographic coordinates in an array for inclusion within a list of polygons.

Value

Returns an array with the coordinates and an index number corresponding to the polygon in polys that contains each coordinate.

Note

If you get errors when pts has only one row, a simple solution is to add a second row with dummy coordinates.

Author(s)

Anthony L. Westerling http://meteora.ucsd.edu/~westerli/westerling.html

References

in preparation

See Also

inout, in.climdiv

Examples


## 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 
  }

[Package climdiv version 0.3 Index]