as.lines,GRaster-method | R Documentation |
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.
## S4 method for signature 'GRaster'
as.lines(x)
x |
A |
A GVector
.
as.points()
, as.polygons()
, terra::as.lines()
, thinLines()
, geometry cleaning, and GRASS module r.to.vect
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.