Learn R Programming

sp (version 1.6-0)

CRS-class: Class "CRS" of coordinate reference system arguments

Description

Interface class to the PROJ projection and transformation system. The class is defined as an empty stub accepting value NA in the sp package. The initiation function may call the PROJ library through rgdal to verify the argument set against those known in the library, returning error messages where necessary. If the "CRS" object is instantiated using CRS() with rgdal using PROJ >= 6 and GDAL >= 3, the object may also have a WKT2 (2019) string carried as a comment. The arguments for a Proj.4 string must be entered exactly as in the Proj.4 documentation, in particular there cannot be any white space in +<key>=<value> strings, and successive such strings can only be separated by blanks. Note that only “+proj=longlat +ellps=WGS84” is accepted for geographical coordinates, which must be ordered (eastings, northings); the “+ellps=” definition must be given (or expanded internally from a given “+datum=” value) for recent versions of the Proj.4 library, and should be set to an appropriate value.

Usage

CRS(projargs, doCheckCRSArgs=TRUE, SRS_string=NULL, get_source_if_boundcrs=TRUE,
 use_cache=TRUE)
identicalCRS(x,y)

Value

CRS returns on success an object of class CRS. identicalCRS returns a logical, indicating whether x and y have identical CRS, or if y

is missing whether all objects in list x

have identical CRS.

Objects from the Class

Objects can be created by calls of the form CRS("projargs"), where "projargs" is a valid string of PROJ.4 arguments. If the argument is a zero-length string or a character NA, the object records NA. If the "CRS" object is instantiated using CRS() with rgdal using PROJ >= 6 and GDAL >= 3, the object may also have a WKT2 (2019) string carried as a comment. The initiation function may call the PROJ library through rgdal to verify the argument set against those known in the library, returning error messages where necessary. The function CRSargs() can be used to show the expanded Proj.4 string used by the PROJ library.

Slots

projargs:

Object of class "character": projection arguments; the arguments must be entered exactly as in the PROJ.4 documentation, in particular there cannot be any white space in +<arg>=<value> strings, and successive such strings can only be separated by blanks.

Methods

show

signature(object = "CRS"): print deprecated Proj.4 projection arguments and WKT2 2019 representation if available

wkt

signature(object = "CRS"): return WKT comment on object

rebuild_CRS

rebuild a CRS object, usually used to add a WKT comment with PROJ >= 6 and GDAL >= 3

Arguments

projargs

A character string of projection arguments; the arguments must be entered exactly as in the PROJ.4 documentation; if the projection is unknown, use as.character(NA), it may be missing or an empty string of zero length and will then set to the missing value. With rgdal built with PROJ >= 6 and GDAL >= 3, the +init= key may only be used with value epsg:<code>. From sp version 1.4-4, the string associated with the SRS_string argument may be entered as-is and will be set as SRS_string if the projargs argument does not begin with a + (suggested by Mikko Vihtakari).

doCheckCRSArgs

default TRUE, must be set to FALSE by package developers including CRS in an S4 class definition to avoid uncontrollable loading of the rgdal namespace

SRS_string

default NULL, only used when rgdal is built with PROJ >= 6 and GDAL >= 3; a valid WKT string or SRS definition such as "EPSG:4326" or "ESRI:102761"

get_source_if_boundcrs

(from rgdal 1.5-17, default TRUE) The presence of the +towgs84= key in a Proj4 string projargs= argument value may promote the output WKT2 CRS to BOUNDCRS for PROJ >= 6 and GDAL >= 3, which is a coordinate operation from the input datum to WGS84. This is often unfortunate, so a PROJ function is called through rgdal to retrieve the underlying source definition.

use_cache

default TRUE, if FALSE ignore cached lookup values

x

object having a proj4string method, or if y is missing, list with objects that have a proj4string method

y

object of class Spatial, or having a proj4string method

Author

Roger Bivand Roger.Bivand@nhh.no

References

https://github.com/OSGeo/PROJ

Examples

Run this code
CRS()
CRS("")
CRS(as.character(NA))
CRS("+proj=longlat +datum=WGS84")
run <- FALSE
run <- require(rgdal) 
if (run) {
  print(CRSargs(CRS("+proj=longlat +datum=NAD27")))
}
if (run) {
  print(CRSargs(CRS("+init=epsg:4267")))
}
if (run) {
  print(CRSargs(CRS("+init=epsg:26978")))
}
if (run) {
  print(CRSargs(CRS(paste("+proj=sterea +lat_0=52.15616055555555",
 "+lon_0=5.38763888888889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel",
 " +towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +units=m"))))
}
if (run) {
  print(CRSargs(CRS("+init=epsg:28992")))
}
if (run) {
  print(CRSargs(CRS("EPSG:28992")))
}
if (run) {
  print(CRSargs(CRS(SRS_string="EPSG:28992")))
}
if (run) {
  o <- try(CRS(SRS_string="ESRI:102760"))
  if (!inherits(o, "try-error")) print(CRSargs(o))
}
if (run) {
  o <- try(CRS("EPSG:4326"))
  if (!inherits(o, "try-error")) print(CRSargs(o))
}
if (run) {
  o <- try(CRS("ESRI:102760"))
  if (!inherits(o, "try-error")) print(CRSargs(o))
}
if (run) {
o <- new("Spatial")
proj4string(o) <- CRS("+init=epsg:27700")
}
if (run && !is.null(comment(slot(o, "proj4string")))) {
  cat(wkt(o), sep="\n")
  cat(wkt(slot(o, "proj4string")), sep="\n")
}

Run the code above in your browser using DataLab