[R-sig-Geo] Finding out in which polygon a point lies

Dieter Vanderelst dieter.vanderelst at gmail.com
Tue Dec 20 16:43:50 CET 2011


Dear List,

I've read in a shapefile using the readShapePoly {maptools} function.
This shapefile represents Angola and has different polygons for the
different regions of the country. I also have a set of coordinates
(lat/long). Now want to do two things:

1 - I want to plot the points on the map. Given that both my points
and the shapefile use the same coordinate reference system
(latitude/longitude) and theWGS84 datum, I think I can just use the
function plot(lon,lat). Please correct me I if I'm wrong here.

2 - The second problem is a bit harder. I want to color the polygons
which contain one or more points. How can I check in which polygon
each of the points lie. I found a partial explanation online on how to
do this with the sp package (see
https://stat.ethz.ch/pipermail/r-help/2009-February/187435.html).
However, I haven't been able to reconstruct the method suggested in
this post.

Any thoughts on how to select polygons based on coordinates using
maptools would be most welcome.

Regards,
Dieter



More information about the R-sig-Geo mailing list