5

I am using sf package version 0.9-6. I define a new object in ESRI:4326 and then try to reproject it to an Albers projection. I get an error, despite explicitly setting the crs when defining the object.

Here is MWE.

library(sf)
# Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
disp_win_wgs84 <- sf::st_sf(st_sfc(st_point(c(-97.2, 32.55)),
                         st_point(c(-85.55, 49.2)),
                         crs = 4326))
target_crs <- 102003
disp_win_trans <- sf::st_transform(disp_win_wgs84, crs = target_crs)

I get the following error:

Error in CPL_transform(x, crs, aoi, pipeline, reverse) : 
  crs not found: is it missing?
In addition: Warning message:
In CPL_crs_from_input(x) :
  GDAL Error 1: PROJ: proj_create_from_database: crs not found

Edit: updated to define the target_crs as a number. Apparently, this is what was causing the error (see the answer). The solution is to use target_crs <- "ESRI:102003", this does not raise an error.

1 Answer 1

6

What exactly is in target_crs? For example, using the USA Contiguous Albers Equal Area Conic ESRI projection (ESRI:102003), your code performs flawlessly:

disp_win_trans = sf::st_transform(
  disp_win_wgs84
  , crs = "ESRI:102003"
)

disp_win_trans
# Simple feature collection with 2 features and 0 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: -112073.8 ymin: -552988 xmax: 770239.1 ymax: 1345785
# projected CRS:  USA_Contiguous_Albers_Equal_Area_Conic
# st_sfc.st_point.c..97.2..32.55....st_point.c..85.55..49.2....
# 1                                     POINT (-112073.8 -552988)
# 2                                      POINT (770239.1 1345785)
2
  • I am sorry I was sloppy and did not notice that target_crs is not defined in MWE. I updated the question, and your solution (to define it as a string rather than a number) resolved the issue.
    – roussanoff
    Feb 12, 2021 at 14:52
  • Thanks for updating, it's much more transparent now. Glad to help.
    – fdetsch
    Feb 12, 2021 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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