[R-sig-Geo] Splitting spatial lines at self intersections (line crossings)
Glenn Stauffer
gestauffer at gmail.com
Thu Jan 25 23:26:35 CET 2018
I have a Spatial Lines object I would like to split at every point where the
line self-intersects (crosses or touches itself), or anywhere lines touch
each other, if there are multiple lines.
I've tried using spatstat to convert the SpatialLines to a psp object and
then use the selfcrossing.psp function to find the intersection points (see
example below). But that seems to identify all the nodes, not just the
points where the line crosses. Also, even if it identified only the
crossings (which is what I want), I am not sure how to perform the next step
and split the lines at those points.
So, 1) I need to identify the crossings/touches, and 2) split the lines at
those points.
Essentially, what I am looking for is an R equivalent to the planarize
function in ArgGIS. Is there a relatively easy way to do this in R?
Thanks,
Glenn
Here is an example of what I have tried.
pts <- cbind(c(120:123,121,125),c(100,100,104,102,99,98))
pt2 <- cbind(c(124,124,123,118,124,125),c(100,97,100,104,106,110))
projstr <- "+init=epsg:3071" # make everything in meters
L <- SpatialLines(list(Lines(list(Line(pts),Line(pt2)),"X")),proj4string =
CRS(projstr))
plot(L)
PSP <- as.psp.SpatialLines(L)
int <- selfcrossing.psp(PSP)
plot(int,add=TRUE,col="red") # identifies more than just the crossings
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list