Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.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
如何在R中对空间点数据帧进行子采样_R_Random Forest_Subsampling - Fatal编程技术网

如何在R中对空间点数据帧进行子采样

如何在R中对空间点数据帧进行子采样,r,random-forest,subsampling,R,Random Forest,Subsampling,我正在经营森林。我导入了表示已使用和未使用场地的点数据,并从光栅GIS图层创建了光栅堆栈。我已经创建了一个SpatialPointDataFrame,其中包含所有已使用和未使用的点及其基础光栅值 require(sp) require(rgdal) require(raster) #my raster stack xvariables <- stack(rlist) #rlist = a list of raster layers # Reading in the spatia

我正在经营森林。我导入了表示已使用和未使用场地的点数据,并从光栅GIS图层创建了光栅堆栈。我已经创建了一个SpatialPointDataFrame,其中包含所有已使用和未使用的点及其基础光栅值

require(sp)
require(rgdal)
require(raster)

#my raster stack
xvariables <- stack(rlist)  #rlist = a list of raster layers   

# Reading in the spatial used and unused points.
ldata <- readOGR(dsn=paste(path, "DATA", sep="/"), layer=used_avail)
str(Ldata@data)


#Attach raster values to point data.
v <- as.data.frame(extract(xvariables, ldata))
ldata@data = data.frame(ldata@data, v[match(rownames(ldata@data), rownames(v)),])
require(sp)
需要(rgdal)
需要(光栅)
#我的光栅堆栈

xvariables对空间*数据帧对象进行子集设置相当简单;只用

spSubset <- spObject[<sample_criterion>,]

spSubset通过注释来处理这一问题不太可能有成效。为了重现您的问题,我需要
rlist
数据
形状文件。请记住,“shapefile”实际上是一组文件(因此,DATA.dbf、DATA.prj、DATA.shp等),能否将这些文件上传到某个地方并提供链接?
library(rgdal)
set.seed(1)
# random sample of NJ colleges...
sampleSize=20
spPoints <- readOGR(dsn=".",layer="NJ_College_Univ_NAD83njsp")
spSample <- spPoints[sample(1:length(spPoints),sampleSize),]

# extract NJ from US States TIGER/Line file
states   <- readOGR(dsn=".",layer="tl_2013_us_state")
NJ       <- states[states$NAME=="New Jersey",]
NJ       <- spTransform(NJ,CRS=CRS(proj4string(spSample)))

# render the map
NJ.df    <- fortify(NJ)
library(ggplot2)
ggplot() +
  geom_path(data=NJ.df, aes(x=long,y=lat, group=group))+
  geom_point(data=as.data.frame(coordinates(spPoints)), 
             aes(x=coords.x1,y=coords.x2),colour="blue", size=3)+
  geom_point(data=as.data.frame(coordinates(spSample)), 
             aes(x=coords.x1,y=coords.x2),colour="red", size=3)+
  coord_fixed() + labs(x="", y="") + theme(axis.text=element_blank())