我想估算降雨量的反距离加权(IDW)插值。 我确定了到所需站点最近的三个站点以获得插值。
我有下表:
那么,IDW的等式:
[(Station_valu1/Dist1^2)+(Station_valu2/Dist2^2)+(Station_valu3/Dist3^2)]
—————————————————————————————————————————————————————————————————————————
1/Dist1^2 + 1/Dist2^2 + 1/Dist3^2
在这个等式中,有几种情况试图解决它们:
1)如果Value1
或Dist1
为空且Value2
,Dist2
,Value3
,Dist3
不是
然后,忽略等式中的Value1
,Dist1
,并仅考虑Value2
,Dist2
和Value3
,Dist3
。
IDW的结果将是:
[Station_valu2/Dist2^2)+(Station_valu3/Dist3^2)]
————————————————————————————————————————————————
Dist2^2 + 1/Dist3^2
我们将使用Value2
,Dist2
和Value3
,Dist3
的相同方案,如果其中任何人的值为空。
我想出了这段代码:
Function IDWW(Value1, Value2, Value3, Dist1,Dist2,Dist3)
Dim a1 As Variant
Dim b1 As Variant
Dim a2 As Variant
Dim b2 As Variant
Dim a3 As Variant
Dim b3 As Variant
If Value1 <> "" And Dist1 <> "" Then
a1 = Value1 / (Dist1) ^ 2
b1 = 1 / (Dist1) ^ 2
ElseIF Value1 = "" OR Dist1 = "" Then
a1 = ""
b1 = ""
End If
If Value2 <> "" And Dist2 <> "" Then
a2 = Value2 / (Dist2) ^ 2
b2 = 1 / (Dist2) ^ 2
ElseIF Value1 = "" OR Dist1 = "" Then
a2 = ""
b2 = ""
End If
If Value3 <> "" And Dist3 <> "" Then
a3 = Value3 / (Dist3) ^ 2
b3 = 1 / (Dist3) ^ 2
ElseIF Value3 = "" OR Dist3 = "" Then
a3 = ""
b3 = ""
End If
IDWW = (a1+a2+a3) / (b1+b2+b3)
End Function
拜托,我需要你的帮助来解决这个问题!
答案 0 :(得分:0)
据我所知,如果它们为空,你想要做的就是设置为零:
Function IDWW(Value1, Value2, Value3, Dist1,Dist2,Dist3)
Dim a1 As Variant
Dim b1 As Variant
Dim a2 As Variant
Dim b2 As Variant
Dim a3 As Variant
Dim b3 As Variant
If Value1 <> "" And Dist1 <> "" Then
a1 = Value1 / (Dist1) ^ 2
b1 = 1 / (Dist1) ^ 2
Else
a1 = 0
b1 = 0
End If
If Value2 <> "" And Dist2 <> "" Then
a2 = Value2 / (Dist2) ^ 2
b2 = 1 / (Dist2) ^ 2
Else
a2 = 0
b2 = 0
End If
If Value3 <> "" And Dist3 <> "" Then
a3 = Value3 / (Dist3) ^ 2
b3 = 1 / (Dist3) ^ 2
Else
a3 = 0
b3 = 0
End If
'Avoid a problem if all 3 distances are empty
If b1 + b2 + b3 = 0 Then
IDWW = 0
Else
IDWW = (a1+a2+a3) / (b1+b2+b3)
End If
End Function