as.polygons: Convert a raster to a polygons vector

as.polygons,GRaster-methodR Documentation

Convert a raster to a polygons vector

Description

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.

Usage

## S4 method for signature 'GRaster'
as.polygons(x, round = TRUE, smooth = FALSE)

Arguments

x

A GRaster. If more than one layer is in the GRaster, 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, see clump().

smooth

Logical: If TRUE, round the corners of square features. Default is FALSE.

Value

A GVector.

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)

}

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