2013-06-28 41 views
0

我有8個環境變量的raster.stack和生態區域爲美國南部提取值

files<-list.files(path='E:/Ecoregions Models/Border Bioclim/',pattern='asc', full.names=TRUE) 
predictors<-stack(files) 

##subset the main shape file into 12 individual shapefiles for the regions of interest 
ER_11.1<-Level.2.ecoregs[Level.2.ecoregs$NA_L2CODE=="11.1",]... 

我試圖使用extract功能拔出5000隨機shape文件指出每個生態區域並將它們保存爲不同的對象。

我無法將單個ecoregion對象投影到柵格文件上。 我已經改變了投影,但仍然存在問題。

>bio_1 
class  : RasterLayer 
dimensions : 324, 444, 143856 (nrow, ncol, ncell) 
resolution : 0.08333333, 0.08333333 (x, y) 
extent  : -125, -88, 18.5, 45.5 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=48 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : E:\Ecoregions Models\Border Bioclim\ModelVariables\bio_1.asc 
names  : bio_1 

> ER_11.1 
class  : SpatialPolygonsDataFrame 
nfeatures : 22 
extent  : -1989641, -1450736, -1748693, -208349.6 (xmin, xmax, ymin, ymax) 
coord. ref. : +proj=utm +zone=48 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
nvariables : 8 
names  : NA_L2CODE,    NA_L2NAME, NA_L1CODE,    NA_L1NAME,      NA_L2KEY,      NA_L1KEY, Shape_Leng, Shape_Area 
min values :  11.1, MEDITERRANEAN CALIFORNIA,  11, MEDITERRANEAN CALIFORNIA, 11.1 MEDITERRANEAN CALIFORNIA, 11 MEDITERRANEAN CALIFORNIA,  331.1174, 1.483274e+08 
max values :  11.1, MEDITERRANEAN CALIFORNIA,  11, MEDITERRANEAN CALIFORNIA, 11.1 MEDITERRANEAN CALIFORNIA, 11 MEDITERRANEAN CALIFORNIA, 5417939.1114, 8.472524e+04 
> 

這裏的問題必須在不同程度上。 有沒有人對如何在光柵包中解決這個問題有任何建議?

回答

1

的CRS爲bio_1顯然是錯誤的,你必須

resolution : 0.08333333, 0.08333333 (x, y) 
extent  : -125, -88, 18.5, 45.5 (xmin, xmax, ymin, ymax) 

也就是說,經度/緯度的大部分美國的座標,但使用的是

coord. ref. : +proj=utm +zone=48 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 

可能是因爲你改變了投影名稱,而你想轉換(項目)的數據?這裏是你可以做什麼:

恢復bio_1的CRS其原始值(我相信)

projection(bio_1) <- "+proj=longlat +datum=WGS84" 

變換多邊形到同一CRS

library(rgdal) 
ER <- spTransform(ER_11.1, CRS(projection(bio_1))) 

而現在提取值:

v <- extract(bio_1, ER)