Skip to contents

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.

Usage

# S4 method for class 'GRaster'
as.lines(x)

Arguments

x

A GRaster. If more than one layer is in the GRaster, only the first will be used (with a warning).

Value

A GVector.

See also

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)

}