I have shapefiles of polygons and lines at my disposal. I would like to intersect polygons and lines with R and thus calculate the length of the lines present in each polygon. You can find the data here "https://www.dropbox.com/s/b6x9gk8bzhan7zm/test.rar?dl=0" .I know how to do it on Arcgis but I would like to have a code on R to automate this because I have to do the same procedure for a lot of data. The code I put in place on R :
setwd("D:/folder/test") library(sp) library(maptools) library(rgeos) library(rgdal) Poly <- readOGR("grille.shp",layer="grille") plot(Poly) line <- readOGR("line.shp",layer="line") plot(line) Inter <- gIntersection(line,Poly,byid=TRUE)
allows me to have an intersection but what I would like to know is how to calculate then the length of the lines present in each polygon ?