27/9/23 - Se agregó la función "FindInZone" a Subs para ver si una ubicación esta dentro de un poligono.

This commit is contained in:
2023-09-27 15:37:27 -06:00
parent 9868557f34
commit 5438cd9635
2 changed files with 47 additions and 0 deletions

View File

@@ -136,4 +136,51 @@ End Sub
'Centra un panel dentro de un elemento superior 'Centra un panel dentro de un elemento superior
Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2) elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Geo-Zone Determination (Point in Polygon)
'Use this to determine If a vehicle is within a defined zone made of 5 or more lat/lon coordinates.
'Point 1 Is also Point 5 (first point And last point are same value).
'You can add the points clockwise or counterclockwise.
Sub FindInZone( polx As List, poly As List, x As Double, y As Double) As Boolean 'ignore
' polx = list of lats for polygon
' poly = list of lons for polygon
' y = lon to test
' x = lat to test
Dim x1, y1, x2, y2, D As Double
Dim i, ni As Int
ni = 0
x1 = polx.Get(0)
y1 = poly.Get(0)
For i = 0 To polx.Size -1
If i < polx.Size Then
x2 = polx.Get(i)
y2 = poly.Get(i)
Else
x2 = polx.Get(0) ' checks the last line
y2 = poly.Get(0)
End If
If y >= Min(y1, y2) Then
If y <= Max(y1, y2) Then
If x <= Max(x1, x2) Then
If (x = x1 And y = y1) Or (x = x1 And x = x2) Then ' checks vertices and vertical lines
Return True
End If
If y1 <> y2 Then
D = (y - y1) * (x2 - x1) / (y2 - y1) + x1
If x1 = x2 Or x <= D Then
ni = ni + 1
End If
End If
End If
End If
End If
x1 = x2
y1 = y2
Next
If ni Mod 2 = 0 Then
Return False
Else
Return True
End If
End Sub End Sub