Learn R Programming

quickPlot (version 1.0.2)

layerNames: 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 ANY layerNames(object)

Arguments

object

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

Author

Eliot McIntire

Examples

Run this code
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)

Run the code above in your browser using DataLab