1

I want to use the Africa Albers Equal Area Conic projection for some analyses on animal territories that span the African continent. https://epsg.io/102022

Unfortunately this has a ESRI code rather than EPSG. The latter play well with many functions in R but not the former.

How do I get around this?

E.g. in the following simple code, it'd be handy to plug in 102022 in place of 4326.

library(sf)
library(spData)

Kenya <- world[world$name_long == "Kenya", 0]
rpoints <- st_sample(Kenya, size = 100, type = "random", crs = st_crs(4326))

2 Answers 2

4

You can just use st_crs("ESRI:102022"):

library(sf)
library(spData)

Kenya <- world[world$name_long == "Kenya", 0]

# Transform to ESRI:102022
Kenya_proj <- st_transform(Kenya,
  crs = st_crs("ESRI:102022")
)

# Sample
rpoints <- st_sample(Kenya,
  size = 100,
  type = "random",
  crs = st_crs("ESRI:102022")
)


# Double check
st_crs(Kenya_proj) == st_crs("ESRI:102022")
#> [1] TRUE

st_crs("ESRI:102022")
#> Coordinate Reference System:
#>   User input: ESRI:102022 
#>   wkt:
#> PROJCRS["Africa_Albers_Equal_Area_Conic",
#>     BASEGEOGCRS["WGS 84",
#>         DATUM["World Geodetic System 1984",
#>             ELLIPSOID["WGS 84",6378137,298.257223563,
#>                 LENGTHUNIT["metre",1]]],
#>         PRIMEM["Greenwich",0,
#>             ANGLEUNIT["Degree",0.0174532925199433]]],
#>     CONVERSION["Africa_Albers_Equal_Area_Conic",
#>         METHOD["Albers Equal Area",
#>             ID["EPSG",9822]],
#>         PARAMETER["Latitude of false origin",0,
#>             ANGLEUNIT["Degree",0.0174532925199433],
#>             ID["EPSG",8821]],
#>         PARAMETER["Longitude of false origin",25,
#>             ANGLEUNIT["Degree",0.0174532925199433],
#>             ID["EPSG",8822]],
#>         PARAMETER["Latitude of 1st standard parallel",20,
#>             ANGLEUNIT["Degree",0.0174532925199433],
#>             ID["EPSG",8823]],
#>         PARAMETER["Latitude of 2nd standard parallel",-23,
#>             ANGLEUNIT["Degree",0.0174532925199433],
#>             ID["EPSG",8824]],
#>         PARAMETER["Easting at false origin",0,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8826]],
#>         PARAMETER["Northing at false origin",0,
#>             LENGTHUNIT["metre",1],
#>             ID["EPSG",8827]]],
#>     CS[Cartesian,2],
#>         AXIS["(E)",east,
#>             ORDER[1],
#>             LENGTHUNIT["metre",1]],
#>         AXIS["(N)",north,
#>             ORDER[2],
#>             LENGTHUNIT["metre",1]],
#>     USAGE[
#>         SCOPE["Not known."],
#>         AREA["Africa"],
#>         BBOX[-35,-25,39,55]],
#>     ID["ESRI",102022]]

