TransWikia.com

writeRaster() not preserving EPSG information

Geographic Information Systems Asked by cjm23 on May 20, 2021

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

One Answer

Try using capitals for epsg: crs(memoryCRS) <- CRS("+init=EPSG:5070") instead of crs(memoryCRS) <- CRS("+init=epsg:5070")

Answered by TVolt on May 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP