Learn R Programming

stplanr (version 0.1.4)

line2points: Convert a SpatialLinesDataFrame 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).

Usage

line2points(l)
line2pointsn(l)

Arguments

l
A SpatialLinesDataFrame

Examples

Run this code
data(routes_fast)
lpoints <- line2pointsn(routes_fast[2,]) # for a single line
lpoints2 = line2points(routes_fast[2,])
plot(lpoints)
plot(lpoints2)
lpoints = line2pointsn(routes_fast) # for many lines
plot(lpoints)
data(flowlines) # load demo flowlines dataset
lpoints <- line2points(flowlines) # for many lines
sp::proj4string(lpoints) # maintains CRS info
plot(lpoints) # note overlapping points
i = 3
j = (2*i):((2*i)+1)
plot(flowlines[i,])
plot(lpoints[j,], add = TRUE)

Run the code above in your browser using DataLab