Created on 2022-01-19 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Spanish_Spain.1252          
#>  ctype    Spanish_Spain.1252          
#>  tz       Europe/Paris                
#>  date     2022-01-19                  
#> 
#> - Packages -------------------------------------------------------------------
#>  ! package     * version date       lib source        
#>    assertthat    0.2.1   2019-03-21 [2] CRAN (R 4.1.0)
#>    backports     1.4.1   2021-12-13 [1] CRAN (R 4.1.2)
#>  D class         7.3-19  2021-05-03 [2] CRAN (R 4.1.0)
#>    classInt      0.4-3   2020-04-07 [1] CRAN (R 4.1.0)
#>    cli           3.0.1   2021-07-17 [1] CRAN (R 4.1.0)
#>    codetools     0.2-18  2020-11-04 [2] CRAN (R 4.1.0)
#>    crayon        1.4.2   2021-10-29 [1] CRAN (R 4.1.2)
#>    DBI           1.1.1   2021-01-15 [2] CRAN (R 4.1.0)
#>    digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.2)
#>    dplyr         1.0.7   2021-06-18 [1] CRAN (R 4.1.0)
#>    e1071         1.7-9   2021-09-16 [1] CRAN (R 4.1.1)
#>    ellipsis      0.3.2   2021-04-29 [2] CRAN (R 4.1.0)
#>    evaluate      0.14    2019-05-28 [2] CRAN (R 4.1.0)
#>    fansi         0.5.0   2021-05-25 [2] CRAN (R 4.1.0)
#>    fastmap       1.1.0   2021-01-25 [2] CRAN (R 4.1.0)
#>    fs            1.5.0   2020-07-31 [2] CRAN (R 4.1.0)
#>    generics      0.1.1   2021-10-25 [1] CRAN (R 4.1.1)
#>    glue          1.6.0   2021-12-17 [1] CRAN (R 4.1.2)
#>    highr         0.9     2021-04-16 [2] CRAN (R 4.1.0)
#>    htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.1)
#>  D KernSmooth    2.23-20 2021-05-03 [2] CRAN (R 4.1.0)
#>    knitr         1.37    2021-12-16 [1] CRAN (R 4.1.0)
#>    lattice       0.20-45 2021-09-22 [1] CRAN (R 4.1.1)
#>    lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
#>    magrittr      2.0.1   2020-11-17 [2] CRAN (R 4.1.0)
#>    pillar        1.6.4   2021-10-18 [1] CRAN (R 4.1.0)
#>    pkgconfig     2.0.3   2019-09-22 [2] CRAN (R 4.1.0)
#>    proxy         0.4-26  2021-06-07 [2] CRAN (R 4.1.0)
#>    purrr         0.3.4   2020-04-17 [2] CRAN (R 4.1.0)
#>    R.cache       0.15.0  2021-04-30 [2] CRAN (R 4.1.0)
#>    R.methodsS3   1.8.1   2020-08-26 [2] CRAN (R 4.1.0)
#>    R.oo          1.24.0  2020-08-26 [2] CRAN (R 4.1.0)
#>    R.utils       2.11.0  2021-09-26 [1] CRAN (R 4.1.1)
#>    R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.1)
#>    raster        3.5-9   2021-12-10 [1] CRAN (R 4.1.2)
#>    Rcpp          1.0.7   2021-07-07 [1] CRAN (R 4.1.0)
#>    reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.1)
#>    rlang         0.4.12  2021-10-18 [1] CRAN (R 4.1.2)
#>    rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.1)
#>    rstudioapi    0.13    2020-11-12 [2] CRAN (R 4.1.0)
#>    s2            1.0.7   2021-09-28 [1] CRAN (R 4.1.1)
#>    sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 4.1.0)
#>    sf          * 1.0-4   2021-11-14 [1] CRAN (R 4.1.2)
#>    sp            1.4-5   2021-01-10 [2] CRAN (R 4.1.0)
#>    spData      * 2.0.1   2021-10-14 [1] CRAN (R 4.1.0)
#>    stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.2)
#>    stringr       1.4.0   2019-02-10 [2] CRAN (R 4.1.0)
#>    styler        1.6.2   2021-09-23 [1] CRAN (R 4.1.1)
#>    terra         1.4-22  2021-11-24 [1] CRAN (R 4.1.2)
#>    tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.2)
#>    tidyselect    1.1.1   2021-04-30 [2] CRAN (R 4.1.0)
#>    units         0.7-2   2021-06-08 [2] CRAN (R 4.1.0)
#>    utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
#>    vctrs         0.3.8   2021-04-29 [2] CRAN (R 4.1.0)
#>    withr         2.4.2   2021-04-18 [2] CRAN (R 4.1.0)
#>    wk            0.5.0   2021-07-13 [1] CRAN (R 4.1.0)
#>    xfun          0.29    2021-12-14 [1] CRAN (R 4.1.2)
#>    yaml          2.2.1   2020-02-01 [2] CRAN (R 4.1.0)
#> 
#> 
2

Just use the proj4 string

prj <- sf::st_crs("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 

rpoints <- st_sample(Kenya, size = 100, type = "random", crs = prj)
4
  • Isn't the WKT form preferred over PROJ4 strings?
    – Spacedman
    Dec 16, 2021 at 16:13
  • 2
    @Spacedman true but, this is a lazy approach. The sf::st_crs parses the PROJ4 string into a WKT format. If you look at the prj object it is in WKT. Dec 16, 2021 at 16:35
  • Thanks for the response Jeffrey. I only used that code as a simple example but it doesn't actually seem to make a difference to the data points when I try it prj <- sf::st_crs("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") Kenya <- world[world$name_long == "Kenya", 0] rpoints <- st_sample(Kenya, size = 100, type = "random", crs = prj) rpoints rpoints_2 <- st_sample(Kenya, size = 100, type = "random", crs = 4326) rpoints_2
    – adkane
    Dec 16, 2021 at 16:55
  • There are some projections that only have the WKT string but when I tried to substituted into a CRS object I get this error "Scale limits cannot be mapped onto spatial coordinates in coord_sf()." Aug 30, 2022 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.