Learn R Programming

terra (version 1.8-5)

as.lines: Conversion to a SpatVector of lines

Description

Conversion of a SpatRaster, SpatVector or SpatExtent to a SpatVector of lines.

Usage

# S4 method for SpatRaster
as.lines(x)

# S4 method for SpatVector as.lines(x)

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

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

Value

SpatVector

Arguments

x

SpatRaster, SpatVector, SpatExtent or matrix. If x is a matrix it should have two columns for a single line, or four columns, where each row has the start and end coordinates (x, y) for lines

crs

character. The coordinate reference system (see crs)

See Also

as.points, as.polygons

Examples

Run this code
r <- rast(ncols=2, nrows=2)
values(r) <- 1:ncell(r)

as.lines(r)

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

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


## with a matrix
s <- cbind(1:5, 1:5)
e <- cbind(1:5, 0)

as.lines(s)
as.lines(cbind(s, e), "+proj=longlat")

Run the code above in your browser using DataLab