st_crs: Retrieve coordinate reference system from object

Description Usage Arguments Format Details Value Examples

View source: R/crs.R

Description

Retrieve coordinate reference system from sf or sfc object

Set or replace retrieve coordinate reference system from object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
st_crs(x, ...)

## S3 method for class 'sf'
st_crs(x, ...)

## S3 method for class 'numeric'
st_crs(x, proj4text = "", valid = TRUE, ...)

## S3 method for class 'character'
st_crs(x, ..., wkt)

## S3 method for class 'sfc'
st_crs(x, ..., parameters = FALSE)

## S3 method for class 'bbox'
st_crs(x, ...)

## S3 method for class 'CRS'
st_crs(x, ...)

## S3 method for class 'crs'
st_crs(x, ...)

st_crs(x) <- value

## S3 replacement method for class 'sf'
st_crs(x) <- value

## S3 replacement method for class 'sfc'
st_crs(x) <- value

st_set_crs(x, value)

NA_crs_

## S3 method for class 'crs'
is.na(x)

## S3 method for class 'crs'
x$name

Arguments

x

numeric, character, or object of class sf or sfc

...

ignored

proj4text

character. Must be used in conjunction with valid = FALSE.

valid

default TRUE. This allows to create crs without checking against the local proj4 database. It can be used to synchronize crs with a remote database, but avoid it as much as possible.

wkt

character well-known-text representation of the crs

parameters

logical; FALSE by default; if TRUE return a list of coordinate reference system parameters, with named elements SemiMajor, InvFlattening, units_gdal, IsVertical, WktPretty, and Wkt

value

one of (i) character: a valid proj4string (ii) integer, a valid EPSG value (numeric), or (iii) a list containing named elements proj4string (character) and/or epsg (integer) with (i) and (ii).

name

element name; epsg or proj4string, or one of proj4strings named components without the +; see examples

Format

An object of class crs of length 2.

Details

The *crs functions create, get, set or replace the crs attribute of a simple feature geometry list-column. This attribute is of class crs, and is a list consisting of epsg (integer EPSG code) and proj4string (character). Two objects of class crs are semantically identical when: (1) they are completely identical, or (2) they have identical proj4string but one of them has a missing EPSG ID. As a consequence, equivalent but different proj4strings, e.g. "+proj=longlat +datum=WGS84" and "+datum=WGS84 +proj=longlat" , are considered different. The operators == and != are overloaded for crs objects to establish semantical identity.

In case a coordinate reference system is replaced, no transformation takes place and a warning is raised to stress this. EPSG values are either read from proj4strings that contain +init=epsg:... or set to 4326 in case the proj4string contains +proj=longlat and +datum=WGS84, literally.

If both epsg and proj4string are provided, they are assumed to be consistent. In processing them, the EPSG code, if not missing valued, is used and the proj4string is derived from it by a call to GDAL (which in turn will call PROJ.4). Warnings are raised when epsg is not consistent with a proj4string that is already present.

NA_crs_ is the crs object with missing values for epsg and proj4string.

Value

If x is numeric, return crs object for SRID x; if x is character, return crs object for proj4string x; if wkt is given, return crs object for well-known-text representation wkt; if x is of class sf or sfc, return its crs object.

Object of class crs, which is a list with elements epsg (length-1 integer) and proj4string (length-1 character).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
sf = st_sf(a = 1:2, geom = sfc)
st_crs(sf) = 4326
st_geometry(sf)
sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs(sfc) = 4326
sfc
sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
library(dplyr)
x = sfc %>% st_set_crs(4326) %>% st_transform(3857)
x
st_crs("+init=epsg:3857")$epsg
st_crs("+init=epsg:3857")$proj4string
st_crs("+init=epsg:3857 +units=m")$b     # numeric
st_crs("+init=epsg:3857 +units=m")$units # character

sf documentation built on July 24, 2019, 5:05 p.m.