【问题标题】:R - transition function for modelling surface water flow with gdistanceR - 用 gdistance 模拟地表水流的过渡函数
【发布时间】:2019-05-01 23:57:01
【问题描述】:

我正在尝试使用 gdistance shortestPath 函数对从指定原点到单个下坡目标点的陆上(地表)水流进行建模。我需要帮助来为此定义适当的transitionFunction,因为我需要确保成本最低的路径只允许水沿着路径流向与前一个单元格相等或更低值的高程单元格。下例中的transitionFunction 选择了最小高程单元格,但根据我定义的transitionFunction,此值可能仍大于之前的单元格值。

我意识到,当上述定义为我想要的时,路径可能会在到达目标点之前终止。这很好,尽管我希望能够尽可能保留从起点到终点的路径。

另外,如果有人知道能够对此类事物进行建模的不同 R 包,请告诉我。

library(gdistance)
library(raster)
library(elevatr)
library(sp)

#load example DEM raster
data(lake)
elevation <- get_elev_raster(lake, z = 9)
#remove negative elevation values from raster
elevation[elevation < 0] <- NA

#create origin and goal points with same projection as elevation raster
origin <- SpatialPoints(cbind(1790000, 640000), proj4string = CRS("+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"))
goal <- SpatialPoints(cbind(1820000, 540000), proj4string = CRS("+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"))

#create df data and convert to SpatialPointsDataFrame
odf <- data.frame("flowreg" = 1)
gdf <- data.frame("flowreg" = 2)
origindf <- SpatialPointsDataFrame(origin, odf)
goaldf <- SpatialPointsDataFrame(goal, gdf)
trCost1 <- transition(elevation, transitionFunction=function(x) 1/min(x), directions=8)
trCost1gc <- geoCorrection(trCost1, type="c")

plot(raster(trCost1))   
sPath1 <- shortestPath(trCost1, origin, goal, 
output="SpatialLines")

plot(elevation)
plot(origindf, add = TRUE, col='red', cex = 5)
plot(goaldf, add = TRUE, col='green', cex = 5)
lines(sPath1)

【问题讨论】:

  • 您当前的代码是否没有保留从起点到终点的路径?从你的身材我看不出来。
  • 当前代码保留路径,是的。问题是 transitionFunction 允许路径“上坡”流动(即,到比中心单元更高的单元)。我想让路径流动,因为地表水会向下坡流动。如果您有任何想法,请告诉我。

标签: r geospatial spatial r-raster sp


【解决方案1】:

我找到了 GRASS GIS(在 R 中使用 rgrass7 访问)r.drain 函数或 raster::flowPath 实现了我在上述问题中尝试做的事情。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多