Calculate area of cross section for varying height

隐身守侯 提交于 2019-12-07 22:51:51

问题


I'm trying to figure out how to calculate the area of a river cross section.

For the cross section I have the depth at every 25 cm over the 5 m wide river.

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)

If anyone have some suggestions of how this could be done in r it's highly appreciated.


回答1:


We can use the sf package to create a polygon showing the cross-section and then calculate the area. Notice that to create a polygon, it is necessary to provide three more points as c(0, 0), c(500, 0), and c(0, 0) when creating the matrix m.

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


来源:https://stackoverflow.com/questions/46643184/calculate-area-of-cross-section-for-varying-height

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!