I am trying to switch away from rgdal and PROJ4 since both are deprecated. I try to assign a coordinate reference system using sf but continue to get an error about the crs still being PROJ4.
pacman::p_load(sf, raster)
cell.coords <- data.frame(lon = rep(c(2, 3), 2), lat =
rep(c(1, 2), each = 2), cell.id = 10:13)
blank.grid <- st_as_sf(rasterToPolygons(rasterFromXYZ(
cell.coords[ , c("lon", "lat", "cell.id")])))
# Try, in turn, each of the following.
# First three successfully show the crs when blank.grid is called,
# but crs(blank.grid) includes "Deprecated Proj.4 representation"
wgs84 <- 4326
# next is based on https://gis.stackexchange.com/questions/372692/how-should-i-handle-crs-properly-after-the-major-change-in-proj-library
wgs84 <- "OGC:CRS84"
# next is based on https://gis.stackexchange.com/questions/385114/how-to-update-crs-r-object-from-proj4-to-proj6
wgs84 <- "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=WGS84 +units=m +no_defs"
# For the rest, blank.grid returns CRS: NA
wgs84 <- "4326+datum=WGS84"
wgs84 <- "+init=epsg:4326+datum=WGS84"
wgs84 <- "EPSG:4326"
# Apply and check each option with
st_crs(blank.grid) <- wgs84
blank.grid
crs(blank.grid)
I realize we are referred (https://gis.stackexchange.com/questions/372692/how-should-i-handle-crs-properly-after-the-major-change-in-proj-library) to the technical references https://cran.r-project.org/web/packages/rgdal/vignettes/CRS_projections_transformations.html and/or http://rgdal.r-forge.r-project.org/articles/PROJ6_GDAL3.html. Both are long documents I don’t understand, and involve a level of detail I hope is not required for using simple rasters.
An optimal solution would be a single command to create blank.grid, with crs as an argument. Using terra rather than raster would be best, since I think I read that raster is likewise not long for this world.