Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choice for printed crs output #168

Closed
florisvdh opened this issue Sep 28, 2020 · 3 comments
Closed

Choice for printed crs output #168

florisvdh opened this issue Sep 28, 2020 · 3 comments

Comments

@florisvdh
Copy link
Contributor

florisvdh commented Sep 28, 2020

Related to #78. Going forward with PROJ 6+ and GDAL 3, raster currently (since at least c9f4464) supports WKT and EPSG-codes so that proj4strings can be avoided in code, which I find really great. Also, the arguments and functions already used the general term crs, which avoids confusion between alternative CRS representations.

Currently, when printing a Raster* object, a proj4string is still printed. As a suggestion to provide more consistency when avoiding proj4string, i.e. when PROJ 6+ and GDAL 3 are used, it seems useful to print the WKT string or a descriptive CRS name. @rhijmans are there intentions to make changes in this area?

It could for example improve consistency with sf, where a CRS name is printed if possible:

cities <- sf::st_read(system.file("vectors/cities.shp", package = "rgdal"))
#> Reading layer `cities' from data source `/home/floris/lib/R/library/rgdal/vectors/cities.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 606 features and 4 fields
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: -165.27 ymin: -53.15 xmax: 177.1302 ymax: 78.2
#> geographic CRS: WGS 84

Created on 2020-09-28 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       Linux Mint 20               
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language nl_BE:nl                    
#>  collate  nl_BE.UTF-8                 
#>  ctype    nl_BE.UTF-8                 
#>  tz       Europe/Brussels             
#>  date     2020-09-28                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
#>  backports     1.1.10  2020-09-15 [1] CRAN (R 4.0.2)
#>  callr         3.4.4   2020-09-07 [1] CRAN (R 4.0.2)
#>  class         7.3-17  2020-04-26 [4] CRAN (R 4.0.0)
#>  classInt      0.4-3   2020-04-07 [1] CRAN (R 4.0.2)
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.2)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.2)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)
#>  devtools      2.3.2   2020-09-18 [1] CRAN (R 4.0.2)
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.2)
#>  dplyr         1.0.2   2020-08-18 [1] CRAN (R 4.0.2)
#>  e1071         1.7-3   2019-11-26 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.2)
#>  KernSmooth    2.23-17 2020-04-26 [4] CRAN (R 4.0.0)
#>  knitr         1.30    2020-09-22 [1] CRAN (R 4.0.2)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)
#>  pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
#>  processx      3.4.4   2020-09-03 [1] CRAN (R 4.0.2)
#>  ps            1.3.4   2020-08-11 [1] CRAN (R 4.0.2)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.2)
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)
#>  reprex        0.3.0   2019-05-16 [1] CRAN (R 4.0.2)
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)
#>  rmarkdown     2.3     2020-06-18 [1] CRAN (R 4.0.2)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  sf            0.9-6   2020-09-13 [1] CRAN (R 4.0.2)
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)
#>  tibble        3.0.3   2020-07-10 [1] CRAN (R 4.0.2)
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)
#>  units         0.6-7   2020-06-13 [1] CRAN (R 4.0.2)
#>  usethis       1.6.3   2020-09-17 [1] CRAN (R 4.0.2)
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)
#>  xfun          0.17    2020-09-09 [1] CRAN (R 4.0.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

The sf documentation says:

format.crs returns NA if the crs is missing valued, or else the name of a crs if it is different from "unknown", or else the user input if it was set, or else its "proj4string" representation

printed proj4string with current raster (caf4148)
library(raster)
#> Loading required package: sp
raster(crs = sf::st_crs(31370)$wkt)
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO"): Discarded
#> datum Reseau_National_Belge_1972 in CRS definition
#> class      : RasterLayer 
#> dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#> resolution : 1, 1  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=lcc +lat_0=90 +lon_0=4.36748666666667 +lat_1=51.1666672333333 +lat_2=49.8333339 +x_0=150000.013 +y_0=5400088.438 +ellps=intl +towgs84=-99.059,53.322,-112.486,0.419,-0.83,1.885,-1 +units=m +no_defs
raster(crs = CRS(SRS_string = "EPSG:31370"))
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO"): Discarded
#> datum Reseau_National_Belge_1972 in CRS definition
#> class      : RasterLayer 
#> dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#> resolution : 1, 1  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=lcc +lat_0=90 +lon_0=4.36748666666667 +lat_1=51.1666672333333 +lat_2=49.8333339 +x_0=150000.013 +y_0=5400088.438 +ellps=intl +units=m +no_defs
raster(crs = 31370)
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO"): Discarded
#> datum Reseau_National_Belge_1972 in CRS definition
#> class      : RasterLayer 
#> dimensions : 180, 360, 64800  (nrow, ncol, ncell)
#> resolution : 1, 1  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=lcc +lat_0=90 +lon_0=4.36748666666667 +lat_1=51.1666672333333 +lat_2=49.8333339 +x_0=150000.013 +y_0=5400088.438 +ellps=intl +units=m +no_defs

