This can be done with the rgeos
package, e.g. with gBuffer
and gDifference
:
library("rgeos")
library("rgdal")
line1 <- matrix(c(-1.81209, -1.80470, -1.80616, 55.68024, 55.67947,
55.67544), ncol=2)
line2 <- matrix(c(-1.80468, -1.80330, -1.79690, 55.68322, 55.68017,
55.67800), ncol=2)
line3 <- matrix(c(-1.79798, -1.80069, -1.78929, 55.68364, 55.68138,
55.67966), ncol=2)
lines <- SpatialLines(list(Lines(list(Line(line1)), ID="1"),
Lines(list(Line(line2)), ID="2"),
Lines(list(Line(line3)), ID="3")))
l <- SpatialLinesDataFrame(lines, data=data.frame(ID=paste(1:3)))
proj4string(l) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
lt <- spTransform(l, CRS("+init=epsg:27700 +datum=WGS84"))
plot(lt, lty=3)
buf_list <- vector(3, mode="list")
res <- vector(3, mode="list")
for (i in 1:3) {
ind <- setdiff(1:3, i)
buf_list[[i]] <- gBuffer(lt[ind,], width=200)
res[[i]] <- gDifference(lt[i, ], buf_list[[i]])
}
lapply(buf_list, plot, col="#FFFFFF90", add=TRUE)
lapply(res, plot, col="red", lwd=2, add=TRUE)
![R plot](https://i.stack.imgur.com/0l14O.png)
Best Answer
[QGIS 2.8] Use the Intersect tool menu : "Vector / Geoprocessing tools / Intersect" (from Miro's answer in comments)
[QGIS 2.18] Use the Intersection Tool in the processing toolbox/panel :