简体   繁体   中英

R: Get all xy-coordinates at the intersection of lines within one SpatialLines(DataFrame)

I'm looking for a way to get the xy-coordinates of all the intersections within one SpatialLines object or SpatialLinesDataFrame . I have found the function gIntersect of rgeos but that only looks at the intersection between two datasets. Since I am working with a dataset of over half a million lines it would take too much time to make a separate file of every line and check whether any line intersects with another. In ArcMap there is the Intersect function that is able to do it in a couple of seconds and I was wondering whether there was also such a function in R. Thanks!

If you convert your SpatialLines object into a psp object from spatstat you can use the spatstat function selfcrossing.psp . However, I'm not sure how it will cope with half a million lines since the number of crossings potentially could be enormous. The code below generates a random segment pattern and finds the self crossings.

BEWARE that this code potentially can take up a lot of memory and kill R, so try with progressively increasing examples before processing a half million lines. The code below used quite a bit of memory on my 5 year old laptop and took 5 seconds to run.

set.seed(42)
N <- 1e4
x <- psp(runif(N), runif(N), runif(N), runif(N), owin(), check=FALSE)
y <- selfcrossing.psp(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM