[R-sig-Geo] Splitting spatial lines at self intersections (line crossings)
Michael Sumner
mdsumner at gmail.com
Fri Jan 26 13:12:44 CET 2018
Ege: I don't believe that this code is enough to get coercion between sp
and spatstat:
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))
library(sp)
library(spatstat)
L1 <- SpatialLines(list(Lines(list(Line(pts)), "X")))
L2 <- SpatialLines(list(Lines(list(Line(pt2)), "X")))
l1 <- as.psp(L1)
l2 <- as.psp(L2)
int <- crossing.psp(l1, l2)
Are we relying on some other code, or perhaps a specific version of
spatstat or its family? (I know ways to convert from Spatial to psp, but I
was taken by this apparent lack of infrastructure - and I'm very keen on
seeing more bridges between these rich worlds).
Cheers, Mike
On Fri, 26 Jan 2018 at 17:48 Ege Rubak <rubak at math.aau.dk> wrote:
> The `psp` class in spatstat consists of individual line segments and
> `selfcrossing.psp` checks whether each individual line intersects one of
> the other lines, which happens at all the points in your plot.
>
> If instead you treat each of the two line sequences as a `psp` you can
> check find the crossings of the two `psp` objects. I.e., continuing your
> code (with `spatstat` and `maptools` loaded):
>
> L1 <- SpatialLines(list(Lines(list(Line(pts)), "X")))
> L2 <- SpatialLines(list(Lines(list(Line(pt2)), "X")))
> l1 <- as.psp(L1)
> l2 <- as.psp(L2)
> int <- crossing.psp(l1, l2)
>
> This gives you the four intersections between the lines. I don't know of
> a simple way to do the next task in `spatstat`. A useful function if you
> are going to try to write some code is `test.crossing.psp` which gives
> you a logical matrix indicating which segments cross.
>
> Cheers,
> Ege
>
> On 01/25/2018 11:26 PM, Glenn Stauffer wrote:
> > 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]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list