Created on 2020-09-28 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       Linux Mint 20               
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language nl_BE:nl                    
#>  collate  nl_BE.UTF-8                 
#>  ctype    nl_BE.UTF-8                 
#>  tz       Europe/Brussels             
#>  date     2020-09-28                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source                          
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)                  
#>  backports     1.1.10  2020-09-15 [1] CRAN (R 4.0.2)                  
#>  callr         3.4.4   2020-09-07 [1] CRAN (R 4.0.2)                  
#>  class         7.3-17  2020-04-26 [4] CRAN (R 4.0.0)                  
#>  classInt      0.4-3   2020-04-07 [1] CRAN (R 4.0.2)                  
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.2)                  
#>  codetools     0.2-16  2018-12-24 [4] CRAN (R 4.0.0)                  
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)                  
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.2)                  
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)                  
#>  devtools      2.3.2   2020-09-18 [1] CRAN (R 4.0.2)                  
#>  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.2)                  
#>  dplyr         1.0.2   2020-08-18 [1] CRAN (R 4.0.2)                  
#>  e1071         1.7-3   2019-11-26 [1] CRAN (R 4.0.2)                  
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)                  
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)                  
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)                  
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)                  
#>  generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.2)                  
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)                  
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)                  
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.2)                  
#>  KernSmooth    2.23-17 2020-04-26 [4] CRAN (R 4.0.0)                  
#>  knitr         1.30    2020-09-22 [1] CRAN (R 4.0.2)                  
#>  lattice       0.20-41 2020-04-02 [4] CRAN (R 4.0.0)                  
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)                  
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)                  
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)                  
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)                  
#>  pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)                  
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)                  
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)                  
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)                  
#>  processx      3.4.4   2020-09-03 [1] CRAN (R 4.0.2)                  
#>  ps            1.3.4   2020-08-11 [1] CRAN (R 4.0.2)                  
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)                  
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.2)                  
#>  raster      * 3.3-16  2020-09-28 [1] Github (rspatial/raster@caf4148)
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)                  
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)                  
#>  reprex        0.3.0   2019-05-16 [1] CRAN (R 4.0.2)                  
#>  rgdal         1.5-16  2020-08-07 [1] CRAN (R 4.0.2)                  
#>  rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)                  
#>  rmarkdown     2.3     2020-06-18 [1] CRAN (R 4.0.2)                  
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.2)                  
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)                  
#>  sf            0.9-6   2020-09-13 [1] CRAN (R 4.0.2)                  
#>  sp          * 1.4-2   2020-05-20 [1] CRAN (R 4.0.2)                  
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)                  
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)                  
#>  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)                  
#>  tibble        3.0.3   2020-07-10 [1] CRAN (R 4.0.2)                  
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)                  
#>  units         0.6-7   2020-06-13 [1] CRAN (R 4.0.2)                  
#>  usethis       1.6.3   2020-09-17 [1] CRAN (R 4.0.2)                  
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)                  
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)                  
#>  xfun          0.17    2020-09-09 [1] CRAN (R 4.0.2)                  
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)                  
#> 
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
@rhijmans
Copy link
Member

The WKT string is too verbose. EPSG codes are not informative. The proj.4 description is a short and very expressive. I cannot think of a better alternative.

@florisvdh
Copy link
Contributor Author

Thanks for your response @rhijmans .

As I understand it, proj4strings returned by rgdal/sp nowadays will not necessarily contain all needed information anymore to adequately define the CRS (it will depend on the CRS at hand), because GDAL3/PROJ>=6 only partly support proj4strings (e.g. +datum and +towgs84 keys are dropped).

It may be not too harmful here in the sense that proj4strings would just be used in printing (when using recent GDAL/PROJ), but proj4strings are to be regarded as obsolete. To keep the printed CRS short, I'd still prefer a name or a code (which can be used to look up the correct WKT string) over a string of CRS parameters one cannot just trust.

The following slides of R. Bivand (from slide 55 onward) provide an interesting example of proj4string degradation (with consequences): https://github.com/rsbivand/whyR20_files/raw/master/bivand_200927.pdf

@rhijmans
Copy link
Member

rhijmans commented Nov 7, 2020

At this point I prefer having more information rather than less. If you want the gory details, you can use crs(x)
The fundamental problem is that there is infinite number of crs'; so a code cannot be generally used. proj.4 is a short description that provides all the information needed for the majority of cases. It is very unfortunate that the PROJ lib will ignore the datum when it is not not WGS84 --- and I should add some code that warns for that.

@rhijmans rhijmans closed this as completed Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants