layerNames: Extract the layer names of Spatial Objects

layerNamesR Documentation

Extract the layer names of Spatial Objects

Description

There are already methods for ⁠Raster*⁠ objects. This adds methods for ⁠SpatialPoints*⁠, ⁠SpatialLines*⁠, and ⁠SpatialPolygons*⁠, returning an empty character vector of length 1. This function was created to give consistent, meaningful results for all classes of objects plotted by Plot.

Usage

layerNames(object)

## S4 method for signature 'ANY'
layerNames(object)

Arguments

object

A ⁠Raster*⁠, ⁠SpatialPoints*⁠, ⁠SpatialLines*⁠, or ⁠SpatialPolygons*⁠ object; or list of these.

Author(s)

Eliot McIntire

Examples

library(terra)

## RasterLayer objects
files <- system.file("maps", package = "quickPlot")
files <- dir(files, full.names = TRUE, pattern = "tif")
maps <- lapply(files, function(x) terra::rast(x))
names(maps) <- sapply(basename(files), function(x) {
  strsplit(x, split = "\\.")[[1]][1]
})
layerNames(maps)

## SpatVector objects
caribou <- terra::vect(cbind(x = stats::runif(1e2, -50, 50),
                             y = stats::runif(1e2, -50, 50)))
layerNames(caribou)


quickPlot documentation built on July 9, 2023, 6:02 p.m.