[R-sig-Geo] Long/Lat coordinates inside a complex spherical polygon

Robert J. Hijmans r.hijmans at gmail.com
Wed Jun 23 00:27:26 CEST 2010


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:
> Hi,
>
> What R package provides a way to determine if a longitude/latitude
> coordinate is situated inside a closed, complex spherical polygon (i.e., a
> point inside a polygon on Earth's surface)?
>
> For example:
>
> p <- rbind( c(-123.4447,48.5146), c(-123.3171,48.5128),
> c(-123.2607,48.4108), c(-123.4018,48.4099), c(-123.4447,48.5146) )
>
> ll <- c(-123.3501,48.4902)
>
> print( isInside( ll, p ) )
>
> I have looked at the following packages:
>
>   - geosphere
>   - GEOmap
>
> I could not find anything else at CRAN that looked suitable.
>
> A good article on the subject is at:
>
> trs-new.jpl.nasa.gov/dspace/bitstream/2014/40409/1/07-03.pdf
>
> Thank you!
> Dave
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list