Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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 a another SpatVector type.

Usage

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

## S4 method for signature 'SpatRaster'
as.lines(x)

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

## S4 method for signature 'SpatVector'
as.polygons(x)

## S4 method for signature 'SpatVector'
as.lines(x)

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

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

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

## S4 method for signature '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? If TRUE only the first layer in x is processed

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

na.rm

logical. If TRUE cells that are NA are ignored

crs

character. The coordinate reference system (see crs

Value

SpatVector

Examples

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)
}

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.