2015-12-25 12 views
1

我正在準備在Maxent模型中使用的環境層(受特定亞洲地區限制)。然而,我遇到一些錯誤消息中的最後一行:在R的特定亞洲地區內修改和掩蓋環境層

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,掩模):不同程度

細節對於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,並且它們的分辨率是相同的。我應該如何解決這個錯誤?

+0

從幫助頁面:「面具可以是另一個光柵* **的相同程度的對象**和** **的決議」。 –

+0

但我仍然收到上面同樣的錯誤錯誤。不同的exents之間連接的xsnd掩碼 –

+0

它們應該是相同的**程度。他們目前不是。 –

回答

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) 

在其他情況下,你可能需要使用(disaggregateresample

0

根據上述建議,我裁剪全球氣候層「預測者3」以確定兩個柵格的範圍。然後,屏蔽最新的柵格以獲取限制在特定區域的目標變量。

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