terra (version 1.7-29)

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

Description

Conversion of a SpatRaster or SpatExtent to a SpatVector of points, lines, or polygons;

And conversion of a SpatVector to another SpatVector type.

Usage

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

# S4 method for SpatRaster as.lines(x)

# S4 method for SpatRaster as.points(x, values=TRUE, na.rm=TRUE, na.all=FALSE)

# S4 method for SpatVector as.polygons(x, extent=FALSE)

# S4 method for SpatVector as.lines(x)

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

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

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

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

Value

SpatVector

Arguments

x

SpatRaster or SpatVector

trunc

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

dissolve

logical; combine cells with the same values? If TRUE only the first layer in x is processed

values

logical; include cell values as attributes?

multi

logical. If TRUE a multi-point geometry is returned

skiplast

logical. If TRUE the last point of a polygon (which is the same as the first point) is not included

extent

logical. if TRUE, a polygon for the extent of the SpatRaster or SpatVector is returned. If x is a SpatRaster, the polygon has vertices for each row and column, not just the four corners of the raster. This can be useful for more precise projection. If that is not required, it is more efficient to get the extent represented by only the four corners with as.polygons(ext(x), crs=crs(x))

na.rm

logical. If TRUE cells that are NA are ignored

na.all

logical. If TRUE cells are only ignored if na.rm=TRUE and their value is NA for all layers instead of for any layer

crs

character. The coordinate reference system (see crs)

Examples

Run this code
r <- rast(ncols=2, nrows=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 DataLab