% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tbl.R
\name{tiff_band_names}
\alias{tiff_band_names}
\title{Read per-band names from a GeoTIFF}
\usage{
tiff_band_names(path)
}
\arguments{
\item{path}{Path to a GeoTIFF file.}
}
\value{
A character vector of length \code{nbands}. Element \code{i} is the name
of band \code{i} (or \code{NA_character_} if the file does not name it).
}
\description{
Returns the band names embedded in the file's GDAL_METADATA XML
(TIFF tag 42112). GDAL writes per-band names as
\verb{<Item name="DESCRIPTION" sample="N" role="description">...</Item>} entries,
where \code{sample} is the 0-based band index. Bands without a name in the XML
are reported as \code{NA}. Files with no GDAL_METADATA tag at all return a
length-\code{nbands} vector of \code{NA_character_}.
}
\details{
This is a small, dependency-free scanner intended for the common case
(\code{terra::names(r) <- ...} and similar). For arbitrary XML, parse the raw
string from \code{\link[=tiff_metadata]{tiff_metadata()}} yourself.
}
\examples{
\donttest{
f <- tempfile(fileext = ".tif")
df <- data.frame(x = rep(1:2, 2), y = rep(1:2, each = 2),
                 band1 = as.double(1:4), band2 = as.double(5:8))
xml <- paste0(
  "<GDALMetadata>",
  "<Item name=\"DESCRIPTION\" sample=\"0\" role=\"description\">temperature</Item>",
  "<Item name=\"DESCRIPTION\" sample=\"1\" role=\"description\">humidity</Item>",
  "</GDALMetadata>")
write_tiff(df, f, metadata = xml)
tiff_band_names(f)
unlink(f)
}

}
