所以最初的问题是使用 raster 包中的 'crs' 函数设置 crs(我还没有使用新的 terra 包)。然后你需要重新投影到相同的crs中。下一步是重新采样栅格,使它们都具有相同的像元分辨率和大小。最后,您可以将它们放在堆栈中。我很着急,所以我没有很好地评论,但如果你有问题,请告诉我。最后一点是基岩文件。您需要先使用 QGIS 或其他程序对其进行地理配准。尝试找到与它相似的已知投影的地图。
library(raster)
ls = list.files(".",pattern ="tif")
ls = ls[-which(ls == "bedrock.tif")]
r = lapply(ls,raster)
names(r) = ls
wgs84 = "+proj=longlat +datum=WGS84 +no_defs"
ETRS = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs"
crs(r$wc2.1_2.5m_bio_1.tif) = wgs84
crs(r$wc2.1_2.5m_bio_12.tif) = wgs84
crs(r$wc2.1_2.5m_elev.tif) = wgs84
crs(r$SBPC1.tif) = ETRS
crs(r$SBPC2.tif) = ETRS
crs(r$SPPC1.tif) = ETRS
crs(r$SPPC2.tif) = ETRS
crs(r$U2018_CLC2018_V2020_20u1.tif) = ETRS
# aggregate for faster processing -- you'll want to change this, but my machine couldn't process it
ra <- lapply(r,aggregate,fact=10, fun=max)
# not all need to be reprojected - this is me being lazy
rp = lapply(ra,projectRaster, crs = ETRS)
# resample rasters to match
sapply(rp,area)
rpr = lapply(rp,resample, y = rp$SBPC1.tif)
sapply(rpr,area)
rs = stack(rpr)
plot(rs)