merge,GRaster,GRaster-method | R Documentation |
merge()
combines two or more GRaster
s, possibly with different extents, into a single larger GRaster
. Where the same cell has different values in each raster, the value of the first raster's cell is used. If this is NA
, then the value of the second raster's cell is used, and so on.
## S4 method for signature 'GRaster,GRaster'
merge(x, y, ...)
x , y , ... |
|
A GRaster
.
terra::merge()
, terra::mosaic()
, and GRASS module r.patch
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Example data
madElev <- fastData("madElev")
madCoast4 <- fastData("madCoast4")
madCoast4 <- vect(madCoast4)
# For the example, crop the elevation raster to two communes
madAnt <- madCoast4[madCoast4$NAME_4 == "Antanambe", ]
madMan <- madCoast4[madCoast4$NAME_4 == "Manompana", ]
elevAnt <- crop(madElev, madAnt)
elevMan <- crop(madElev, madMan)
plot(madElev)
plot(elevAnt, col = "red", legend = FALSE, add = TRUE)
plot(elevMan, col = "blue", legend = FALSE, add = TRUE)
# Convert a SpatRaster to a GRaster
ant <- fast(elevAnt)
man <- fast(elevMan)
# merge
antMan <- merge(ant, man)
plot(antMan, main = "Antman!")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.