我想在目录中对栅格进行采样,然后移至新目录(ngrok http --host-header=rewrite 50452
),并使用未采样的栅格(train
)创建另一个栅格。
为此,我做了:
test1
我必须解决问题,首先,我的library(raster)
# Example data
r <- raster(ncol=10, nrow=10)
# 10 layers
s <- stack(lapply(1:10, function(i) setValues(r, runif(ncell(r)))))
#Create GeoTIFF for each layer
sl<-1:10
for (i in 1:length(sl)){
writeRaster(s[[i]],filename=paste(sl[i],sep=""),
format="GTiff",datatype="FLT4S",overwrite=TRUE)
}
#Imagens crete in batch
f <- list.files(getwd(), pattern = ".tif")
ras <- lapply(f,raster)
#Sample 80% of images for calibration
rasS<-sample(ras,round(length(ras)*0.8,digits=0))
dir.create("train")
file.copy(list.files(rasS),"train")
Error in list.files(rasS) : invalid 'path' argument
#Not sample images - 20%
rasT<- ras[ras!=rasS]
Error in ras != rasS : comparison of these types is not implemented
In addition: Warning message:
In ras != rasS :
longer object length is not a multiple of shorter object length
dir.create("test1")
file.copy(list.files(rasT),"train")
列表是无效的'path'参数,而!=参数对于未采样栅格选择无效。任何想法,请!
答案 0 :(得分:1)
您的问题在这里file.copy(list.files(rasS),"train")
。 rasS列表对象不是目录,无法传递到list.files
。您还试图不正确地采样和索引。
尝试类似的东西:
( sidx <- sample(1:length(ras), round(length(ras)*0.8,digits=0)) )
( rasS <- ras[sidx] )
( rasT <- ras[-sidx] )
dir.create("train")
lapply(rasS, FUN=function(x) {
writeRaster(x, file.path(getwd(),"train", paste0(names(x), ".tif")), )
})