inside {fastshp}R Documentation

Finds shapes that contain given points

Description

inside returns indices of shapes that contain given points

Usage

inside(shp, x, y, clockwise = TRUE, all = FALSE)

Arguments

shp

shape object (as returned by read.shp(..., format="polygon")) to match against

x

x coordinates of the points to match

y

y coordinates of the points to match

clockwise

logical: if TRUE then polygons are oriented clockwise, otherwise counter-clockwise

all

logical: if TRUE then the result is a list of vectors listing all matches, otherwise only the first match per point is returned

Details

The matching uses bounding box as a first approximation and then winding rule (due east) to determine whether the point is inside. If more than one shape matches, the index of the first matching shape is returned unless all=TRUE is set in which case each entry is a list of all matches. Points exactly on the boundary (as far as possible by floating point arithmetics) are not considered inside. Note that the shape cooridnates must be in R polygon format (format="polygon" in read.shp) or have just one part, otherwise parts will not be treated properly.

Value

If all=FALSE: Integer vector of the same length as the number of points, each value is either an index of the first matching shape or NA if the point is not inside of any shapes.

If all=TRUE: List of integer vectors with the indices of matching shapes (which whill be empty if there is no match). There will be as many elements in the list as there are points.

Note

Holes are currently not considered by this method. There is a slower implementation using CGAL that treats holes properly.

Author(s)

Simon Urbanek


[Package fastshp version 0.1-0 Index]