【问题标题】:Modifying and Masking Environmental Layers within specific asia area in R在 R 中修改和屏蔽特定亚洲区域内的环境层
【发布时间】:2015-12-25 01:07:56
【问题描述】:

我正在尝试准备用于 Maxent 模型的环境层(仅限于特定的亚洲地区)。但是,我在最后一行遇到了一些错误消息:

library(sp)
library(maptools)
library(rworldmap)
library(dismo)
# A specified range of Asia area that suitable for special species
tsta <- read.csv('CM10_Kop_Shp_V1.2/Asiaclip/Asiaclipt.csv',as.is=TRUE)[https://drive.google.com/file/d/0B4vIx9MCfJgfbHpINTlyUGZVbXc/view?usp=sharing][1]
tsta <- tsta[,seq(1,4)]
coordinates(tsta) = c("Lon", "Lat")
gridded(tsta) <- TRUE
ra <- raster(tsta)

# a Rasterstack contains global range of 40 bioclim variables
files3 <- list.files(path=paste
                     ("CM10_1975H_Bio_ASCII_V1.2/CM10_1975H_Bio_V1.2"),
                     , pattern='txt',full.names=TRUE )[https://www.climond.org/Core/Authenticated/Data/CM10_V1.2/CM10_Bio_V1.2/CM10_Bio_ASCII_V1.2/CM10_1975H_Bio_ASCII_V1.2.zip][1]

predictors3 <- stack(files3)
asia.predictors3 <- mask(predictors3,ra)

compareRaster(x, mask) 中的错误:不同程度

predictors3 的详细信息是

predictors3
class       : RasterStack 
dimensions  : 857, 2160, 1851120, 40  (nrow, ncol, ncell, nlayers)
resolution  : 0.1666667, 0.1666667  (x, y)
extent      : -180, 180, -59.16667, 83.66667  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
names       : CM10_1975H_Bio01_V1.2, CM10_1975H_Bio02_V1.2, CM10_1975H_Bio03_V1.2, CM10_1975H_Bio04_V1.2, CM10_1975H_Bio05_V1.2, CM10_1975H_Bio06_V1.2, CM10_1975H_Bio07_V1.2, CM10_1975H_Bio08_V1.2, CM10_1975H_Bio09_V1.2, CM10_1975H_Bio10_V1.2, CM10_1975H_Bio11_V1.2, CM10_1975H_Bio12_V1.2, CM10_1975H_Bio13_V1.2, CM10_1975H_Bio14_V1.2, CM10_1975H_Bio15_V1.2, ... 

ra 的详细信息是:

ra
class       : RasterLayer 
dimensions  : 213, 290, 61770  (nrow, ncol, ncell)
resolution  : 0.1666667, 0.1666667  (x, y)
extent      : 97.5, 145.8333, 18.16667, 53.66667  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : Location 
values      : 168505, 377653  (min, max)

我的目标是准备一个 RasterLayer 或 Rasterstack 包含“predictors3”的所有变量,但限制在“ra”的范围内。如您所见,ra 的范围包含在预测变量的范围中3,并且它们的分辨率相同。我应该如何修复错误?

【问题讨论】:

  • 来自帮助页面:“遮罩可以是相同范围分辨率的另一个Raster*对象”。
  • 但是我仍然收到上面相同的错误错误。附加的 x snd 掩码之间的不同程度
  • 它们应该是相同的范围。他们目前不是。
  • 我添加了以下代码来识别范围:bb
  • 但仍然收到错误消息:警告消息:关闭未使用的连接 3 (C:/Users/user/AppData/Local/Temp/R_raster_user/2015-12-25_113604_6496_66889.gri)

标签: r mask layer maxent


【解决方案1】:

此时rapredictors3的原点和分辨率相同,可以使用crop

predictors3 <- raster(xmn=-180, xmx=180, ymn=-59.16667, ymx=83.66667, res=1/6)
ra <- raster(xmn=97.5, xmx=145.8333, ymn=18.16667, ymx=53.66667, res=1/6)

x <- crop(predictors3, ra)

在其他情况下,您可能需要使用 (dis)aggregateresample

【讨论】:

    【解决方案2】:

    根据上述建议,我裁剪了全球气候层“predictors3”以识别两个栅格的范围。然后,对最新的栅格进行掩码,获取特定区域内的定位变量。

    asia.predictors <- crop(predictors3,ra)
    asia.predictors3 <- mask(asia.predictors,ra)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多