![](/img/trans.png)
[英]Joining tables to a raster attribute table to create new raster with the reclassified values python or 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.