Change the coordinate reference system ("project") of a SpatVector or SpatRaster.
# S4 method for SpatVector
project(x, y, ...)# S4 method for SpatRaster
project(x, y, method="bilinear", mask=FALSE,
filename="", overwrite=FALSE, wopt=list(), ...)
SpatVector
if (x
is a SpatRaster, the prefered approach is for y
to be a SpatRaster as well, serving as a template for the output SpatRaster. Alternatively, you can provide a character variable containing a textual coordinate reference system (crs).
You can use the following formats to provide textual coordinate reference system (crs) definitions: WKT, PROJ.4 (e.g., +proj=longlat +datum=WGS84
), or an EPSG code (e.g., "epsg:4326"
) to define the output coordinate reference system (crs). But note that when using PROJ.4 you now must use the WGS84 datum. Other datums are silently ignored.
If x
is a SpatVector, you can provide a crs definition as discussed above, or any other object from which such a crs can be extracted with crs
character. Method used for estimating the new cell values. One of:
near: nearest neighbor. This method is fast, and it can be the preferred method if the cell values represent classes. It is not a good choice for continuous values. bilinear: bilinear interpolation. Default. cubic: cubic interpolation. cubicspline: cubic spline interpolation.
logical. If TRUE
, mask out areas outside the input extent (see example with Robinson projection)
character. Output filename. Optional
logical. If TRUE
, filename
is overwritten
list. Options for writing files as in writeRaster
additional arguments. None implemented
SpatVector or SpatRaster
# NOT RUN {
## SpatRaster
a <- rast(ncol=40, nrow=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(ncol=94, nrow=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 <- "+proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84"
p <- project(v, crs)
p
# }
Run the code above in your browser using DataLab