?? module1.bas
字號:
Attribute VB_Name = "Module1"
Type Car
X As Double
Y As Double
End Type
Type SearchLine
Firstpointx As Double
FirstPointY As Double
SecondPointX As Double
SecondPointY As Double
ThirdPointX As Double
ThirdPointY As Double
D As Double
Angle As Double
DisAngle As Double
Name As String
End Type
Public Function MapMatch(ByVal GpsX As Double, ByVal GpsY As Double, ByVal CarSpeed As Double) As Car
Dim Road() As SearchLine
Dim Part() As SearchLine
Static LastGpsX As Double
Static LastGpsY As Double
Static LCarGpsX As Double
Static LCarGpsY As Double
Static AglMax As Double
Dim FpointX As Double
Dim FpointY As Double
Dim SpointX As Double
Dim SpointY As Double
Dim TpointX As Double
Dim TpointY As Double
Dim r As Double
Dim m1 As Double
Dim m2 As Double
Dim agl As Double
Dim disagl As Double
Dim Max As Double
Dim PMax As Double
Dim N As Integer
Dim Ct As Integer
Dim i As Integer
Dim j As Integer
Dim z As Integer
Dim g As Integer
Dim k1 As Integer
Dim k2 As Integer
Dim f_point, s_point As Integer
Dim big As Double
Dim small As Double
Dim Sel_Features As mapxlib.Features
Dim Sel_Feature As mapxlib.Feature
Dim Sel_Point As mapxlib.FindFeature
'速度判斷/停車狀態~~~~~~~~~~~~~~~~~~~~~~
Debug.Print GpsX, GpsY, LastGpsX, LastGpsY, "gps qqqqqqqqqq", CarSpeed, "CarSpeed"
'停車狀態TTTTTTTTTTTTTTTTTTTTT
If CarSpeed < 2 Then
'如果有上次車輛匹配效果,則采用上次車輛匹配效果
If LastGpsX <> 0 And LastGpsY <> 0 Then
MapMatch.X = LCarGpsX
MapMatch.Y = LCarGpsY
Else
MapMatch.X = GpsX
MapMatch.Y = GpsY
End If
'停車狀態結束TTTTTTTTTTTTTTTTT
'正常行駛狀態$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Else
big = 1E+20
small = 0.0005
AglMax = 360
r = 0.05
Dim pt As New Point
pt.Set GpsX, GpsY
'選取待匹配路段
Set Sel_Features = Form1.Map1.Layers("TC-B路段").SearchWithinDistance(pt, r, miUnitKilometer, 1)
N = Sel_Features.Count
Debug.Print N & "NNN"
'匹配過程——————————————————————————————————————————
'搜索目標路段
'當未找到目標路段的時候,取用GPS定位數據
'(1)8888888888888888
If N = 0 Then
MapMatch.X = GpsX
MapMatch.Y = GpsY
'當找到目標路段的時候,對目標路段進行篩選
'(1)888888888888888888
ElseIf N > 0 Then
ReDim Road(N) As SearchLine
i = 1
j = 9999
Max = 9999
k2 = 9999
For Each Sel_Feature In Sel_Features
'選取路段節點,分直線段和非直線段兩種
'目標路段的起終點
Road(i).Name = Sel_Feature.Name
'取路段的起終點
Dim Post As Integer
Post = InStr(1, Road(i).Name, "-", vbTextCompare)
f_point = CInt(Mid(Road(i).Name, 1, Post - 1))
s_point = CInt(Mid(Road(i).Name, Post + 1))
Debug.Print f_point, s_point, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Dim ft_fin As FindFeature
Set ft_fin = Form1.Map1.Layers("TC-B路段").Find.Search(CStr(f_point) & "-" & CStr(s_point))
'Debug.Print ft_fin & "ft_fin"
Ct = ft_fin.Parts.Item(1).Count
Debug.Print Ct & "count"
'路段處理過程%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(就是附值road(i).d過程) 開始
'(2)8 8
'直線段節點選取(直 直 直 直 直 直 直 直 直) 開始
If Ct = 2 Then
'取路段兩個節點的X,Y坐標
Set Sel_Point = Form1.Map1.Layers("TC-B節點").Find.Search(f_point)
Road(i).Firstpointx = Sel_Point.CenterX
Road(i).FirstPointY = Sel_Point.CenterY
Set Sel_Point = Form1.Map1.Layers("TC-B節點").Find.Search(s_point)
Road(i).SecondPointX = Sel_Point.CenterX
Road(i).SecondPointY = Sel_Point.CenterY
Debug.Print Road(i).Firstpointx, Road(i).FirstPointY, Road(i).SecondPointX, Road(i).SecondPointY, "Road(i).Firstpointx, Road(i).FirstPointY, Road(i).SecondPointX, Road(i).SecondPointY"
'判斷路段垂直,平行還是一般,求在該路段的投影點和路段的角度
'(3)8 8 8
If Road(i).Firstpointx = Road(i).SecondPointX Then
Road(i).ThirdPointX = Road(i).Firstpointx
Road(i).ThirdPointY = GpsY
Road(i).Angle = 0
ElseIf Road(i).FirstPointY = Road(i).SecondPointY Then
Road(i).ThirdPointX = GpsX
Road(i).ThirdPointY = Road(i).FirstPointY
Road(i).Angle = 90
ElseIf Road(i).SecondPointX > Road(i).Firstpointx And Road(i).SecondPointY > Road(i).FirstPointY Then
m1 = (Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)
m2 = -1 / m1
Road(i).ThirdPointX = (GpsY - Road(i).FirstPointY + m1 * Road(i).Firstpointx - m2 * GpsX) / (m1 - m2)
Road(i).ThirdPointY = Road(i).FirstPointY + m1 * (Road(i).ThirdPointX - Road(i).Firstpointx)
Road(i).Angle = 90 - Atn((Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)) * 180 / 3.14159265358979
ElseIf Road(i).SecondPointX > Road(i).Firstpointx And Road(i).SecondPointY < Road(i).FirstPointY Then
m1 = (Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)
m2 = -1 / m1
Road(i).ThirdPointX = (GpsY - Road(i).FirstPointY + m1 * Road(i).Firstpointx - m2 * GpsX) / (m1 - m2)
Road(i).ThirdPointY = Road(i).FirstPointY + m1 * (Road(i).ThirdPointX - Road(i).Firstpointx)
Road(i).Angle = 90 - Atn((Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)) * 180 / 3.14159265358979
ElseIf Road(i).SecondPointX < Road(i).Firstpointx And Road(i).SecondPointY < Road(i).FirstPointY Then
m1 = (Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)
m2 = -1 / m1
Road(i).ThirdPointX = (GpsY - Road(i).FirstPointY + m1 * Road(i).Firstpointx - m2 * GpsX) / (m1 - m2)
Road(i).ThirdPointY = Road(i).FirstPointY + m1 * (Road(i).ThirdPointX - Road(i).Firstpointx)
Road(i).Angle = 270 - Atn((Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)) * 180 / 3.14159265358979
ElseIf Road(i).SecondPointX < Road(i).Firstpointx And Road(i).SecondPointY > Road(i).FirstPointY Then
m1 = (Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)
m2 = -1 / m1
Road(i).ThirdPointX = (GpsY - Road(i).FirstPointY + m1 * Road(i).Firstpointx - m2 * GpsX) / (m1 - m2)
Road(i).ThirdPointY = Road(i).FirstPointY + m1 * (Road(i).ThirdPointX - Road(i).Firstpointx)
Road(i).Angle = 270 - Atn((Road(i).SecondPointY - Road(i).FirstPointY) / (Road(i).SecondPointX - Road(i).Firstpointx)) * 180 / 3.14159265358979
End If
'(3)8 8 8
Debug.Print Road(i).Angle, "angle", Road(i).ThirdPointX, Road(i).ThirdPointY, "Road(i).ThirdPointX, Road(i).ThirdPointY"
Debug.Print (Form1.Map1.Distance(Road(i).ThirdPointX, Road(i).ThirdPointY, Road(i).Firstpointx, Road(i).FirstPointY) + Form1.Map1.Distance(Road(i).ThirdPointX, Road(i).ThirdPointY, Road(i).SecondPointX, Road(i).SecondPointY)) - Form1.Map1.Distance(Road(i).Firstpointx, Road(i).FirstPointY, Road(i).SecondPointX, Road(i).SecondPointY)
'判斷投影點在不在路段上,若不在就不選擇該路段
'(3)(2)8 8 8 2
If (Form1.Map1.Distance(Road(i).ThirdPointX, Road(i).ThirdPointY, Road(i).Firstpointx, Road(i).FirstPointY) + Form1.Map1.Distance(Road(i).ThirdPointX, Road(i).ThirdPointY, Road(i).SecondPointX, Road(i).SecondPointY)) - Form1.Map1.Distance(Road(i).Firstpointx, Road(i).FirstPointY, Road(i).SecondPointX, Road(i).SecondPointY) < small Then
Road(i).D = Sqr((GpsX - Road(i).ThirdPointX) ^ 2 + (GpsY - Road(i).ThirdPointY) ^ 2)
Else
Road(i).D = 9998
End If
'(3)(2)8 8 8 2
Debug.Print Road(i).D, "Road(i).D", i, "i"
'(3)(3)8 8 8 3
If N <> 1 Then
'(4)8 8 8 8
If Road(i).D <> 9998 Then
'(5)8 8 8 8 8
If LastGpsX <> 0 And LastGpsY <> 0 Then
'(6)8 8 8 8 8 8
If GpsY = LastGpsY And GpsX <> LastGpsX Then
agl = 90
ElseIf GpsX = LastGpsX And GpsY <> LastGpsY Then
If Road(i).Angle > 90 And Road(i).Angle < 270 Then
agl = 180
ElseIf Road(i).Angle < 90 Then
agl = 0
ElseIf Road(i).Angle > 270 Then
agl = 360
End If
Else
'(7)8 8 8 8 8 8 8
If GpsY > LastGpsY And GpsX > LastGpsX Then
agl = 90 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY < LastGpsY And GpsX < LastGpsX Then
agl = 270 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY < LastGpsY And GpsX > LastGpsX Then
agl = 90 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
ElseIf GpsY > LastGpsY And GpsX < LastGpsX Then
agl = 270 - Atn((LastGpsY - GpsY) / (LastGpsX - GpsX)) * 180 / 3.14159265358979
End If
'(7)8 8 8 8 8 8 8
End If
'(6)8 8 8 8 8 8
End If
Debug.Print agl, "agl", LastGpsX, LastGpsY, GpsX, GpsY
'(5)8 8 8 8 8
disagl = Abs(Road(i).Angle - agl)
Debug.Print disagl, "disagl"
'(5)8 8 8 8 8 2
If disagl > 90 And disagl < 180 Then
Road(i).DisAngle = 180 - disagl
ElseIf disagl > 180 And disagl < 270 Then
Road(i).DisAngle = disagl - 180
ElseIf disagl > 270 Then
Road(i).DisAngle = 360 - disagl
Else
Road(i).DisAngle = disagl
End If
'(5)8 8 8 8 8 2
Debug.Print Road(i).DisAngle, AglMax, "Road(i).DisAngle, AglMax"
End If
'(4)8 8 8 8
End If
'(3)(3)8 8 8 3
Debug.Print Road(i).D, "i", i
'直線段節點選取(直 直 直 直 直 直 直 直 直) 結束
'非直線段節點選取
ElseIf Ct > 2 And Ct < 10 Then
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -