project | R Documentation |
Change the coordinate reference system ("project") of a SpatVector, SpatRaster or a matrix with coordinates.
## S4 method for signature 'SpatVector'
project(x, y, partial = FALSE)
## S4 method for signature 'SpatRaster'
project(x, y, method, mask=FALSE, align_only=FALSE, res=NULL,
origin=NULL, threads=FALSE, filename="", ..., use_gdal=TRUE, by_util = FALSE)
## S4 method for signature 'SpatExtent'
project(x, from, to)
## S4 method for signature 'matrix'
project(x, from, to)
x |
SpatRaster, SpatVector, SpatExtent or matrix (with x and y columns) whose coordinates to project |
y |
if You can use the following formats to define coordinate reference systems: WKT, PROJ.4 (e.g., If |
partial |
logical. If |
method |
character. Method used for estimating the new cell values of a SpatRaster. One of:
|
mask |
logical. If |
align_only |
logical. If |
res |
numeric. Can be used to set the resolution of the output raster if |
origin |
numeric. Can be used to set the origin of the output raster if |
threads |
logical. If |
filename |
character. Output filename |
... |
additional arguments for writing files as in |
use_gdal |
logical. If |
by_util |
logical. If |
from |
character. Coordinate reference system of |
to |
character. Output coordinate reference system |
SpatVector or SpatRaster
The PROJ.4 notation of coordinate reference systems has been partly deprecated in the GDAL/PROJ library that is used by this function. You can still use this notation, but *only* with the WGS84 datum. Other datums are silently ignored.
Transforming (projecting) raster data is fundamentally different from transforming vector data. Vector data can be transformed and back-transformed without loss in precision and without changes in the values. This is not the case with raster data. In each transformation the values for the new cells are estimated in some fashion. Therefore, if you need to match raster and vector data for analysis, you should generally transform the vector data.
When using this method with a SpatRaster
, the preferable approach is to provide a template SpatRaster
as argument y
. The template is then another raster dataset that you want your data to align with. If you do not have a template to begin with, you can do project(rast(x), crs)
and then manipulate the output to get the template you want. For example, where possible use whole numbers for the extent and resolution so that you do not have to worry about small differences in the future. You can use commands like dim(z) = c(180, 360)
or res(z) <- 100000
.
The output resolution should generally be similar to the input resolution, but there is no "correct" resolution in raster transformation. It is not obvious what this resolution is if you are using lon/lat data that spans a large North-South extent.
crs
, resample
## SpatRaster
a <- rast(ncols=40, nrows=40, xmin=-110, xmax=-90, ymin=40, ymax=60,
crs="+proj=longlat +datum=WGS84")
values(a) <- 1:ncell(a)
newcrs="+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
b <- rast(ncols=94, nrows=124, xmin=-944881, xmax=935118, ymin=4664377, ymax=7144377, crs=newcrs)
w <- project(a, b)
## SpatVector
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
crs(v, proj=TRUE)
cat(crs(v), "\n")
project(v, "+proj=moll")
project(v, "EPSG:2169")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.