Convert 2 matrices to lines

mats2line(mat1, mat2, crs = NA)

Arguments

mat1

Matrix representing origins

mat2

Matrix representing destinations

crs

Number representing the coordinate system of the data, e.g. 4326

See also

Examples

m1 <- matrix(c(1, 2, 1, 2), ncol = 2) m2 <- matrix(c(9, 9, 9, 1), ncol = 2) l <- mats2line(m1, m2) class(l)
#> [1] "sfc_LINESTRING" "sfc"
l
#> Geometry set for 2 features #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1 ymin: 1 xmax: 9 ymax: 9 #> CRS: NA
#> LINESTRING (1 1, 9 9)
#> LINESTRING (2 2, 9 1)
lsf <- sf::st_sf(l, crs = 4326) class(lsf)
#> [1] "sf" "data.frame"
plot(lsf)
# mapview::mapview(lsf)