Skip to content
Prev 169500 / 398506 Next

maptools: Test if point is in polygon

Renaud Lancelot <renaud.lancelot <at> gmail.com> writes:
The initial question was not put clearly. The pip function in splancs will 
work for a two-column matrix of points, but not for the object in question, 
if it was read in from a shapefile using readShapeSpatial(). In that case, 
the object is a SpatialPolygonsDataFrame as defined in the sp package, and 
the overlay() methods in sp should be the place to look - see 
?"overlay-methods". Typically, one would define the query point(s) as 
a SpatialPoints object, and overlay it on the input object. The output is 
a vector of indices, showing which Polygons object the points lie in, or NA 
if they do not.

Roger Bivand

PS. These kinds of questions typically get more focussed response on the 
R-sig-geo list; further, RSiteSearch() with 'point polygon' does show many 
useful avenues.