| project,GRaster-method | R Documentation |
project() changes the coordinate reference system (CRS) of a GRaster or GVector. It has three use cases:
x is a GRaster and y is a GRaster: x will be projected to the CRS of y and resampled to have the same resolution as y. If argument align is FALSE, then it will also be cropped to the extent of y.
x is a GRaster and y is a GVector or a CRS string (typically in Well-Known Text format): x will be projected to the CRS specified by y and resampled but not cropped.
x is a GVector and y is a GRaster, GVector, or CRS string: The vector will be projected to the CRS of y.
## S4 method for signature 'GRaster'
project(
x,
y,
align = FALSE,
method = NULL,
fallback = TRUE,
res = "fallback",
wrap = FALSE,
verbose = FALSE
)
## S4 method for signature 'GVector'
project(x, y, wrap = FALSE)
x |
A |
y |
A character or |
align |
Logical: If |
method |
Character or
Note #1: If Note #2: Methods that use multiple cells will cause the focal cell to become |
fallback |
Logical (for projecting |
res |
Character (for projecting
|
wrap |
Logical:
|
verbose |
Logical (for projecting |
When projecting a raster, the "fallback" methods in GRASS module r.import are actually used, even though the method argument takes the strings specifying non-fallback methods. See the manual page for the r.import GRASS module.
A GRaster or GVector.
terra::project(), sf::st_transform(), GRASS manual pages for modules r.proj and v.proj (see grassHelp("r.proj") and grassHelp("v.proj"))
if (grassStarted()) {
### Setup for all examples
library(sf)
library(terra)
# Climate raster, elevation raster, rivers vector
madElev <- fastData("madElev")
madRivers <- fastData("madRivers")
madChelsa <- fastData("madChelsa")
# Convert objects into fasterRaster formats
chelsa <- fast(madChelsa)
elev <- fast(madElev)
rivers <- fast(madRivers)
### Project raster without resampling
elevWGS84 <- project(elev, crs(chelsa))
elevWGS84
### Project raster and resample to resolution of another raster
elevWGS84Resamp <- project(elev, chelsa)
elevWGS84Resamp
res(elevWGS84)
res(elevWGS84Resamp)
res(chelsa)
### Project vector
riversWGS84 <- project(rivers, chelsa)
riversWGS84
cat(crs(rivers)) # using "cat()" to make it look nice
cat(crs(riversWGS84))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.