inside {fastshp}R Documentation

Finds shapes that contain given points


inside returns indices of shapes that contain given points


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



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


x coordinates of the points to match


y coordinates of the points to match


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


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


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.


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.


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


Simon Urbanek

[Package fastshp version 0.1-2 Index]