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). The last function, line2vertices, returns all the points that are vertices but not nodes.

line2points(l, ids = rep(1:nrow(l)))

line2pointsn(l)

line2vertices(l)

Arguments

l

An sf object or a SpatialLinesDataFrame from the older sp package

ids

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

See also

Examples

l <- routes_fast_sf[2:4, ] lpoints <- line2points(l) lpoints_sfc <- line2points(sf::st_geometry(l)) identical(lpoints, lpoints_sfc)
#> [1] TRUE
line2points(sf::st_linestring(matrix(c(0, 0, 2, 2), ncol = 2, byrow = TRUE)))
#> Simple feature collection with 2 features and 1 field #> geometry type: POINT #> dimension: XY #> bbox: xmin: 0 ymin: 0 xmax: 2 ymax: 2 #> CRS: NA #> id geometry #> 1 1 POINT (0 0) #> 2 1 POINT (2 2)
lpoints2 <- line2pointsn(l) plot(sf::st_geometry(lpoints), pch = lpoints$id, cex = lpoints$id, col = "black")
plot(lpoints2$geometry, add = TRUE)
# in sp data forms (may be depreciated) l <- routes_fast[2:4, ] lpoints <- line2points(l) lpoints2 <- line2pointsn(l) plot(lpoints, pch = lpoints$id, cex = lpoints$id)
points(lpoints2)