【问题标题】:Calculate area of cross-section as function of height计算横截面面积作为高度的函数
【发布时间】:2018-03-20 21:14:29
【问题描述】:

我试图弄清楚如何计算不同水位的河流横截面的充水面积。

对于横截面,我在 5 m 宽的河流上每 25 cm 有一个深度,并且可以根据一个很好回答的上一个问题来计算面积 Calculate area of cross section for varying height

x_profile <- seq(0, 500, 25)
y_profile <- c(50, 73, 64, 59, 60, 64, 82, 78, 79, 76, 72, 
           68, 63, 65, 62, 61, 56, 50, 44, 39, 25)

library(sf)

#Create matrix with coordinates
m <- matrix(c(0, x_profile, 500, 0, 0, -y_profile, 0, 0),
        byrow = FALSE, ncol = 2)

#Create a polygon
poly <- st_polygon(list(m))

# Calcualte the area
st_area(poly)

但是这个横截面只是部分充满了水,我现在尝试计算的是充满水的横截面。

水从最深处开始充满横截面,然后深度会发生变化,例如:

water_level<-c(40, 38, 25, 33, 40, 42, 50, 39)

有人对如何在 r 中完成此操作有任何想法吗?提前致谢。

【问题讨论】:

  • 您的water_level 值是否与y_profile 相同?我认为您只需要找到 y_profilewater_level 之间的差异,但如果您没有相同数量的值,这将很难做到。
  • 所以 water_level 是 40 那么这是水位 Y 轴值 max(y_profile) - 40 = 42?
  • 一种方法是在水位上构建一个矩形,包围剖面并使用st_intersection与剖面相交。
  • 请注意,有关 R 中 GIS 操作的问题可能在 gis.stackexchange.com 上做得更好
  • @shea 水位只在横截面剖面的最深处测量,就像 Spacedman 描述的 water_level 40 代表水位 Y 轴值 max(y_profile)。非常感谢!下次我会注意的!

标签: r area integral


【解决方案1】:

此函数计算轮廓与距离轮廓底部指定深度处的线的交点。它有点多余,因为它还需要 x 和 y 配置文件值,理论上可以从 profile 中提取:

filler <- function(depth, profile, xprof, yprof, xdelta=100, ydelta=100){
    d = -(max(yprof))+depth
    xr = range(xprof)
    yr = range(-yprof)
    xdelta = 100
    xc = xr[c(1,2,2,1,1)] + c(-xdelta, xdelta, xdelta, -xdelta, -xdelta)
    yc = c(d, d, min(yr)-ydelta, min(yr)-ydelta, d)
    water = st_polygon(list(cbind(xc,yc)))
    st_intersection(profile, water)
}

所以在使用中:

> plot(poly)
> plot(filler(40, poly, x_profile, y_profile), add=TRUE, col="green")
> plot(filler(30, poly, x_profile, y_profile), add=TRUE, col="red")
> plot(filler(15, poly, x_profile, y_profile), add=TRUE, col="blue")

请注意,第一个绿色区域被较浅的区域略微覆盖。还要注意蓝色区域是如何分成两个部分的。你可以用st_area得到横截面,在零深度处面积为零:

 > st_area(filler(20, poly, x_profile, y_profile))
[1] 2450.761
> st_area(filler(2, poly, x_profile, y_profile))
[1] 15.27778
> st_area(filler(0, poly, x_profile, y_profile))
[1] 0

不确定如果您超出个人资料顶部会发生什么...

【讨论】:

  • 非常感谢您的回答!效果很好!
猜你喜欢
  • 2018-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-09
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
相关资源
最近更新 更多