title: How to generate nodes from existing network? R
body: <p>I have a road segment called my_line with start point and end point</p>
  <pre><code>
  df &lt;- data.frame(id = &quot;a&quot;, lon1 = 1, lat1 = 5, lon2 = 7, lat2 = 9)  
  dt &lt;- as.data.table(df)
  
  sf &lt;- dt[
    , {
      geometry &lt;- sf::st_linestring(x = matrix(c(lon1, lat1, lon2, lat2), ncol = 2))
      geometry &lt;- sf::st_sfc(geometry)
      geometry &lt;- sf::st_sf(geometry = geometry)
    }
    , by = id
  ]
  
  my_line &lt;- sf::st_as_sf(sf)
  
  </code></pre>
  <pre><code>pt &lt;- st_cast(my_line, &quot;POINT&quot;)
  start &lt;- pt[1,] # create start point
  end &lt;- pt[nrow(pt),] # create end point
  </code></pre>
  <p>I want to split this road every 2 metres (2-meter interval), and the new points are called new.pt</p>
  <pre><code>sdist = 2 # split distance
  
  numOfPoints  &lt;-  as.numeric(st_length(my_line) / sdist)
  new.pt &lt;- st_line_sample(sf.sf,  numOfPoints, type = &quot;regular&quot;) # new points
  </code></pre>
  <pre><code>library(ggplot2)
  ggplot() +
    geom_sf(data = sf.sf) +
    geom_sf(data = start, color = 'green') +
    geom_sf(data = end, color = 'red')  + geom_sf(data = new.pt, color = 'black')
  
  </code></pre>
  <p>Now I want to use <code>new.pt</code> as to create a new road segment according to this format</p>
  <p>(start --&gt; new.pt[1], new.pt[1]--&gt; new.pt[2], new.pt[2] --&gt; end)</p>
  <p>i.e. 3 lines; 2 new nodes generated from the existing line</p>
  <p>How to do that in R?</p>