Learn R Programming

mapview (version 1.1.0)

coords2Lines: Convert points to SpatialLines*

Description

Create a SpatialLines* object from a Line object or set of point coordinates in one go, i.e. without being required to run through the single steps outlined in SpatialLines.

Usage

"coords2Lines"(coords, ID, data, match.ID = TRUE, ...)
"coords2Lines"(coords, ID, data, match.ID = TRUE, ...)

Arguments

coords
Line object or 2-column numeric matrix with x and y coordinates.
ID
character, see Lines.
data
data.frame with data to add to the output SpatialLines* object (optional).
match.ID
logical, see SpatialLinesDataFrame.
...
Further arguments passed on to SpatialLines (i.e., proj4string).

Value

If data is missing, a SpatialLines object; else a SpatialLinesDataFrame object.

See Also

SpatialLines-class, SpatialLinesDataFrame.

Examples

Run this code
## Not run: 
# library(sp)
# 
# coords1 <- cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2))
# sln1 <- coords2Lines(coords1, ID = "A")
# 
# coords2 <- cbind(c(5, 4, 2, 5), c(2, 3, 2, 2))
# sln2 <- coords2Lines(coords2, ID = "B")
# 
# mapview(sln1)
# 
# plot(sln1, col = "grey75")
# plot(sln2, col = "grey25", add = TRUE)
# ## End(Not run)

Run the code above in your browser using DataLab