-1
我正在嘗試從列中包含物種名稱,經度和緯度的矩陣創建柵格圖層。創建柵格圖層
的數據名稱是「基地」,當我嘗試使用的base
用命令的範圍內創建rasterlayer
r<-raster(base)
我得到一個錯誤:
Error en .local(x, ...) : list has no "x"
你願意幫我?謝謝
我正在嘗試從列中包含物種名稱,經度和緯度的矩陣創建柵格圖層。創建柵格圖層
的數據名稱是「基地」,當我嘗試使用的base
用命令的範圍內創建rasterlayer
r<-raster(base)
我得到一個錯誤:
Error en .local(x, ...) : list has no "x"
你願意幫我?謝謝
你不會給我們太多的東西,但你可能想嘗試一下(下面的例子ASSUMES你的座標數據是使用WGS84數據的lat-long格式的。如果它不是在2-d空間的點表示會出錯,所以請儘量找你的投影信息...
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
有機會的話,你的「基地」是一個數據幀。使用'as.matrix(基地)'可能會解決問題。 – Azim 2018-02-04 17:19:54