extend,GRaster,numeric-method | R Documentation |
extend()
adds cells around a raster, making it larger.
## S4 method for signature 'GRaster,numeric'
extend(x, y, fill = NA)
## S4 method for signature 'GRaster,SpatRaster'
extend(x, y, snap = "near", fill = NA)
## S4 method for signature 'GRaster,SpatVector'
extend(x, y, snap = "near", fill = NA)
## S4 method for signature 'GRaster,SpatExtent'
extend(x, y, snap = "near", fill = NA)
## S4 method for signature 'GRaster,sf'
extend(x, y, snap = "near", fill = NA)
## S4 method for signature 'GRaster,GSpatial'
extend(x, y, snap = "near", fill = NA)
x |
A |
y |
Any of:
|
fill |
Numeric: Value to place in the new cells. The default is |
snap |
Character: Method used to align
|
Known issues: When GRaster
s are saved to disk explicitly using writeRaster()
, or implicitly using rast()
or plot()
, rows and columns that are entirely NA
are dropped.
A GRaster
.
terra::extend()
if (grassStarted()) {
# Setup
library(terra)
# Example data
madElev <- fastData("madElev")
madRivers <- fastData("madRivers")
# Send spatial objects to GRASS:
elev <- fast(madElev)
rivers <- fast(madRivers)
# Extend raster by number of rows/columns:
extended1 <- extend(elev, 10, fill = 900)
extended2 <- extend(elev, c(10, 20), fill = 900)
extended3 <- extend(elev, c(10, 80, 0, 100), fill = 900)
dim(elev)
dim(extended1)
dim(extended2)
dim(extended3)
plot(extended3)
# When exporting a raster, NA rows and columns are removed.
extended4 <- extend(elev, 100, fill=1) # default fill is NA
extended4terra <- rast(extended4)
dim(extended4)
dim(extended4terra)
plot(extended4)
# Extend the raster by another object with a wider extent.
# For tis example, first crop the raster, then extend it.
elevCrop <- crop(elev, rivers)
uncrop <- extend(elevCrop, elev, fill = 900)
plot(uncrop)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.