[R] point.in.polygon help

Hasan Diwan hasan.diwan at gmail.com
Sat Jan 14 01:30:31 CET 2012


  x <- sapply(c(1:max(greens[,1])), function() {
    poly.x <- greens[greens[,1] == hole, 2]
    poly.y <- greens[greens[,1] == hole, 3]
    p.x <- gps[,3]
    p.y <- gps[,4]
    require(sp)
    gps[which(point.in.polygon(p.x,p.y,poly.x,poly.y) != 0),ncol(gps)]
<- gps[which(point.in.polygon(p.x,p.y,poly.x,poly.y) != 0),ncol(gps)]
+ 0.2
}
gps is a set of GPS readings from a golf course and greens is a
data.frame consisting of coordinates for the 18 holes. The code above
is supposed to show which (gps[,3], gps[,4]) lie within a polygon with
edges p.x, and p.y. It's not quite working, samples from gps and
greens follow:
> head(greens)
  holeno       latitude       longitude
1      1 37.55451273121 -122.3801181128
2      1 37.55446160943 -122.3801234772
3      1 37.55443003419 -122.3801140894
4      1 37.55440898403 -122.3800966551
5      1 37.55440296970 -122.3800778796
6      1 37.55438342311 -122.3800644686
> head(gps)
      logged_on       longitude       latitude speed tag_id track score
1 1321738590000 -122.3811569214 37.55739593506  0.14   <NA> 95.84   0.2
2 1321738591000 -122.3812255859 37.55743408203  0.15   <NA> 95.84   0.2
3 1321738592000 -122.3812179565 37.55741882324  0.27   <NA> 95.84   0.2
4 1321738593000 -122.3812789917 37.55744934082  0.53   <NA> 95.84   0.2
5 1321738594000 -122.3812789917 37.55744552612  0.11   <NA> 95.84   0.2
6 1321738595000 -122.3812637329 37.55744171143  0.06   <NA> 95.84   0.2
>
There should be about 36 points in the polygon outlined and the code
is outputting no points.  Many thanks and do be in touch if you desire
further information...
-- 
Sent from my mobile device
Envoyait de mon portable



More information about the R-help mailing list