馨馨 发表于 2016-5-22 09:00:26

规则格网记录点号,反距离加权插值求出高程

离散点格网化,记录点号在哪个格网,用反距离加权插值求出高程
把每个格网点当做原点,在四个象限内寻找4-8个离散点参与插值运算
设格网点与离散点距离为d,若d<20,范围内有4-8个离散点,则用这些离散点参与插值运算
若离散点小于4个或者大于8个,动态调整距离,是d增加或者减小,代码是记录点号,问题是不能找出每个格网点参与运算的离散点,求大家帮忙Sub RecordPointPosition()
Dim NX As Integer, NY As Integer '离散点所在网格的列'离散点所在的网格的行
Dim i As Integer, j As Integer
Dim Xmax As Double, Xmin As Double, Ymax As Double, Ymin As Double

dbld = 20
Open "E:\zuizhi.txt" For Input As #1 '打开输入文件
Input #1, Xmax, Ymax, Xmin, Ymin '读取文件数据
Close #1

L = 0
Open "E:\demdata.txt" For Input As #1 '打开原始文件
Do While Not EOF(1)
Input #1, H(L), X(L), Y(L), Z(L)
L = L + 1
Loop
Close #1

M = Fix((Xmax - Xmin) / dbld) + 1 '列数
N = Fix((Ymax - Ymin) / dbld) + 1 '行数

ReDim IP(L) As Long, IREG(N, M) As Double


'循环判断
For i = 1 To L - 1
'计算样点所在网格
NX = Fix((X(i) - Xmin) / dbld)
NY = Fix((Y(i) - Ymin) / dbld)
If IREG(NY, NX) = 0 Then
IREG(NY, NX) = H(i) '记录点号
Else
j = IREG(NY, NX)
'寻找链表的末端
Do
If IP(j) = 0 Then
    IP(j) = H(i) '记录点号
Exit Do
Else
    j = IP(j)
End If
Loop

End If
Next i
end sub
页: [1]
查看完整版本: 规则格网记录点号,反距离加权插值求出高程