Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

line2points

Convert a spatial (linestring) object to points


Description

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. If the input l object is composed by only 1 LINESTRING with 2 POINTS, then it returns an empty sf object.

Usage

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, ]
lpoints <- line2points(l)
plot(l$geometry)
plot(lpoints, add = TRUE)
# test all vertices:
plot(l$geometry)
lpoints2 <- line2pointsn(l)
plot(lpoints2$geometry, add = TRUE)

# extract only internal vertices
l_internal_vertices <- line2vertices(l)
plot(sf::st_geometry(l), reset = FALSE)
plot(l_internal_vertices, add = TRUE)
# The boundary points are missing

stplanr

Sustainable Transport Planning

v0.8.2
MIT + file LICENSE
Authors
Robin Lovelace [aut, cre] (<https://orcid.org/0000-0001-5679-6536>), Richard Ellison [aut], Malcolm Morgan [aut] (<https://orcid.org/0000-0002-9488-9183>), Barry Rowlingson [ctb], Nick Bearman [ctb], Nikolai Berkoff [ctb], Scott Chamberlain [rev] (Scott reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/10), Mark Padgham [ctb], Andrea Gilardi [ctb] (<https://orcid.org/0000-0002-9424-7439>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.