I need to upload some rasters in .tif format to a geoserver that requires EPSG information to correctly display the data. When I assign an EPSG using crs() to a raster that is in memory, the WKT information reflects that EPSG code correctly. However, when I write that raster to disk and read it back into R to double check, the EPSG code is not preserved and the WKT information is different (though the crs is the same).
memoryCRS <- raster("wiltpoint.tif")
crs(memoryCRS) <- "EPSG:5070"
writeRaster(memoryCRS, "wiltpoint2.tif")
diskCRS <- raster("wiltpoint2.tif")
cat(wkt(memoryCRS))
#> PROJCRS["NAD83 / Conus Albers",
#> BASEGEOGCRS["NAD83",
#> DATUM["North American Datum 1983",
cat(wkt(diskCRS))
#> PROJCRS["unknown",
#> BASEGEOGCRS["unknown",
#> DATUM["North American Datum 1983",
all.equal(wkt(memoryCRS), wkt(diskCRS))
#> [1] "1 string mismatch"
identicalCRS(memoryCRS, diskCRS)
#> [1] TRUE
compareCRS(memoryCRS, diskCRS)
#> [1] TRUE
crs(memoryCRS) <- CRS("+init=epsg:5070"), see comments here https://gis.stackexchange.com/a/111227/14229" – Nick Nov 12 '20 at 18:19crs(memoryCRS) <- CRS('+init=epsg:5070')and it has the same issue. Same goes forproj4string(memoryCRS) <- '+init=epsg:5070'andprojection(memoryCRS) <- '+init=epsg:5070'– cjm23 Nov 12 '20 at 18:41