diff --git a/R/utils.R b/R/utils.R index 8b74a64..2eae2fb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -38,6 +38,18 @@ add_lat <- function(x){ stack(lat, x) } +#' Augment a raster object, adding layers containing cell row-column indices. +#' +#' @param x raster layer or stack +#' @return the input layer, with an additional layer of latitude values +add_coords <- function(windrose){ + rows <- cols <- windrose[[1]] + rows[] <- rep(1:nrow(rows), each=ncol(rows)) + cols[] <- rep(1:ncol(rows), nrow(rows)) + windrose <- stack(windrose, rows, cols) + names(windrose) <- c("SW", "W", "NW", "N", "NE", "E", "SE", "S", "row", "col") + return(windrose) +} #' Get neighbor names for a windrose object #' diff --git a/man/add_coords.Rd b/man/add_coords.Rd new file mode 100644 index 0000000..15a2d5f --- /dev/null +++ b/man/add_coords.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{add_coords} +\alias{add_coords} +\title{Augment a raster object, adding layers containing cell row-column indices.} +\usage{ +add_coords(windrose) +} +\arguments{ +\item{x}{raster layer or stack} +} +\value{ +the input layer, with an additional layer of latitude values +} +\description{ +Augment a raster object, adding layers containing cell row-column indices. +}