2013-03-14 4 views
-1

종의 이름, 위도 및 위도가 열에 들어있는 행렬에서 래스터 레이어를 만들려고합니다.RasterLayer 만들기

데이터 이름은 "기본"입니다, 내가 명령으로 base의 범위와 rasterlayer을 만들려고 할 때

r<-raster(base) 

나는 오류 얻을 :

Error en .local(x, ...) : list has no "x" 

당신이 도움이 될를 나를? 감사합니다

+0

'기준'이 데이터 프레임 일 가능성이 있습니다. 'as.matrix)'문제를 해결할 수 있습니다. – Azim

답변

2

우리에게 많은 것을주지는 않지만 이것을 시도하고 싶을 수도 있습니다 (아래 예 :) 좌표 데이터가 WGS84 데이터를 사용하여 위도 - 길이 형식으로되어 있다고 가정합니다. 2 차원 공간에서 점의 표현이 잘못 될 수 있으므로 투영 정보를 찾으십시오.

require(sp) 
require(raster) 
require(maptools) 


#Some dummy data in the format you have described 
base <- data.frame(longitude = sample(c(-20:20) , 10) , latitude = sample(c(-30:30) , 10) , species = sample(letters[1:3] , 10 , repl = TRUE)) 
head(base) 
#  longitude latitude species 
# 1  -10  7  a 
# 2   3  14  b 
# 3  -9  29  b 
# 4  -8  -25  a 
# 5   0  -19  b 
# 6  -19  19  c 

#Make spatial points dataframe, which will have a spatial extent 
spdf <- SpatialPointsDataFrame(base[ c("longitude" , "latitude") ] , data = data.frame(base$species) , proj4string = CRS("+proj=longlat +datum=WGS84")) 

#make raster based on the extent of your data 
r <- raster(extent(spdf)) 
r 
# class  : RasterLayer 
# dimensions : 10, 10, 100 (nrow, ncol, ncell) 
# resolution : 3.3, 5.8 (x, y) 
# extent  : -20, 13, -29, 29 (xmin, xmax, ymin, ymax) 
# coord. ref. : NA 
# values  : none