2017-10-09 82 views
2

我想弄清楚如何計算不同水位的河流橫截面積水面積。根據高度計算橫截面面積

對於橫截面我有充分25釐米在寬5米的河流和在深度的區域可以基於一個很好的回答以前的問題 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中做任何想法?提前致謝。

+0

你有相同「水位」值的數量爲「y_profile」?我認爲你只需要找出'y_profile'和'water_level'之間的差異,但是如果你沒有相同數量的值,這將很難做到。 – shea

+0

因此,對於'water_level'是40,那麼這是一個水平的Y軸值'max(y_profile) - 40' = 42? – Spacedman

+1

做到這一點的一種方法是在水平面上構建一個矩形,該矩形包圍輪廓並與使用'st_intersection'的輪廓相交。 – Spacedman

回答

5

該函數計算剖面與距剖面底部指定深度處的直線的交點。它略顯多餘,因爲它也需要在理論上可以從profile提取x和y的配置文件值:

使用
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") 

depths

注意第一綠色區域被較不深的區域稍微覆蓋。還要注意藍色區域分爲兩部分。你可以得到的橫截面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 

不知道,如果你去上面的個人資料的頂部會發生什麼......

+0

非常感謝您的回答!這工作完美! – Nicolle