terra (version 1.0-10)

as.spatvector: Coercion to a SpatVector, or to another SpatVector type

Description

Coercion of a SpatRaster or SpatExtent to a SpatVector (polygons); SpatRaster to a points SpatVector; or of a SpatVector to a lower level SpatVector type (polygons to lines or points; lines to points

Usage

# S4 method for SpatRaster
as.polygons(x, trunc=TRUE, dissolve=TRUE, values=TRUE, extent=FALSE, ...)

# S4 method for SpatRaster as.points(x, values=TRUE, ...)

# S4 method for SpatVector as.lines(x, ...)

# S4 method for SpatVector as.points(x, multi=FALSE, ...)

# S4 method for SpatExtent as.polygons(x, crs="", ...)

# S4 method for SpatExtent as.lines(x, crs="", ...)

# S4 method for SpatExtent as.points(x, crs="", ...)

Arguments

x

SpatRaster or SpatVector

trunc

logical; truncate values to integers. Cels with the same value are merged. Therefore, if trunc=FALSE the object returned can be very large

dissolve

logical; combine cells with the same values?

values

logical; include cell values as attributes? If FALSE the cells are not dissolved and the object returned can be very large

multi

logical. If TRUE a multipoint geometry is returned

extent

logical. if TRUE, a polygon for the extent of the SpatRaster is returned. It has vertices for each grid cell, not just the four corners of the raster. This can be useful for more precise projection. In other cases it is better to do as.polygons(ext(x)) to get a much smaller object returned that covers the same extent

crs

character. The coordinate reference system

...

additional arguments. None implemented

Value

SpatVector

Examples

Run this code
# NOT RUN {
r <- rast(ncol=2, nrow=2)
values(r) <- 1:ncell(r)

as.points(r)
as.lines(ext(r), crs=crs(r))

if  (gdal() >= "3.0.0") {
	p <- as.polygons(r)
	p
	as.lines(p)
	as.points(p)
}
# }

Run the code above in your browser using DataCamp Workspace