dt2raster: Convert 'data.table' to a 'RasterLayer' for plotting, etc.

Description Usage Arguments Value Author(s) Examples

View source: R/rasters.R

Description

DETAILED DESCRIPTION NEEDED

Usage

1
dt2raster(dt, r, val)

Arguments

dt

data.table object with columns ID, or both X and Y, and the values to assign to the raster specified by column val.

r

Raster* object.

val

The name of the column in dt containing the values for the raster.

Value

A RasterLayer object.

Author(s)

Alex Chubaty

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(data.table)
library(sp)
library(raster)

r <- raster(nrows = 10, ncols = 10)
r[] <- 10

# using x,y coordinates
#dt1 <- data.table(X = , Y = , value = r[])

# using pixel ids
dt2 <- data.table(ID = 1L:ncell(r), VALUE = r[])
dt2[, VALUE := sample(1L:10L, ncell(r), replace = TRUE)]

if (interactive())
  plot(dt2raster(dt2, r, "VALUE"))

achubaty/amc documentation built on April 6, 2021, 6:56 a.m.