thinLines: Reduce linear features on a raster so linear features are 1...

thinLines,GRaster-methodR Documentation

Reduce linear features on a raster so linear features are 1 cell wide

Description

The thinLines() function attempts to reduce linear features on a raster to just 1 cell wide. You may need to run thinLines() multiple times on the same raster (or experiment with the iter argument) to get acceptable output. thinLines() can be helpful to run on a raster before using as.lines().

Usage

## S4 method for signature 'GRaster'
thinLines(x, iter = 200)

Arguments

x

A GRaster.

iter

Numeric integer: Number of iterations (default is 200).

Value

A GRaster.

See Also

as.lines(), GRASS manual page for module r.thin (see grassHelp("r.thin"))

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.