as.polygons()
converts a GRaster
to a "polygons" GVector
. After running this function, geometry cleaning may be useful to use to "tidy up" the vector.
Arguments
- x
A
GRaster
. If more than one layer is in theGRaster
, only the first will be used (with a warning).- round
Logical: If
TRUE
(default), values in the raster will be rounded first before conversion to a vector. This causes cells that are adjacent that have the same (rounded) values to be combined into a single polygon. For more control, seeclump()
.- smooth
Logical: If
TRUE
, round the corners of square features. Default isFALSE
.
See also
as.points()
, as.lines()
, terra::as.polygons()
, geometry cleaning, and GRASS module r.to.vect
Examples
if (grassStarted()) {
# Setup
library(terra)
# Elevation
madElev <- fastData("madElev")
# Convert SpatRaster to GRaster:
elev <- fast(madElev)
# To speed things up, first group cells of similar value:
elevClumps <- clump(elev, minDiff = 0.0115)
# Convert to polygons:
rastToPolys <- as.polygons(elevClumps)
plot(rastToPolys)
}