Skip to main content
added 955 characters in body
Source Link
Mikko
  • 374
  • 1
  • 3
  • 15

EDIT: What if you want both, the string and comment? Use raster::crs(). This can be useful to keep it PROJ6 through a function/script.

raster::crs(x)
#> CRS arguments: +proj=longlat +datum=WGS84 +no_defs 

comment(raster::crs(x))
[1] "GEOGCRS[\"WGS 84 (with axis order normalized for visualization)\",\n    DATUM[\"World Geodetic System 1984\",\n        ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n            LENGTHUNIT[\"metre\",1]],\n        ID[\"EPSG\",6326]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433],\n        ID[\"EPSG\",8901]],\n    CS[ellipsoidal,2],\n        AXIS[\"geodetic longitude (Lon)\",east,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]],\n        AXIS[\"geodetic latitude (Lat)\",north,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]]]"

Created on 2021-05-27 by the reprex package (v2.0.0)

Created on 2021-05-27 by the reprex package (v2.0.0)

EDIT: What if you want both, the string and comment? Use raster::crs(). This can be useful to keep it PROJ6 through a function/script.

raster::crs(x)
#> CRS arguments: +proj=longlat +datum=WGS84 +no_defs 

comment(raster::crs(x))
[1] "GEOGCRS[\"WGS 84 (with axis order normalized for visualization)\",\n    DATUM[\"World Geodetic System 1984\",\n        ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n            LENGTHUNIT[\"metre\",1]],\n        ID[\"EPSG\",6326]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433],\n        ID[\"EPSG\",8901]],\n    CS[ellipsoidal,2],\n        AXIS[\"geodetic longitude (Lon)\",east,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]],\n        AXIS[\"geodetic latitude (Lat)\",north,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]]]"

Created on 2021-05-27 by the reprex package (v2.0.0)

added 41 characters in body
Source Link
Mikko
  • 374
  • 1
  • 3
  • 15

To assign a CRS to a SpatialPolygons object, which does not have a CRS, use the sp::proj4string function even though you are assigning wkt (= well-known text, PROJ6 CRS format). Note how you can now omit the SRS_string argument within sp::CRS().

The sp::proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in the assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the sp::proj4string() function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

To assign a CRS to a SpatialPolygons object which does not have a CRS, use the sp::proj4string function even though you are assigning PROJ6. Note how you can now omit the SRS_string argument within sp::CRS().

The sp::proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the sp::proj4string() function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

To assign a CRS to a SpatialPolygons object, which does not have a CRS, use the sp::proj4string function even though you are assigning wkt (= well-known text, PROJ6 CRS format). Note how you can now omit the SRS_string argument within sp::CRS().

The sp::proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in the assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the sp::proj4string() function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

added 24 characters in body
Source Link
Mikko
  • 374
  • 1
  • 3
  • 15

The sp::proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the sp::proj4string() function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

The proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

The sp::proj4string() should be understood as a function name. It does not necessarily have to do with PROJ4 any longer if it is used in assignment. The good news is that you only need to change the "inside" from "+init=epsg:4326" to "EPSG:4326" in the sp::CRS() function and things should work as previously as long as you do not use the sp::proj4string() function to retrieve PROJ6 (wkt) information. If you do, you'll get a warning, but the comment is actually not lost anyway in the assignment (as demonstrated by the proj4string(y) <- proj4string(x) example). It is only lost if you use proj4string() to print CRS information:

added 96 characters in body
Source Link
Mikko
  • 374
  • 1
  • 3
  • 15
Loading
Source Link
Mikko
  • 374
  • 1
  • 3
  • 15
Loading