繁体   English   中英

遍历R中的增量栅格值以创建新的栅格数据集

[英]Iterate through Incremental Raster Values in R to Create New Raster Datasets

抱歉,是否曾经有人问过这个问题,但我找不到解决我问题的方法,我认为这是一个相当简单的问题。 我有一个单一的源栅格数据集,其中包含100到500之间的连续浮动值。我想做的是以50的增量循环遍历此源栅格,以导出/创建所有小于该增量的值的新栅格数据集。 例如,我有以下R代码(使用栅格库)来指定栅格并标识增量。 我将开发一种方法来自动创建9个小于或等于每个增量值的输出栅格数据集。 我似乎无法到达那里。 有人可以帮忙吗? TIA!

#Trying to iteratively create new raster datasets 
#Based on increments of Source Raster

library(raster)

setwd("C:/Path/To/Folder")

r=raster("Source_Raster.tif") #Raster is floating between 100 and 500

#Create a list of increments I would like to use
list <-seq(100, 500, 50)
#The list creates the following sequence:
# 100 150 200 250 300 350 400 450 500

###THIS IS WHERE I STRUGGLE####
# I would like to use the sequence to create
# new raster datasets that only include values
# from the source raster that are less than or equal to each increment

# for example, the first output raster will contain values less than 
# or equal to the first increment (100)

r100 <- calc(r, fun=function(x){ x[x > 100] <- NA; return(x)} )

确定断点后,我们可以使用lapply函数创建每个栅格图层。 在此示例中, r_list是具有9个栅格图层的最终输出。

library(raster)

set.seed(145)

# Create example raster
r <- raster(matrix(runif(100, min = 100, max = 500), ncol = 10))

# Create break points
brk <-seq(100, 500, 50)

# Conduct the operation, create nine raster than smaller than each break points
r_list <- lapply(brk, function(x){ 
  temp <- r
  temp[temp > x] <- NA 
  return(temp)
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM