as.lines()
converts a GRaster
to a "lines" GVector
. Before you apply this function, you may need to run thinLines()
on the raster to reduce linear features to a single-cell width. You may also need to use clean geometry (especially the removeDups()
and removeDangles()
) afterward to remove duplicated vertices and "dangling" lines.
See also
as.points()
, as.polygons()
, terra::as.lines()
, thinLines()
, geometry cleaning, and GRASS module r.to.vect
Examples
if (grassStarted()) {
# Setup
library(terra)
# Elevation
madElev <- fastData("madElev")
# Convert to GRaster:
elev <- fast(madElev)
# Thin elevation raster:
thinned <- thinLines(elev, iter = 300)
plot(thinned)
# Convert to lines:
rastToLines <- as.lines(thinned)
plot(rastToLines)
# We can clean this:
cleanLines <- fixDangles(x = rastToLines)
plot(rastToLines, col = "red")
plot(cleanLines, add = TRUE)
}