Interface class to the PROJ.4 projection system. The class is defined as an empty stub accepting value NA in the sp package. If the rgdal package is available, then the class will permit spatial data to be associated with coordinate reference systems

checkCRSArgs(uprojargs)
checkCRSArgs_ng(uprojargs=NA_character_, SRS_string=NULL,
  get_source_if_boundcrs=TRUE)
compare_CRS(CRS1, CRS2)

Arguments

uprojargs

character string PROJ.4 projection arguments

SRS_string

default NULL, experimental in connection with adaptation to GDAL>=3/PROJ>=6; a valid WKT string or SRS definition such as "OGC:CRS84"

get_source_if_boundcrs

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.

CRS1, CRS2

objects of class "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; 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. The initiation function calls the PROJ.4 library to verify the argument set against those known in the library, returning error messages where necessary. The complete argument set may be retrieved by examining the second list element returned by validObject("CRS object") to see which additional arguments the library will use (which assumptions it is making over and above submitted arguments). The function CRSargs() can be used to show the expanded argument list used by the PROJ.4 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 projection arguments in object

References

https://proj.org/

Author

Roger Bivand Roger.Bivand@nhh.no

Note

Lists of projections may be seen by using the programs installed with the PROJ.4 library, in particular proj and cs2cs; with the latter, -lp lists projections, -le ellipsoids, -lu units, and -ld datum(s) known to the installed software (available in rgdal using projInfo). These are added to in successive releases, so tracking the website or compiling and installing the most recent revisions will give the greatest choice. Finding the very important datum transformation parameters to be given with the +towgs84 tag is a further challenge, and is essential when the datums used in data to be used together differ. Tracing projection arguments is easier now than before the mass ownership of GPS receivers raised the issue of matching coordinates from different argument sets (GPS output and paper map, for example). See GridsDatums and showEPSG for help in finding CRS definitions.

The 4.9.1 release of PROJ.4 omitted a small file of defaults, leading to reports of “major axis or radius = 0 or not given” errors. From 0.9-3, rgdal checks for the presence of this file (proj_def.dat), and if not found, and under similar conditions to those used by PROJ.4, adds “+ellps=WGS84” to the input string being checked by checkCRSArgs The “+no_defs” tag ignores the file of defaults, and the default work-around implemented to get around this problem; strings including “init” and “datum” tags also trigger the avoidance of the work-around. Now messages are issued when a candidate CRS is checked; they may be suppressed using suppressMessages.

Examples

set_thin_PROJ6_warnings(TRUE) CRSargs(CRS("+proj=longlat"))
#> [1] "+proj=longlat +datum=WGS84 +no_defs"
try(CRS("+proj=longlat"))
#> Coordinate Reference System: #> Deprecated Proj.4 representation: +proj=longlat +datum=WGS84 +no_defs #> WKT2 2019 representation: #> GEOGCRS["unknown", #> DATUM["World Geodetic System 1984", #> ELLIPSOID["WGS 84",6378137,298.257223563, #> LENGTHUNIT["metre",1]], #> ID["EPSG",6326]], #> PRIMEM["Greenwich",0, #> ANGLEUNIT["degree",0.0174532925199433], #> ID["EPSG",8901]], #> CS[ellipsoidal,2], #> AXIS["longitude",east, #> ORDER[1], #> ANGLEUNIT["degree",0.0174532925199433, #> ID["EPSG",9122]]], #> AXIS["latitude",north, #> ORDER[2], #> ANGLEUNIT["degree",0.0174532925199433, #> ID["EPSG",9122]]]]
CRSargs(CRS("+proj=longlat +datum=NAD27"))
#> [1] "+proj=longlat +datum=NAD27 +no_defs"
CRSargs(CRS("+init=epsg:4267"))
#> [1] "+proj=longlat +datum=NAD27 +no_defs"
CRSargs(CRS("+init=epsg:26978"))
#> [1] "+proj=lcc +lat_0=36.6666666666667 +lon_0=-98.5 +lat_1=38.5666666666667 +lat_2=37.2666666666667 +x_0=400000 +y_0=400000 +datum=NAD83 +units=m +no_defs"
CRSargs(CRS(paste("+proj=stere +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")))
#> [1] "+proj=stere +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"
# see http://trac.osgeo.org/gdal/ticket/1987 CRSargs(CRS("+init=epsg:28992"))
#> [1] "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"
crs <- CRS("+init=epsg:28992") CRSargs(CRS(CRSargs(crs)))
#> [1] "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"
library(sp) data(meuse) coordinates(meuse) <- c("x", "y") proj4string(meuse) <- CRS("+init=epsg:28992") CRSargs(CRS(proj4string(meuse)))
#> Warning: CRS object has comment, which is lost in output; in tests, see #> https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
#> [1] "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"
run <- new_proj_and_gdal() if (run) { c1 <- CRS(SRS_string="OGC:CRS84") c2 <- CRS("+proj=longlat") compare_CRS(c1, c2) }
#> strict equivalent #> FALSE TRUE #> equivalent_except_axis_order #> TRUE
if (run) { comment(c2) <- NULL compare_CRS(c1, c2) }
#> Warning: NULL target CRS comment, falling back to PROJ string
#> strict equivalent #> FALSE TRUE #> equivalent_except_axis_order #> TRUE