在栅格图层上叠加(绘图)点数据

时间:2019-03-11 22:35:33

标签: r ascii raster

因此,我有以下脚本尝试准备数据,以便稍后使用“ biomod2”包对它们进行建模。它试图在环境层(bio1,bio7)上覆盖物种(xlm)存在点。

library(biomod2)
library(raster)

    data <- structure(list(longitude = c(-122.84,-119.418,-78.6569,-78.1834, -89.3985), latitude = c(45.28,36.7783,37.4316,-1.8312, 32.3547)), .Names = c("X_WGS84", 
"Y_WGS84"), class = "data.frame", row.names = c(NA, -5L))
data$xlm<-1

spdf <- SpatialPointsDataFrame(coords = xy, data = data,
                               proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))

myRespName <- 'xlm'
myResp <- as.numeric(data[,myRespName])
myRespXY <- data[,c('X_WGS84','Y_WGS84')]
myExpl = stack( system.file( "external/bioclim/current/bio3.grd", package="biomod2"),
system.file( "external/bioclim/current/bio4.grd", package="biomod2"))
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,expl.var = myExpl,resp.xy = myRespXY,resp.name = myRespName)
plot(myBiomodData)

在这种情况下它可以工作,但是问题是当我想用自己的数据替换程序包中的“ bio4.grd”和“ bio3.grd”层时,它不起作用。我已经尝试过如下。首先,我认为这可能是“ asci”文件格式,但是即使将它们转换为“ grd”,我仍然无法将要点叠加在堆叠的图层上。但是,它确实仅覆盖了美国南部(密西西比州路易斯安那州附近)的一个点。

library(biomod2)
library(raster) 

data <- structure(list(longitude = c(-122.84,-119.418,-78.6569,-78.1834, -89.3985), latitude = c(45.28,36.7783,37.4316,-1.8312, 32.3547)), .Names = c("X_WGS84", 
"Y_WGS84"), class = "data.frame", row.names = c(NA, -5L))
data$xylella<-1

spdf <- SpatialPointsDataFrame(coords = xy, data = data,
                               proj4string = CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))

myRespName <- 'xylella'

myResp <- as.numeric(data[,myRespName])

myRespXY <- data[,c('X_WGS84','Y_WGS84')]

bio2<-raster("C:\\Data\\BioClim_V2_MaxEnt\\wc2.0_bio_10m_02.asc")
crs(bio2) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
writeRaster(bio2, "C:\\Data\\BioClim_V2_MaxEnt\\bio2", overwrite=TRUE)

bio7<-raster("C:\\Data\\BioClim_V2_MaxEnt\\wc2.0_bio_10m_07.asc")
crs(bio7) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
writeRaster(bio7, "C:\\Data\\BioClim_V2_MaxEnt\\bio7", overwrite=TRUE)

myExpl = stack (bio2,bio7)

myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,expl.var = myExpl,resp.xy = myRespXY,resp.name = myRespName)

plot(myBiomodData)

任何帮助,我们将不胜感激。非常感谢。

0 个答案:

没有答案