inside: Finds shapes that contain given points

Description Usage Arguments Details Value Note Author(s)

View source: R/inside.R

Description

inside returns indices of shapes that contain given points

Usage

1
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


s-u/fastshp documentation built on May 28, 2019, 10:47 a.m.