Skip to content

Instantly share code, notes, and snippets.

View philipshirk's full-sized avatar

Philip Shirk philipshirk

  • CDC (work) + personal projects
  • Atlanta, GA
View GitHub Profile
@etiennebr
etiennebr / as.data.table.r
Last active July 23, 2024 23:44
Transform raster or terra object to data.table
#' Transform raster to data.table
#'
#' @param x Raster* object
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed
#' @param optional logical. If `TRUE`, setting row names and converting column names (to syntactic names: see make.names) is optional
#' @param xy logical. If `TRUE`, also return the spatial coordinates
#' @param centroids logical. If TRUE return the centroids instead of all spatial coordinates (only relevant if xy=TRUE)
#' @param sepNA logical. If TRUE the parts of the spatial objects are separated by lines that are NA (only if xy=TRUE and, for polygons, if centroids=FALSE
#' @param ... Additional arguments (none) passed to `raster::as.data.frame`
#'