Learn R Programming

terra (version 1.8-5)

metags: Set or get metadata

Description

You can set arbitrary metadata to (layers of) a SpatRaster using "name=value" tags. When wring a SpatRaster to a GTiff file, these tags are written to file.

Usage

# S4 method for SpatRaster
metags(x, layer=NULL)<-value

# S4 method for SpatRaster metags(x, layer=NULL, name=NULL)

Value

SpatRaster (metags<-), or named character (metags)

Arguments

x

SpatRaster

layer

NULL or positive integer. If the value is NULL, the tags assigned or returned are for the SpatRaster. Otherwise for the layer number(s)

name

character

value

character of "name=value" or two-column matrix

Examples

Run this code
r <- rast(ncol=5, nrow=5)
m <- cbind(c("one", "two", "three"), c("ABC", "123", "hello"))
metags(r) <- m
metags(r)

metags(r) <- c("another_tag=another_value", "one more=this value")
metags(r)

metags(r) <- c(another_tag="44", `one more`="that value")
metags(r)


metags(r, name="two")

# remove a tag
metags(r) <- cbind("one", "")
metags(r) <- "two="
metags(r)

# remove all metags
metags(r) <- NULL
metags(r)

Run the code above in your browser using DataLab