Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用raster::extract using buffer创建一个数据框,其中包含raster::extract中的属性信息_R_Raster_R Raster - Fatal编程技术网

使用raster::extract using buffer创建一个数据框,其中包含raster::extract中的属性信息

使用raster::extract using buffer创建一个数据框,其中包含raster::extract中的属性信息,r,raster,r-raster,R,Raster,R Raster,我有以下情况: library(spatstat) library(raster) #Create a SpatialPointsDataFrame pts <- rpoispp(60) ## Coordinates status<-rep(c("control","treat"),15) d<-data.frame(pts$x[1:30],pts$y[1:30],status) colnames(d)<-c("x","y","status") pts.sampling

我有以下情况:

library(spatstat)
library(raster)

#Create a SpatialPointsDataFrame
pts <- rpoispp(60) ## Coordinates
status<-rep(c("control","treat"),15)
d<-data.frame(pts$x[1:30],pts$y[1:30],status)
colnames(d)<-c("x","y","status")
pts.sampling = SpatialPoints(cbind(pts$x[1:30],pts$y[1:30]), proj4string=CRS("+proj=utm +zone=22 +south +datum=WGS84 +units=m +no_defs"))
df.pts.SPDF<- SpatialPointsDataFrame(pts.sampling, data = d)

#Create some rasters
r <- raster(ncol=10, nrow=10)
s <- stack(lapply(1:4, function(i) setValues(r, runif(ncell(r)))))

## Extract raster values in 6 distance around (buffer) and organize the results 
res<- data.frame(coordinates(pts.sampling),
                   df.pts.SPDF,
                   extract(s, df.pts.SPDF,buffer=6))

#Error in data.frame(coordinates(pts.sampling), df.pts.SPDF, extract(s,  : 
#  arguments imply differing number of rows: 30, 8
库(spatstat)
图书馆(光栅)
#创建空间点数据帧

pts我不确定我是否得到了你想要做的事情,因为你肯定需要提出更好的解释,但这是你想要的吗

## Extract raster values in 6 distance around (buffer) and organize the results 
x <- extract(s, df.pts.SPDF,buffer=6)
res<- data.frame(coordinates(pts.sampling),
                 df.pts.SPDF,
                 do.call("rbind", x))

> head(res)
#  coords.x1 coords.x2         x         y  status coords.x1.1 coords.x2.1 optional   layer.1   layer.2   layer.3   layer.4
#1 0.8824756 0.1675364 0.8824756 0.1675364 control   0.8824756   0.1675364     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
#2 0.3197404 0.6779792 0.3197404 0.6779792   treat   0.3197404   0.6779792     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
#3 0.1542464 0.5778322 0.1542464 0.5778322 control   0.1542464   0.5778322     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
#4 0.6299502 0.3118177 0.6299502 0.3118177   treat   0.6299502   0.3118177     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
#5 0.4714429 0.1400559 0.4714429 0.1400559 control   0.4714429   0.1400559     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
#6 0.4568768 0.6155193 0.4568768 0.6155193   treat   0.4568768   0.6155193     TRUE 0.2979335 0.8745829 0.4586767 0.4631793
##提取周围6个距离(缓冲区)的光栅值并组织结果
x