R 在运行 terra::resample() 函数时崩溃

问题描述 投票:0回答:1

以下代码用于利用不同土地覆盖类别的知识来制作位置地图

library(terra)

WD_AOI<-("POLYGON")
WD_LU<-("Land_cover")
WD_SOC<-("SOC_MAP")
# Open the shapefile of the region/country
setwd(WD_AOI)
AOI<-vect("study_area.shp")
# Open Land Use Layer (ESA)
setwd(WD_LU)
ESA_LU<-rast("Land_Cover_2.tif")
plot(ESA_LU)
# Cut the LU layer by the country polygon
ESA_LU_AOI<-crop(ESA_LU,AOI)
plot(ESA_LU_AOI)
# Reclassify ESA LAND USE to FAO LAND USE classes
#     0 = 0   No Data
#   190 = 1 Artificial
#   10 11 20 30 40 = 2 Croplands
#   130 = 3 Grassland
#   50 60 61 62 70 71 72 80 81 82 90 100 110 = 4 Tree Covered
#   120 121 122= 5 Shrubs Covered
#   160 180 = 6 Herbaceous vegetation flooded
#   170 = 7 Mangroves
#   150 151 152 153= 8 Sparse Vegetation
#   200 201 202 = 9 Baresoil
#   220 = 10 Snow and Glaciers
#   210 = 11 Waterbodies
#   12 = 12 Treecrops
#   20 = 13 Paddy fields(rice/ flooded crops)
# Reclassify matrix. "Is" to "become"
is<-c(0,190,10,11,20,30,40,130,50,60,61,62,70,71,72,80,81,82,90,100,110,120,121,122,160,180,170,150,151,152,153,200,201,202,220,210,12)
become<-c(0,1,2,2,2,2,2,3,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,6,6,7,8,8,8,8,9,9,9,10,11,12)
recMat<-matrix(c(is,become),ncol=2,nrow=37)
# Reclassify
ESA_FAO <- classify(ESA_LU_AOI, recMat)
#Resample to SOC map layer extent and resolution
setwd(WD_SOC)
SOC_MAP_AOI<-rast(c("SOC_MAP_AOI.tif"))
ESA_FAO_res<-resample(ESA_FAO,SOC_MAP_AOI, method='near)

当我运行最后一行代码时,就会发生以下崩溃(所有文件都不超过半兆字节,因此据我所知,大小不应该是问题):

我尝试查看其他报告,例如以下内容:https://github.com/rspatial/terra/issues/32 到现在为止。

r crash gis
1个回答
0
投票

我想知道是否是因为您更改了工作目录。是这样操作的吗

library(terra)
AOI <- vect("POLYGON/study_area.shp")
ESA_LU <- rast("Land_cover/Land_Cover_2.tif")
ESA_LU_AOI<-crop(ESA_LU,AOI)
is <- c(0,190,10,11,20,30,40,130,50,60,61,62,70,71,72,80,81,82,90,100,110,120,121,122,160,180,170,150,151,152,153,200,201,202,220,210,12)
become <- c(0,1,2,2,2,2,2,3,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,6,6,7,8,8,8,8,9,9,9,10,11,12)
recMat <- cbind(is, become)
ESA_FAO <- classify(ESA_LU_AOI, recMat)
SOC_MAP_AOI <- rast(c("SOC_MAP/SOC_MAP_AOI.tif"))
ESA_FAO_res <- resample(ESA_FAO, SOC_MAP_AOI, method='near)
© www.soinside.com 2019 - 2024. All rights reserved.