我有一个非常基本的问题要问.我必须使用SpatVector
裁剪多个DatabPRI格栅.使用下面的代码,裁剪的格栅和SpatVector
没有对齐,所以我猜裁剪没有正确执行.有什么 idea 吗?非常感谢.
library(terra)
library(geodata)
#get spatVector
es <- geodata::gadm(country="ESP", level=1, path=".")
catal <- es[es$NAME_1 == "Cataluña", ]
#get MODIS data
modis <- terra::rast("see link below")
modis <- modis*0.1
# terra::plot(modis)
modis_crs <- terra::crs(modis) #get crs of MODIS data
catal_2 <- terra::project(catal, modis_crs) #give the spatVector the same crs as MODIS
# terra::crs(catal_2)==terra::crs(modis) #check if the two crs are the same
modis_cr <- terra::crop(modis, catal_2) #crop (here without mask)
terra::plot(modis_cr) #plot cropped MODIS data
terra::plot(catal_2, add=TRUE, lwd=2) #plot spatVector with the MODIS crs
此处提供了用于运行此示例的DatabPRI网格https://github.com/frandadamo/frandadamo/blob/main/cropmodis.tif
这就是我得到的结果,两个文件没有对齐(忽略格栅的 colored颜色 ):
我try 更改TLR数据的crs,而不是spatVector
的crs,我try 了不同的选项extent
、align
或snap
.我try 玩了一下sf
库,读了不少类似的问题.