[R-sig-Geo] dividing a line by points lying on it

Matthias Hinz matthias.m.hinz at gmail.com
Fri Mar 27 12:49:13 CET 2015


Hello,

it would have been been easier if you included the link to the related 
thread from 2013, instead of letting me figure out myself ;-)

http://r-sig-geo.2731867.n2.nabble.com/split-divide-SpatialLines-sp-into-n-segments-td7583234.html

So far, my first idea is the following iterative solution:

 1. For the first, figure out on which line segment, i.e. straight line
    it is located (iterate pairwise over all coordinates of the linestring)
      * If you find the intersection, split the SpatialLine at this point
      * Finding a point on a straight line might be implemented in some
        R-function, but actually is elementary mathematics. Mind
        rounding errors during floating point operations.

     2 ...n Repeat for the remaining points, but test against the 
previously splitted SpatialLines, i.e. the     outcome of the preceding step

Regards,
Matthias Hinz

Am 26.03.2015 um 12:24 schrieb Wolfgang Biener:
> Hi there,
>
> I want to divide a line into n+1 lines. The shall be divided by points 
> lying on it.
> Since I don't have any idea how to solve can also post the starting 
> point of the problem.
>
> Thanks for your Help
>
>
> library(sp)
> Sl = SpatialLines(list(Lines(list(Line(cbind(c(1,2,2),c(1,1,2)))),
>                              ID="a")))
>
> set.seed(123)
> sample.points <- spsample(Sl, 10, type="regular")
>
> x11()
> plot(Sl)
> plot(sample.points, pch=1, col="red", add=T)
>


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list