Hello, I have been spending some time on Google looking for an intersection of polygons and polylines. I have indeed a SpatialPolygonsDataFrame (administrative boundaries) and thousands of SpatialLines (outputs GCM's hurricanes tracks simulations), the SpatialPolygonsDataFrame have an attribute (names of the polygon), I want to find the intersection of the polygon and each polyline, and create a new column for each polyline in the attribute of the polygon, and fill 1 if the polyline hit the polygon, 0 ifelse. This is a little example to express the case
library(sp) P <- SpatialPolygons(list(Polygons(list(Polygon(cbind(c(1,1.5,2.8,2,1), c(3,4,3.5,2.3,3)))), "p1"), Polygons(list(Polygon(cbind(c(1.5,3.5,4,3.5,2.8,1.5), c(4,4.3,3.5,3.8,3.5,4)))), "p2"), Polygons(list(Polygon(cbind(c(2,2.8,3.5,3,2.5,2),c(2.3,3.5,3.8,2,1,2.3)) )), "p3"), Polygons(list(Polygon(cbind(c(3,3.5,4,3.8,3),c(2,3.8,3.5,1.5,2)))), "p4")), 1:4) nom<-LETTERS[1:4] attr <- data.frame(nom, row.names = sapply(slot(P, "polygons"),function(x) slot(x, "ID"))) polyg<- SpatialPolygonsDataFrame(P, attr) dat<-as(polyg,"data.frame") nom p1 A p2 B p3 C p4 D L<-SpatialLines(list(Lines(list(Line(cbind(c(7,6,5,4.2,3,2.8,1), c(4,3.5,3,2.8,2.5,1.8,1)))),"l1"))) #plot(polyg) #plot(L,add=T) The result that I want is like this nom l1 p1 A 0 p2 B 0 p3 C 1 p4 D 1 Thanks you! <span id=m2wTl><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Obtenez votre e-mail GRATUIT avec 10 Mo sur <a href="http://www.mail2france.com" target="new">http://www.mail2france.com</a></font></span> [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
