Skip to content

Long/Lat coordinates inside a complex spherical polygon

2 messages · David Jarvis, Robert J. Hijmans

#
David, You can use overlay in sp, but that does not consider the
inter-vertex curvature of the polygons. If this is a concern (i.e.
your have polygons with vertices that are far apart), you could first
uses geosphere::makePoly  to at least avoid the worst mistakes (as in
the example below). For relatively small polygons with a reasonable
number of vertices it would probably not make much of a difference.
Robert

library(sp)
library(geosphere)

pol <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-60), c(-180,-20))
sp1 <- SpatialPolygons(list(Polygons(list(Polygon(pol)), 1)))
sp2 <- makePoly(pol, interval=100000, sp=T)

pt = data.frame(cbind(x=-111, y=-41))
coordinates(pt) = ~ x + y

# pt is (incorrectly) outside sp1
overlay(pt, sp1)
# but (correctly) inside (polygon #1)
overlay(pt, sp2)

plot(sp1)
plot(sp2, add=T, border='red')
points(pt, col='blue', cex='x', pch=2)
On Tue, Jun 22, 2010 at 2:37 PM, David Jarvis <thangalin at gmail.com> wrote: