as.lines: Convert a raster to a lines vector

as.lines,GRaster-methodR Documentation

Convert a raster to a lines vector

Description

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 signature '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

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. In this case, we need to run 300 thinning iterations
# for the function to reduce the raster to linear features.
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)

}

adamlilith/fasterRaster documentation built on Oct. 26, 2024, 4:06 p.m.