as.lines: Conversion to a SpatVector of lines

as.linesR Documentation

Conversion to a SpatVector of lines

Description

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

Usage

## S4 method for signature 'SpatRaster'
as.lines(x, na.rm=FALSE)

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

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

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

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

na.rm

logical. Only show lines for cells that are not NA?

crs

character. The coordinate reference system (see crs)

segments

logical. Should (poly-)lines or polygons be disaggregated into their line-segments? See disagg

Value

SpatVector

See Also

as.points, as.polygons

Examples

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

as.lines(r)

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

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


terra documentation built on Aug. 22, 2026, 5:07 p.m.