Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

crs

Get or set a coordinate reference system


Description

Get or set the coordinate reference system (CRS), also referred to as a "projection", of a SpatRaster or SpatVector object.

Setting a new CRS does not change the data itself, it just changes the label. So you should only set the CRS of a dataset (if it does not come with one) to what it *is*, not to what you would *like it to be*. See project to *transform* an object from one CRS to another.

Usage

## S4 method for signature 'SpatRaster'
crs(x, proj4=FALSE, describe=FALSE)

## S4 method for signature 'SpatVector'
crs(x, proj4=FALSE, describe=FALSE)

## S4 replacement method for signature 'SpatRaster'
crs(x)<-value

## S4 replacement method for signature 'SpatVector'
crs(x)<-value

Arguments

x

SpatRaster or SpatVector

proj4

logical. If TRUE the crs is returned in PROJ.4 notation. But note that GDAL now only supports the WGS84 and NAD83 datums with this notation

describe

logical. If TRUE the name, EPSG code, and the name and extent of the area of use are returned if known

value

character string describing a coordinate reference system. This can be in a WKT format, as a EPSG code, or a PROJ.4 "+" format (but see Note)

Value

character or modified SpatRaster/Vector

Note

Because of changes in the PROJ library that is behind the coordinate transformations, when using the PROJ.4 format, the datum should be WGS84 – if you want to transform your data to a different coordinate reference system)

Examples

r <- rast()
crs(r)
crs(r, describe=TRUE, proj4=TRUE)

crs(r) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
crs(r)

# You can also use epsg codes
crs(r)  <- "epsg:25831"
crs(r, describe=TRUE)$area

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.