Convert a SpatialLinesDataFrame to points The number of points will be double the number of lines with line2points. A closely related function, line2pointsn returns all the points that were line vertices. The points corresponding with a given line, i, will be (2*i):((2*i)+1).

line_to_points(l, ids = rep(1:nrow(l), each = 2))

line2pointsn(l)

Arguments

l

A SpatialLinesDataFrame

ids

Vector of ids (by default 1:nrow(l))

Examples

l <- routes_fast[2:4, ] lpoints <- line_to_points(l) lpoints2 <- line2pointsn(l) plot(lpoints, pch = lpoints$id, cex = lpoints$id)
points(lpoints2, add = TRUE)
#> Warning: "add" is not a graphical parameter
line_to_points(routes_fast_sf[2:4, ])
#> Simple feature collection with 6 features and 1 field #> geometry type: POINT #> dimension: XY #> bbox: xmin: -1.550964 ymin: 53.8175 xmax: -1.516748 ymax: 53.82868 #> epsg (SRID): NA #> proj4string: NA #> id p #> 1 1 POINT (-1.516748 53.82868) #> 2 1 POINT (-1.535849 53.82832) #> 3 2 POINT (-1.516748 53.82868) #> 4 2 POINT (-1.550964 53.82408) #> 5 3 POINT (-1.516748 53.82868) #> 6 3 POINT (-1.530693 53.8175)