2

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

JRR
  • 9,389
  • 1
  • 13
  • 28
cjm23
  • 21
  • 2
  • 1
    Have you tried the proj4string rather than the EPSG code? – Jeffrey Evans Nov 12 '20 at 18:19
  • Try crs(memoryCRS) <- CRS("+init=epsg:5070"), see comments here https://gis.stackexchange.com/a/111227/14229" – Nick Nov 12 '20 at 18:19
  • 1
    Unfortunately, I have tried crs(memoryCRS) <- CRS('+init=epsg:5070') and it has the same issue. Same goes for proj4string(memoryCRS) <- '+init=epsg:5070' and projection(memoryCRS) <- '+init=epsg:5070' – cjm23 Nov 12 '20 at 18:41
  • 1
    I would like to better understand this problem. Why must the server have EPSG code? (that would be odd, as there is an infinite number of coordinate reference systems; and a finite number of EPSG codes); and how should it be stored? – Robert Hijmans Nov 19 '20 at 06:20
  • My understanding is that the GeoServer can't register a layer without a clearly identifiable EPSG code and matching WKT and that the same proj string can correspond to more than one EPSG codes. In the example above, the difference in that first line: PROJCRS["NAD83 / Conus Albers", and PROJCRS["unknown", is why the GeoServer is not correctly recognizing the raster. – cjm23 Nov 20 '20 at 16:25

1 Answers1

1

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

TVolt
  • 21
  • 2