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

Tom Gottfried tom.gottfried at tum.de
Tue Dec 20 17:37:55 CET 2011


Hi,

Am 20.12.2011 16:43, schrieb Dieter Vanderelst:
> 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.

Use spplot() for the polygons and the sp.layout argument for the points. 
See ?spplot.

> 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.

What did you try already? Some lines of code would be helpful. In any 
case, what you can use is over() from the sp package (overlay is 
deprecated).

regards,
Tom

> Any thoughts on how to select polygons based on coordinates using
> maptools would be most welcome.
>
> Regards,
> Dieter
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Technische Universität München
Department für Pflanzenwissenschaften
Lehrstuhl für Grünlandlehre
Alte Akademie 12
85350 Freising / Germany
Phone: ++49 (0)8161 715324
Fax:   ++49 (0)8161 713243
email: tom.gottfried at wzw.tum.de
http://www.wzw.tum.de/gruenland



More information about the R-sig-Geo mailing list