【问题标题】:R: How to create a raster of probabilities from multiple rastersR:如何从多个栅格创建概率栅格
【发布时间】:2021-03-16 16:39:40
【问题描述】:

在 R 中,我需要创建一个具有 概率raster 4 个栅格(与道路、斜坡、草丛和树木覆盖的距离)。对于其中的每一个,我都创建了一个公式来计算重量。不幸的是,我无法共享数据。下面的这个功能是我迄今为止尝试做的,但它还没有工作。它给出了错误:Non-numeric argument to mathematical function。有什么建议吗?

  probabilities_raster <- function(tc, gc, road, slp){
    
    # Create structure to hold data
    propxy_raster <- raster(ncol=100, nrow=100)
    ncell(propxy_raster)
    
    treecover <- (dnorm(tc, mean=0.7, sd=0.1))/(dnorm(0.7, mean=0.7, sd=0.1))  # not working
    
    grasscover <- (dnorm(gc, mean=0.3, sd=0.1))/(dnorm(0.3, mean=0.3, sd=0.1))  # not working
    
    road <- pnorm(-2+4*road)   # not working
    
    slope <- exp(-10*slp)  # this one works
    
    # Calculate weight
    weight <- treecover * grasscover * road * slope
    
    propxy_raster <- weight
    return(propxy_raster) 
  }
  
  raster_1 <- probabilities_raster(tc=raster_treecover, gc=raster_grasscover, road=raster_road, slp=
  raster_slope)

【问题讨论】:

    标签: r probability raster spatial weighted


    【解决方案1】:

    这是一个最小的、独立的可重现示例Minimal 也很重要,因为您的问题确实应该是: "如何将dnorm 与 RasterLayer 一起使用?"

    library(raster)
    tc <- raster() 
    values(tc) <- runif(ncell(tc))
    x <- dnorm(tc, mean=0.7, sd=0.1)
    #Error in dnorm(tc, mean = 0.7, sd = 0.1) : 
    #  Non-numeric argument to mathematical function
    

    我认为你正在寻找的是

    x <- calc(tc, function(i) dnorm(i, 0.7, 0.3))
    

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      相关资源
      最近更新 更多