Skip to contents

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

Arguments

x

SpatRaster, SpatVector or SpatExtent

crs

character. The coordinate reference system (see crs)

Value

SpatVector

Examples

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

as.lines(r)
#>  class       : SpatVector 
#>  geometry    : lines 
#>  dimensions  : 6, 0  (geometries, attributes)
#>  extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#>  coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84) 

as.lines(ext(r), crs=crs(r))
#>  class       : SpatVector 
#>  geometry    : lines 
#>  dimensions  : 1, 0  (geometries, attributes)
#>  extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#>  coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84) 

if  (gdal() >= "3.0.0") {
  p <- as.polygons(r)
  as.lines(p)
}
#>  class       : SpatVector 
#>  geometry    : lines 
#>  dimensions  : 4, 1  (geometries, attributes)
#>  extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#>  coord. ref. : lon/lat WGS 84 (CRS84) (OGC:CRS84) 
#>  names       : lyr.1
#>  type        : <int>
#>  values      :     1
#>                    2
#>                    3