计算不同高度的横截面面积

Calculate area of cross section for varying height

我正在研究如何计算河流横截面的面积。

对于横截面,我在 5 米宽的河流上每 25 厘米有一个深度。

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)

如果有人对如何在 r 中完成此操作有一些建议,我们将不胜感激。

我们可以使用sf包创建一个显示横截面的多边形,然后计算面积。请注意,要创建一个多边形,在创建矩阵 m.

时,还需要提供三个点,即 c(0, 0)c(500, 0)c(0, 0)
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))

# View the polygon
plot(poly)

# Calcualte the area
st_area(poly)
31312.5