⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module1.bas

📁 VB开发的基于mapX的地图匹配的程序。包含自己开发的点匹配算法。
💻 BAS
📖 第 1 页 / 共 2 页
字号:
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 + -