-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodOSM.bas
More file actions
972 lines (694 loc) · 27.4 KB
/
modOSM.bas
File metadata and controls
972 lines (694 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
Attribute VB_Name = "modOSM"
Option Explicit
'https://wiki.openstreetmap.org/wiki/Map_features
Public Type tNode
fileID As Currency 'could be bigger than LONG 4bytes (currency 8 Bytes)
id As Long
X As Double
Y As Double
Used As Boolean
scrX As Double ' Long
scrY As Double ' Long
'Dijkstra--------------------------------
NNext As Long 'N of nodes reachable from this Node
NEXTnode() As Long 'List of Nodes reachable from this Node
NextNodeCOST() As Double
NEXTNodeWay() As Long
NextNodeWAYSegment() As Long
dIsWay As Boolean
dCost As Double
dBestfrom As Long
dVisited As Long 'Boolean
ONEWAY As Long '?? Boolean 'Long Maybe Useless
'------------------------------------------------
Layer As Long 'For bridges / tunnels
Traffic As Double
End Type
Public Type tRoad
fileID As Long
id As Long
NN As Long ' Number of nodes of the road
invNN As Double '1/NN
N() As Currency 'List of Nodes
SegDX() As Double ' 1 to NN-1
SegDY() As Double 'Segment direction and angle
SegAngle() As Double
RoadWidth As Double
Name As String
wayType As String
isDRIVEABLE As Boolean ' Can be used by Cars
IsStreetSideParkable As Boolean
IsRailWay As Boolean
IsBoundary As Boolean
IsBuilding As Boolean
IsArea As Boolean
IsWater As Boolean
IsLeisure As Boolean
IsAmenity As Boolean
IsShop As Boolean
IsNatural As Boolean
isNotAsphalt As Boolean
Layer As Long
Lanes As Long
OneWayDirections As Long 'Drivable ways 0= Both : 1 = Forward -1=Backward
'bound Box
BBx1 As Double
BBY1 As Double
BBx2 As Double
BBY2 As Double
'World Center
CenterX As Double ' NON SALVARE
CenterY As Double
R As Double
G As Double
B As Double
End Type
Public Const MAPSsubFolder As String = "\MAPS\"
Public Node() As tNode
Public NNode As Long
Public WAY() As tRoad
Public NWay As Long
Public DJ As clsDijkstra
Public dijPATH As tRoad
Private ptsUSED As Long
Public MapOwest As Double
Public MapNorth As Double
Public MapEast As Double
Public MapSouth As Double
Public EastOwestMapExtension As Currency
Public NorthSouthMapExtension As Currency
Private NODESbyFileID As cCollection
Public minLayer As Long
Public maxLayer As Long
Private Function RemoveM(v As String) As String
Dim I As Long
I = InStr(1, v, "m")
If I Then
RemoveM = Left$(v, I - 1)
Else
RemoveM = v
End If
End Function
Public Sub ReadOSM(FN As String)
Dim X As Double
Dim Y As Double
Dim utmX As Double
Dim utmY As Double
Dim MaxNways As Long
Dim MaxNNodes As Long
Dim objXML As MSXML2.DOMDocument60
Dim objXML2 As New MSXML2.DOMDocument60
Dim objElem As MSXML2.IXMLDOMElement
Dim objElem2 As MSXML2.IXMLDOMElement
Dim objSub As MSXML2.IXMLDOMElement
Dim K As String
Dim v As String
Set objXML = New MSXML2.DOMDocument60
MapOwest = 1E+99
MapNorth = 1E+99
MapEast = -1E+99
MapSouth = -1E+99
minLayer = 100000000#
maxLayer = -100000000#
NNode = 0
NWay = 0
Erase Node
Erase WAY
Erase CAR
Set DJ = New clsDijkstra
Set NODESbyFileID = New_c.Collection(False)
SETPROGRESS "Start reading " & MAPSsubFolder & frmMain.File1.FileName
If objXML.Load(FN) Then
NNode = 0
For Each objElem In objXML.selectNodes("//node")
NNode = NNode + 1
If (NNode And 1023&) = 0& Then
' frmMain.Caption = "reading nodes.... " & NNode
SETPROGRESS "reading nodes.... " & NNode
DoEvents
End If
If NNode >= MaxNNodes Then
MaxNNodes = NNode + 10000
ReDim Preserve Node(MaxNNodes)
End If
With Node(NNode)
'Set objElem = objXML.selectSingleNode("//node")
'Debug.Print objElem.getAttribute("id")
'Debug.Print objElem.getAttribute("lat")
'Debug.Print objElem.getAttribute("lon")
.id = NNode
.fileID = (objElem.getAttribute("id"))
NODESbyFileID.Add NNode, .fileID
X = Val(objElem.getAttribute("lat"))
Y = Val(objElem.getAttribute("lon"))
LatLongToUTM X, Y, utmX, utmY
.X = utmX
.Y = utmY
If utmX < MapOwest Then MapOwest = utmX
If utmX > MapEast Then MapEast = utmX
If utmY < MapNorth Then MapNorth = utmY
If utmY > MapSouth Then MapSouth = utmY
' ' iterate its sub-nodes
' For Each objSub In objElem.childNodes
' Debug.Print objSub.xml
' Stop
' Next
End With
Next
EastOwestMapExtension = MapEast - MapOwest
NorthSouthMapExtension = MapSouth - MapNorth
'---------------------
NWay = 0
For Each objElem In objXML.selectNodes("//way")
If (NWay And 1023&) = 0& Then
' frmMain.Caption = "reading Ways.... " & NWay
SETPROGRESS "reading Ways.... " & NWay
DoEvents
End If
'Debug.Print "---------------------------------------------------------"
'Debug.Print "way: " & objElem.getAttribute("id")
NWay = NWay + 1
If NWay > MaxNways Then
MaxNways = NWay + 2500
ReDim Preserve WAY(MaxNways)
End If
With WAY(NWay)
.fileID = objElem.getAttribute("id")
For Each objElem2 In objElem.childNodes ' objXML2.selectNodes("//nd ref") 'objXML2.childNodes
If objElem2.getAttribute("ref") <> vbNull Then
'Add nodes
.NN = .NN + 1
ReDim Preserve .N(.NN)
ReDim Preserve .SegAngle(.NN)
ReDim Preserve .SegDX(.NN)
ReDim Preserve .SegDY(.NN)
.N(.NN) = objElem2.getAttribute("ref")
'Debug.Print objElem2.getAttribute("ref")
End If
If objElem2.getAttribute("k") <> vbNull Then
K = objElem2.getAttribute("k")
v = objElem2.getAttribute("v")
'Debug.Print K & vbTab & V
.Lanes = 2
Select Case K
Case "highway", "railway"
.wayType = Replace$(v, ",", ".")
.isDRIVEABLE = _
(.wayType <> "pedestrian" And _
.wayType <> "path" And _
.wayType <> "steps" And _
.wayType <> "footway" And _
.wayType <> "cycleway" And _
.wayType <> "rail" And _
K <> "railway")
If v = "mini_roundabout" Then
.OneWayDirections = 1
End If
If K = "railway" And .wayType = "rail" Then .IsRailWay = True
Case "name"
.Name = v
Case "width"
.RoadWidth = Val(RemoveM(v)) '6M' '-------------------------------------TO DO
Case "building"
If v <> "no" Then
.IsBuilding = True
If .Name = vbNullString Then
If v <> "yes" And v <> "hut" And v <> "roof" And _
v <> "residential" And v <> "detached" And _
v <> "house" And _
v <> "apartments" _
Then .Name = v
End If
End If
Case "area"
If v <> "no" Then .IsArea = True
Case "waterway"
If v = "riverbank" Then .IsWater = True
Case "leisure"
If v <> "no" Then .IsLeisure = True
If v = "swimming_pool" Then .IsLeisure = True: .Name = "Swimming Pool"
Case "amenity"
.IsAmenity = True
If .Name = vbNullString Then .Name = v
If .Name = "bench" Then .IsAmenity = False
Case "lanes"
If v = "1" Then
' .OneWayDirections = 1 ''' ???????????
End If
.Lanes = Val(v)
If .Lanes = 0 Then .Lanes = 2 '''????
Case "junction"
If v = "roundabout" Then
.OneWayDirections = 1
End If
Case "shop"
.IsShop = True
If .Name = vbNullString Then .Name = v
Case "natural"
If v = "water" Then
.IsWater = True
If .Name = vbNullString Then .Name = v
End If
'-------------------
Case "surface"
If v <> "asphalt" Then .isNotAsphalt = True
Case "layer"
.Layer = Val(v)
Case "boundary"
.IsBoundary = True
Case "oneway"
If v = "yes" Or v = "true" Then
.OneWayDirections = 1
ElseIf v = "-1" Then
.OneWayDirections = -1
ElseIf v = "no" Then
.OneWayDirections = 0
End If
End Select
'If .isNotAsphalt Then .Layer = -1
If InStr(1, K, "parking") Then
If v <> "no" Then .IsStreetSideParkable = True
End If
If LenB(.Name) Then .Name = Replace$(.Name, ",", ".")
If .RoadWidth < kRoadW Then .RoadWidth = kRoadW
End If
Next
.invNN = 1 / .NN
End With
Next
End If
SETPROGRESS "Sorting Ways..."
SortWaysByLayer WAY, 1, NWay
frmMain.Caption = " " & NNode & " Nodes and " & NWay & " Ways readed."
End Sub
''Private Function FindNodeID(fileID As Currency) As Long ', PrevI As Long) As Long
'' FindNodeID = NODESbyFileID.Item(fileID)
'' Dim I As Long
'' Dim J As Long
'' Static prevI As Long
''
'' I = prevI
'' J = I
'' Do
'' I = I + 1&
'' I = ((I - 1&) Mod NNode) + 1&
'' J = (NNode + J - 2) Mod NNode + 1
'' If Node(I).fileID = fileID Then FindNodeID = I: prevI = I - 1: Exit Do
'' If Node(J).fileID = fileID Then FindNodeID = J: prevI = J + 1: Exit Do
'' Loop While True
''End Function
Private Sub DIJKSTRAsetupCosts()
Dim I&, J&
Dim myNode&
For I = 1 To NWay
If WAY(I).isDRIVEABLE Then
For J = 2 To WAY(I).NN
If WAY(I).OneWayDirections >= 0 Then 'Street Forward
myNode = WAY(I).N(J - 1)
With Node(myNode)
If .dIsWay Then
.NNext = .NNext + 1
ReDim Preserve .NEXTnode(.NNext)
ReDim Preserve .NextNodeCOST(.NNext)
.NEXTnode(.NNext) = WAY(I).N(J)
.NextNodeCOST(.NNext) = calcStreetSegmentCOST(myNode, WAY(I).N(J) * 1)
ReDim Preserve .NEXTNodeWay(.NNext)
ReDim Preserve .NextNodeWAYSegment(.NNext)
.NEXTNodeWay(.NNext) = I
.NextNodeWAYSegment(.NNext) = J - 1
End If
End With
'Else
'MsgBox "node " & myNode & " Not used"
End If
If WAY(I).OneWayDirections <= 0 Then 'Street Backward
myNode = WAY(I).N(J)
With Node(myNode)
If .dIsWay Then
.NNext = .NNext + 1
ReDim Preserve .NEXTnode(.NNext)
ReDim Preserve .NextNodeCOST(.NNext)
.NEXTnode(.NNext) = WAY(I).N(J - 1)
.NextNodeCOST(.NNext) = calcStreetSegmentCOST(myNode, WAY(I).N(J - 1) * 1)
ReDim Preserve .NEXTNodeWay(.NNext)
ReDim Preserve .NextNodeWAYSegment(.NNext)
.NEXTNodeWay(.NNext) = I
'Negative Sign to indicate Opposite Direction (for Cost)
' in "DIJKSTRAvisit"
.NextNodeWAYSegment(.NNext) = -(J - 1)
End If
End With
'MsgBox "node " & myNode & " Not used"
End If
Next
End If
Next
End Sub
Private Sub DIJKSTRAsetup()
Dim I As Long
Dim J As Long
Dim MinX As Double
Dim MinY As Double
''''''''''''''''''''''''''''''''''''for dijkstra
For I = 1 To NWay
If (I And 1023&) = 0& Then
SETPROGRESS "DIJKSTRA setup ...." & I & " / " & NWay, I / NWay: DoEvents
End If
With WAY(I)
If Not (.isDRIVEABLE) Or .IsArea Or .IsBuilding Or .IsWater Or .IsAmenity Then
Else
If Len(.wayType) And .wayType <> "pedestrian" _
And .wayType <> "path" _
And .wayType <> "steps" _
And .wayType <> "footway" _
And .wayType <> "cycleway" Then
For J = 1 To .NN
Node(.N(J)).dIsWay = True
Node(.N(J)).ONEWAY = .OneWayDirections
'Debug.Print .wayType, .NAME: Stop
Next
End If
End If
End With
Next
'--------------------------------------------------
'''Setup ONEways (for DIJKSTRA) & Draw
DIJKSTRAsetupCosts
'-------------------------- END [DIJKSTRAsetup]
'---------------------TRANSLATE ALL
MinX = 1E+99
MinY = 1E+99
For I = 1 To NNode
If Node(I).dIsWay Then '2024
If Node(I).X < MinX Then MinX = Node(I).X
If Node(I).Y < MinY Then MinY = Node(I).Y
End If
Next
MinX = MinX + 20
MinY = MinY + 20
For I = 1 To NNode
Node(I).X = Round(Node(I).X - MinX, 2)
Node(I).Y = Round(Node(I).Y - MinY, 2)
Next
'SET World Coordinates Bounding Boxes
Dim X#, Y#
For I = 1 To NWay
With WAY(I)
.BBx1 = 1E+99
.BBY1 = 1E+99
.BBx2 = -1E+99
.BBY2 = -1E+99
For J = 1 To .NN
X = Node(.N(J)).X
Y = Node(.N(J)).Y
If X < .BBx1 Then .BBx1 = X
If Y < .BBY1 Then .BBY1 = Y
If X > .BBx2 Then .BBx2 = X
If Y > .BBY2 Then .BBY2 = Y
Next
If .IsBuilding Then 'Some Random color
.R = Rnd * 2 - 1
.G = Rnd * 2 - 1
.B = Rnd * 2 - 1
End If
End With
Next
frmMain.Caption = "": DoEvents
End Sub
Public Sub PURGEAndSave(FN As String)
Dim I As Long
Dim J As Long
Dim K As Long
Dim sx#, sy#, sc#
Dim NID As Currency
Dim DX#, DY#, A#
ptsUSED = 0
'Find Used Points---------------------And Convert FileID to ID
For I = 1 To NWay
With WAY(I)
For J = 1 To .NN
'NID = FindNodeID( .N(J))
NID = NODESbyFileID.Item(.N(J)) '<----------------------------- !!!
.N(J) = NID
' .N(J) = FindNodeID( .N(J), PREV)
If NID Then Node(.N(J)).Used = True
If .isDRIVEABLE Then
If .Layer > maxLayer Then maxLayer = .Layer
If .Layer < minLayer Then minLayer = .Layer
' sx = sx + Node(J).X
' sy = sy + Node(J).Y
' sc = sc + 1
End If
Next
'-------------------------------------------- way angles
For J = 1 To .NN - 1
K = J + 1
DX = Node(.N(K)).X - Node(.N(J)).X
DY = Node(.N(K)).Y - Node(.N(J)).Y
A = Atan2(DX, DY)
If A < 0 Then A = A + PI2
.SegAngle(J) = Round(A, 4)
.SegDX(J) = Round(Cos(A), 4)
.SegDY(J) = Round(Sin(A), 4)
Next
For J = 1 To .NN
' For J = 2 To .NN - 1
Node(.N(J)).Layer = .Layer
Next
'-------------------------------------------------------
If (I And 1023&) = 0& Then
' frmMain.Caption = "Elaborating Ways ... " & I & "/" & NWay
SETPROGRESS "Elaborating Ways ... " & I & "/" & NWay, I / NWay
DoEvents
End If
End With
Next
' CalcWaysAngles
For I = 1 To NNode
If Node(I).Used Then ptsUSED = ptsUSED + 1
Next
'--------------------------------------------------------------------------------------
DIJKSTRAsetup '<---------------------------------------------
' SAVEPURGED
frmMain.Caption = "ready"
DoEvents
End Sub
Public Sub SAVEPURGED()
Dim I As Long
Dim J As Long
'--------------------------------------------------------------------------------------
' frmMain.Caption = "Saving points .... used " & ptsUSED & " of " & NNode
DoEvents
Open App.Path & "\OUT.txt" For Output As 1
Print #1, minLayer
Print #1, maxLayer
Print #1, NNode ' ptsUSED
For I = 1 To NNode
If (I And 1023&) = 0 Then SETPROGRESS "Saving Points... " & I, I / NNode
'If Node(I).Used Then
Print #1, Replace(CStr(Node(I).X), ",", ".")
Print #1, Replace(CStr(Node(I).Y), ",", ".")
Print #1, Node(I).Layer
'End If
Next
Print #1, "---------------------------------------------------"
Print #1, NWay
For I = 1 To NWay
With WAY(I)
If (I And 1023&) = 0 Then
' frmMain.Caption = "Saving Way .... " & I
DoEvents
SETPROGRESS "Saving Ways... " & I, I / NWay
End If
Print #1, "Way -------------" & I
Print #1, .NN
For J = 1 To .NN
Print #1, Node(.N(J)).id
Print #1, Replace(CStr(.SegAngle(J)), ",", ".")
Print #1, Replace(CStr(.SegDX(J)), ",", ".")
Print #1, Replace(CStr(.SegDY(J)), ",", ".")
Next
Print #1, .wayType
'If LenB(.NAME) Then
Print #1, .Name
'Else
' Print #1, "no name"
'End If
Print #1, IIf(.isDRIVEABLE, "yes", "no")
Print #1, IIf(.IsRailWay, "yes", "no")
Print #1, IIf(.IsBoundary, "yes", "no")
Print #1, IIf(.IsArea, "yes", "no")
Print #1, IIf(.IsBuilding, "yes", "no")
Print #1, IIf(.IsWater, "yes", "no")
Print #1, IIf(.IsLeisure, "yes", "no")
Print #1, IIf(.IsAmenity, "yes", "no")
Print #1, IIf(.IsShop, "yes", "no")
Print #1, IIf(.isNotAsphalt, "yes", "no")
Print #1, .Layer
Print #1, .Lanes
' Print #1, IIf(.IsNatural, "yes", "no")
Print #1, .OneWayDirections
Print #1, Replace(.RoadWidth, ",", ".")
Print #1, Replace(.invNN, ",", ".")
End With
Next
Close 1
End Sub
Private Function YesNo2Bool(S As String) As Boolean
If S = "yes" Then YesNo2Bool = True
End Function
Public Sub LOADpurged()
Dim I As Currency
Dim J As Currency
Dim S As String
'--------------------------------------------------------------------------------------
' frmMain.Caption = "LOADING... "
SETPROGRESS "LOADING... "
DoEvents
Open App.Path & "\OUT.txt" For Input As 1
Input #1, minLayer
Input #1, maxLayer
Input #1, ptsUSED
NNode = ptsUSED
ReDim Node(NNode)
MapOwest = 1E+99
MapNorth = 1E+99
MapEast = -1E+99
MapSouth = -1E+99
For I = 1 To NNode
Input #1, Node(I).X
Input #1, Node(I).Y
If Node(I).X < MapOwest Then MapOwest = Node(I).X
If Node(I).X > MapEast Then MapEast = Node(I).X
If Node(I).Y < MapNorth Then MapNorth = Node(I).Y
If Node(I).Y > MapSouth Then MapSouth = Node(I).Y
Input #1, Node(I).Layer
Next
EastOwestMapExtension = MapEast - MapOwest
NorthSouthMapExtension = MapSouth - MapNorth
Input #1, S '"---------------------------------------------------"
Input #1, NWay
ReDim WAY(NWay)
For I = 1 To NWay
With WAY(I)
If (I And 1023&) = 0& Then
' frmMain.Caption = "Loading Way .... " & I
SETPROGRESS "Loading Way .... ", I / NWay
DoEvents
End If
Input #1, S '"Way -------" & I
Input #1, .NN
ReDim .N(.NN)
ReDim .SegAngle(.NN)
ReDim .SegDX(.NN)
ReDim .SegDY(.NN)
For J = 1 To .NN
Input #1, .N(J)
Input #1, .SegAngle(J)
Input #1, .SegDX(J)
Input #1, .SegDY(J)
Next
Input #1, .wayType
Input #1, .Name ': If LenB(.NAME) = 0 Then Stop
Input #1, S: .isDRIVEABLE = YesNo2Bool(S)
Input #1, S: .IsRailWay = YesNo2Bool(S)
Input #1, S: .IsBoundary = YesNo2Bool(S)
Input #1, S: .IsArea = YesNo2Bool(S)
Input #1, S: .IsBuilding = YesNo2Bool(S)
Input #1, S: .IsWater = YesNo2Bool(S)
Input #1, S: .IsLeisure = YesNo2Bool(S)
Input #1, S: .IsAmenity = YesNo2Bool(S)
Input #1, S: .IsShop = YesNo2Bool(S)
Input #1, S: .isNotAsphalt = YesNo2Bool(S)
Input #1, S: .Layer = S
Input #1, S: .Lanes = S
Input #1, .OneWayDirections
Input #1, .RoadWidth
Input #1, .invNN
End With
Next
Close 1
DIJKSTRAsetup '<---------------------------------------------
' frmMain.Caption = "Done": DoEvents
End Sub
Public Sub UPDATETRAFFIC()
Dim I&, N1&, N2&, J&
For I = 1 To NNode
Node(I).Traffic = 0
Next
For I = 1 To Ncars
N1 = CAR(I).NEXTnode
Node(N1).Traffic = Node(N1).Traffic + 1
' For J = 1 To Node(N1).NNext
' N2 = Node(N1).NEXTnode(J)
' Node(N2).Traffic = Node(N2).Traffic + 1
' Next
Next
SETPROGRESS "TRAFFIC"
DIJKSTRAsetupCosts
End Sub
Private Function CalcWaysAngles()
Dim I As Long
Dim J As Long
Dim K As Long
Dim DX#, DY#, A#
For I = 1 To NWay
With WAY(I)
For J = 1 To .NN - 1
K = J + 1
DX = Node(.N(K)).X - Node(.N(J)).X
DY = Node(.N(K)).Y - Node(.N(J)).Y
A = Atan2(DX, DY)
If A < 0 Then A = A + PI2
.SegAngle(J) = Round(A, 4)
.SegDX(J) = Round(Cos(A), 4)
.SegDY(J) = Round(Sin(A), 4)
Next
For J = 1 To .NN
' For J = 2 To .NN - 1
Node(.N(J)).Layer = .Layer
Next
End With
Next
End Function
Private Function SortWaysByLayer(WAys() As tRoad, ByVal Min As Long, ByVal Max As Long)
' FROM HI to LOW 'https://www.vbforums.com/showthread.php?11192-quicksort
Dim Low As Long, high As Long, temp As tRoad
Dim TestDist#
'Debug.Print min, max
Low = Min: high = Max
' TestDist = (WAys(min).Layer + WAys(max).Layer) * 0.5
TestDist = WAys((Min + Max) * 0.5).Layer
Do
Do While (WAys(Low).Layer < TestDist): Low = Low + 1&: Loop
Do While (WAys(high).Layer > TestDist): high = high - 1&: Loop
If (Low <= high) Then
temp = WAys(Low): WAys(Low) = WAys(high): WAys(high) = temp
Low = Low + 1&: high = high - 1&
End If
Loop While (Low <= high)
If (Min < high) Then SortWaysByLayer WAys, Min, high
If (Low < Max) Then SortWaysByLayer WAys, Low, Max
End Function
'Private Function SortWaysByAsphalt(WAys() As tRoad, ByVal Min As Long, ByVal Max As Long)
' ' FROM HI to LOW 'https://www.vbforums.com/showthread.php?11192-quicksort
' Dim Low As Long, high As Long, temp As tRoad
' Dim TestDist As Boolean
' 'Debug.Print min, max
' Low = Min: high = Max
' ' TestDist = (WAys(min).Layer + WAys(max).Layer) * 0.5
' TestDist = WAys((Min + Max) * 0.5).isNotAsphalt
' Do
'
' Do While (WAys(Low).isNotAsphalt < TestDist): Low = Low + 1&: Loop
' Do While (WAys(high).isNotAsphalt > TestDist): high = high - 1&: Loop
'
' If (Low <= high) Then
' temp = WAys(Low): WAys(Low) = WAys(high): WAys(high) = temp
' Low = Low + 1&: high = high - 1&
' End If
' Loop While (Low <= high)
' If (Min < high) Then SortWaysByAsphalt WAys, Min, high
' If (Low < Max) Then SortWaysByAsphalt WAys, Low, Max
'
'End Function