Learn R Programming

SpaDES.tools (version 0.1.1)

rasterizeReduced: Convert reduced representation to full raster

Description

Convert reduced representation to full raster

Usage

rasterizeReduced(reduced, fullRaster, newRasterCols,
  mapcode = names(fullRaster), ...)

Arguments

reduced

data.frame or data.table that has at least one column of codes that are represented in the fullRaster.

fullRaster

RasterLayer of codes used in reduced that represents a spatial representation of the data.

newRasterCols

Character vector, length 1 or more, with the name(s) of the column(s) in reduced whose value will be returned as a Raster or list of Rasters.

mapcode

a character, length 1, with the name of the column in reduced that is represented in fullRaster.

...

Other arguments. None used yet.

Value

A RasterLayer or list of RasterLayer of with same dimensions as fullRaster representing newRasterCols spatially, according to the join between the mapcode contained within reduced and fullRaster

See Also

raster

Examples

Run this code
# NOT RUN {
library(data.table)
library(raster)
library(quickPlot)

ras <- raster(extent(0, 15, 0, 15), res = 1)
fullRas <- randomPolygons(ras, numTypes = 2)
names(fullRas) <- "mapcodeAll"
uniqueComms <- unique(fullRas)
reducedDT <- data.table(mapcodeAll = uniqueComms,
                        communities = sample(1:1000, length(uniqueComms)),
                        biomass = rnbinom(length(uniqueComms), mu = 4000, 0.4))
biomass <- rasterizeReduced(reducedDT, fullRas, "biomass")

# The default key is the layer name of the fullRas, so rekey incase of miskey
setkey(reducedDT, biomass)

communities <- rasterizeReduced(reducedDT, fullRas, "communities")
setColors(communities) <- c("blue", "orange", "red")
if (interactive()) {
  clearPlot()
  Plot(biomass, communities, fullRas)
}
# }

Run the code above in your browser using DataLab