Learn R Programming

spatialEco (version 2.0-1)

combine: raster combine

Description

Combines rasters into all unique combinations of inputs

Usage

combine(x)

Value

A ratified rasterLayer or a list containing a SpatialPixelsDataFrame and a data.frame of unique combinations.

Arguments

x

raster stack/brick or SpatialPixelsDataFrame object

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Details

Please note that this is not a memory safe function that utilizes rasters out of memory in the manner that the raster package does.

If sp = TRUE the object will be a list with "combine", containing the SpatialPixelsDataFrame with the value attribute containing the unique combinations, and "summary" with the summary table of collapsed combinations and associated attributes.

If sp = FALSE the a single ratified rasterLayer class object is returned with the summary table as the raster attribute table, this is most similar to the ESRI format resulting from their combine function.

Examples

Run this code
if(require(terra, quietly = TRUE)) { 

# Create example data (with a few NA's introduced)
 r1 <- rast(nrows=100, ncol=100)
   names(r1) <- "LC1"
   r1[] <- round(runif(ncell(r1), 1,4),0)
     r1[c(8,10,50,100)] <- NA
 r2 <- rast(nrows=100, ncol=100)
   names(r2) <- "LC2"
   r2[] <- round(runif(ncell(r2), 2,6),0)
     r2[c(10,50,100)] <- NA   
 r3 <- rast(nrows=100, ncol=100)
   names(r3) <- "LC3"
   r3[] <- round(runif(ncell(r3), 2,6),0)
     r3[c(10,50,100)] <- NA   
 r <- c(r1,r2,r3)  
   names(r) <- c("LC1","LC2","LC3")

 # Combine rasters with a multilayer stack
 cr <- combine(r)
   head(cr$summary)
   plot(cr$combine)

# or, from separate layers
 cr <- combine(c(r1,r3))

}

Run the code above in your browser using DataLab