forked from valhalla/valhalla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.lua
1486 lines (1279 loc) · 43.3 KB
/
graph.lua
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
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--TODO: check if you can use lua type boolean instead of strings and pass that back to osm2pgsql
--with the hopes that they will become strings once they get back to c++ and then just work in
--postgres
highway = {
["motorway"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["motorway_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["trunk"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["trunk_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["primary"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["primary_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["secondary"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["secondary_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["residential"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["residential_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["service"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["tertiary"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["tertiary_link"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["road"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["track"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["unclassified"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["undefined"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["unknown"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["living_street"] = {["auto_forward"] = "true", ["truck_forward"] = "true", ["bus_forward"] = "true", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["footway"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "true", ["bike_forward"] = "false"},
["pedestrian"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "true", ["bike_forward"] = "false"},
["steps"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["bridleway"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["construction"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "false", ["bike_forward"] = "false"},
["cycleway"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "false", ["bike_forward"] = "true"},
["path"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "false", ["pedestrian"] = "true", ["bike_forward"] = "true"},
["bus_guideway"] = {["auto_forward"] = "false", ["truck_forward"] = "false", ["bus_forward"] = "true", ["pedestrian"] = "false", ["bike_forward"] = "false"}
}
road_class = {
["motorway"] = 0,
["motorway_link"] = 0,
["trunk"] = 1,
["trunk_link"] = 1,
["primary"] = 2,
["primary_link"] = 2,
["secondary"] = 3,
["secondary_link"] = 3,
["tertiary"] = 4,
["tertiary_link"] = 4,
["unclassified"] = 5,
["residential"] = 6,
["residential_link"] = 6
}
restriction = {
["no_left_turn"] = 0,
["no_right_turn"] = 1,
["no_straight_on"] = 2,
["no_u_turn"] = 3,
["only_right_turn"] = 4,
["only_left_turn"] = 5,
["only_straight_on"] = 6,
["no_entry"] = 7,
["no_exit"] = 8,
["no_turn"] = 9
}
dow = {
["Sunday"] = 1,
["sunday"] = 1,
["Sun"] = 1,
["sun"] = 1,
["Su"] = 1,
["su"] = 1,
["Monday"] = 2,
["monday"] = 2,
["Mon"] = 2,
["mon"] = 2,
["Mo"] = 2,
["mo"] = 2,
["Tuesday"] = 3,
["tuesday"] = 3,
["Tues"] = 3,
["tues"] = 3,
["Tue"] = 3,
["tue"] = 3,
["Tu"] = 3,
["tu"] = 3,
["Wednesday"] = 4,
["wednesday"] = 4,
["Weds"] = 4,
["weds"] = 4,
["Wed"] = 4,
["wed"] = 4,
["We"] = 4,
["we"] = 4,
["Thursday"] = 5,
["thursday"] = 5,
["Thurs"] = 5,
["thurs"] = 5,
["Thur"] = 5,
["thur"] = 5,
["Th"] = 5,
["th"] = 5,
["Friday"] = 6,
["friday"] = 6,
["Fri"] = 6,
["fri"] = 6,
["Fr"] = 6,
["fr"] = 6,
["Saturday"] = 7,
["saturday"] = 7,
["Sat"] = 7,
["sat"] = 7,
["Sa"] = 7,
["sa"] = 7
}
--the default speed for tracks is lowered after
--the call to default_speed
default_speed = {
[0] = 105,
[1] = 90,
[2] = 75,
[3] = 60,
[4] = 50,
[5] = 40,
[6] = 30,
[7] = 20
}
access = {
["yes"] = "true",
["private"] = "true",
["no"] = "false",
["permissive"] = "true",
["agricultural"] = "false",
["use_sidepath"] = "true",
["delivery"] = "true",
["designated"] = "true",
["dismount"] = "true",
["discouraged"] = "false",
["forestry"] = "false",
["destination"] = "true",
["customers"] = "true",
["official"] = "false",
["public"] = "true",
["restricted"] = "true",
["allowed"] = "true",
["emergency"] = "false"
}
private = {
["private"] = "true",
["delivery"] = "true"
}
no_thru_traffic = {
["destination"] = "true",
["customers"] = "true",
["delivery"] = "true"
}
sidewalk = {
["both"] = "true",
["none"] = "false",
["no"] = "false",
["right"] = "true",
["left"] = "true",
["separate"] = "false",
["yes"] = "true",
["shared"] = "true",
["this"] = "true",
["detached"] = "false",
["raised"] = "true",
["separate_double"] = "false",
["sidepath"] = "false",
["explicit"] = "true"
}
use = {
["driveway"] = 4,
["alley"] = 5,
["parking_aisle"] = 6,
["emergency_access"] = 7,
["drive-through"] = 8
}
motor_vehicle = {
["yes"] = "true",
["private"] = "true",
["no"] = "false",
["permissive"] = "true",
["agricultural"] = "false",
["delivery"] = "true",
["designated"] = "true",
["discouraged"] = "false",
["forestry"] = "false",
["destination"] = "true",
["customers"] = "true",
["official"] = "false",
["public"] = "true",
["restricted"] = "true",
["allowed"] = "true"
}
foot = {
["yes"] = "true",
["private"] = "true",
["no"] = "false",
["permissive"] = "true",
["agricultural"] = "false",
["use_sidepath"] = "true",
["delivery"] = "true",
["designated"] = "true",
["discouraged"] = "false",
["forestry"] = "false",
["destination"] = "true",
["customers"] = "true",
["official"] = "true",
["public"] = "true",
["restricted"] = "true",
["crossing"] = "true",
["sidewalk"] = "true",
["allowed"] = "true",
["passable"] = "true",
["footway"] = "true"
}
wheelchair = {
["no"] = "false",
["yes"] = "true",
["designated"] = "true",
["limited"] = "true",
["official"] = "true",
["destination"] = "true",
["public"] = "true",
["permissive"] = "true",
["only"] = "true",
["private"] = "true",
["impassable"] = "false",
["partial"] = "false",
["bad"] = "false",
["half"] = "false",
["assisted"] = "true"
}
bus = {
["no"] = "false",
["yes"] = "true",
["designated"] = "true",
["urban"] = "true",
["permissive"] = "true",
["restricted"] = "true",
["destination"] = "true",
["delivery"] = "false",
["official"] = "false"
}
psv = {
["bus"] = "true",
["no"] = "false",
["yes"] = "true",
["designated"] = "true",
["permissive"] = "true",
["1"] = "true",
["2"] = "true"
}
truck = {
["designated"] = "true",
["yes"] = "true",
["no"] = "false",
["destination"] = "true",
["delivery"] = "true",
["local"] = "true",
["agricultural"] = "false",
["private"] = "true",
["discouraged"] = "false",
["permissive"] = "false",
["unsuitable"] = "false",
["agricultural;forestry"] = "false",
["official"] = "false",
["forestry"] = "false",
["destination;delivery"] = "true"
}
hazmat = {
["designated"] = "true",
["yes"] = "true",
["no"] = "false",
["destination"] = "true",
["delivery"] = "true"
}
bicycle = {
["yes"] = "true",
["designated"] = "true",
["use_sidepath"] = "true",
["no"] = "false",
["permissive"] = "true",
["destination"] = "true",
["dismount"] = "true",
["lane"] = "true",
["track"] = "true",
["shared"] = "true",
["shared_lane"] = "true",
["sidepath"] = "true",
["share_busway"] = "true",
["none"] = "false",
["allowed"] = "true",
["private"] = "true",
["official"] = "true"
}
cycleway = {
["yes"] = "true",
["designated"] = "true",
["use_sidepath"] = "true",
["permissive"] = "true",
["destination"] = "true",
["dismount"] = "true",
["lane"] = "true",
["track"] = "true",
["shared"] = "true",
["shared_lane"] = "true",
["sidepath"] = "true",
["share_busway"] = "true",
["allowed"] = "true",
["private"] = "true",
["cyclestreet"] = "true"
}
bike_reverse = {
["opposite"] = "true",
["opposite_lane"] = "true",
["opposite_track"] = "true"
}
bus_reverse = {
["opposite"] = "true",
["opposite_lane"] = "true"
}
shared = {
["shared_lane"] = 1,
["share_busway"] = 1,
["shared"] = 1
}
dedicated = {
["opposite_track"] = 2,
["track"] = 2
}
separated = {
["opposite_lane"] = 3,
["lane"] = 3
}
oneway = {
["no"] = "false",
["-1"] = "true",
["yes"] = "true",
["true"] = "true",
["1"] = "true"
}
bridge = {
["yes"] = "true",
["no"] = "false",
["1"] = "true"
}
--TODO: building_passage is for ped only
tunnel = {
["yes"] = "true",
["no"] = "false",
["1"] = "true",
["building_passage"] = "true"
}
--TODO: snowmobile might not really be passable for much other than ped..
toll = {
["yes"] = "true",
["no"] = "false",
["true"] = "true",
["false"] = "false",
["1"] = "true",
["interval"] = "true",
["snowmobile"] = "true"
}
--node proc needs the same info as above but in the form of a mask so duplicate..
motor_vehicle_node = {
["yes"] = 1,
["private"] = 1,
["no"] = 0,
["permissive"] = 1,
["agricultural"] = 0,
["delivery"] = 1,
["designated"] = 1,
["discouraged"] = 0,
["forestry"] = 0,
["destination"] = 1,
["customers"] = 1,
["official"] = 0,
["public"] = 1,
["restricted"] = 1,
["allowed"] = 1
}
bicycle_node = {
["yes"] = 4,
["designated"] = 4,
["use_sidepath"] = 4,
["no"] = 0,
["permissive"] = 4,
["destination"] = 4,
["dismount"] = 4,
["lane"] = 4,
["track"] = 4,
["shared"] = 4,
["shared_lane"] = 4,
["sidepath"] = 4,
["share_busway"] = 4,
["none"] = 0,
["allowed"] = 4,
["private"] = 4,
["official"] = 4
}
foot_node = {
["yes"] = 2,
["private"] = 2,
["no"] = 0,
["permissive"] = 2,
["agricultural"] = 0,
["use_sidepath"] = 2,
["delivery"] = 2,
["designated"] = 2,
["discouraged"] = 0,
["forestry"] = 0,
["destination"] = 2,
["customers"] = 2,
["official"] = 2,
["public"] = 2,
["restricted"] = 2,
["crossing"] = 2,
["sidewalk"] = 2,
["allowed"] = 2,
["passable"] = 2,
["footway"] = 2
}
wheelchair_node = {
["no"] = 0,
["yes"] = 256,
["designated"] = 256,
["limited"] = 256,
["official"] = 256,
["destination"] = 256,
["public"] = 256,
["permissive"] = 256,
["only"] = 256,
["private"] = 256,
["impassable"] = 0,
["partial"] = 0,
["bad"] = 0,
["half"] = 0,
["assisted"] = 256
}
bus_node = {
["no"] = 0,
["yes"] = 64,
["designated"] = 64,
["urban"] = 64,
["permissive"] = 64,
["restricted"] = 64,
["destination"] = 64,
["delivery"] = 0,
["official"] = 0,
}
truck_node = {
["designated"] = 8,
["yes"] = 8,
["no"] = 0,
["destination"] = 8,
["delivery"] = 8,
["local"] = 8,
["agricultural"] = 0,
["private"] = 8,
["discouraged"] = 0,
["permissive"] = 0,
["unsuitable"] = 0,
["agricultural;forestry"] = 0,
["official"] = 0,
["forestry"] = 0,
["destination;delivery"] = 8
}
psv_node = {
["bus"] = 64,
["no"] = 0,
["yes"] = 64,
["designated"] = 64,
["permissive"] = 64,
["1"] = 64,
["2"] = 64
}
function round(val, n)
if (n) then
return math.floor( (val * 10^n) + 0.5) / (10^n)
else
return math.floor(val+0.5)
end
end
--convert the numeric (non negative) number portion at the beginning of the string
function numeric_prefix(num_str, allow_decimals)
--not a string
if num_str == nil then
return nil
end
--find where the numbers stop
local index = 0
for c in num_str:gmatch"." do
if tonumber(c) == nil then
if c == "." then
if allow_decimals == false then
break
end
else
break
end
end
index = index + 1
end
--there weren't any numbers
if index == 0 then
return nil
end
--convert number portion of string to actual numeric type
return tonumber(num_str:sub(0, index))
end
--normalize a speed value
function normalize_speed(speed)
--grab the number prefix
local num = numeric_prefix(speed, false)
--check if the rest of the string ends in "mph" convert to kph
if num then
if speed:sub(-3) == "mph" then
num = round(num * 1.609344)
end
--if num > 150kph or num < 10kph....toss
if num > 150 or num < 10 then
return nil
end
end
return num
end
function normalize_weight(weight)
if weight then
local w = weight:gsub("%s+", "")
--grab the number prefix
local num = numeric_prefix(w, true)
if num then
if w:sub(-1) == "t" or w:sub(-5) == "tonne" or w:sub(-6) == "tonnes" then
if (num .. "t" == w) or (num .. "tonne" == w) or (num .. "tonnes" == w) then
return round(num,2)
end
end
if w:sub(-3) == "ton" or w:sub(-4) == "tons" then
if (num .. "ton" == w) or (num .. "tons" == w) then
return round(num,2)
end
end
if w:sub(-2) == "lb" or w:sub(-3) == "lbs" then
if (num .. "lb" == w) or (num .. "lbs" == w) then
return round((num/2000),2) -- convert to tons
end
end
if w:sub(-2) == "kg" then
if (num .. "kg" == w) then
return round((num/1000),2)
end
end
return round(num,2) --3.5
end
end
return nil
end
function normalize_measurement(measurement)
if measurement then
local m = measurement:gsub("%s+", "")
--7'6" or 7ft6in
--7m
--7
--grab the number prefix
local num = numeric_prefix(m, true)
if num then
if m:sub(-1) == "m" or m:sub(-5) == "meter" or m:sub(-6) == "meters" then
if (num .. "m" == m) or (num .. "meter" == m) or (num .. "meters" == m) then
return round(num,2)
end
end
local feet
local inches
if m:sub(-2) == "in" or m:sub(-1) == "\"" or m:sub(-6) == "inches" or m:sub(-4) == "inch" then
--have to check for inches only
if (num .. "in" == m) or (num .. "\"" == m) or (num .. "inches" == m) or (num .. "inch" == m) then
return round((num * 0.0254),2)
end
feet = num
m = string.sub(measurement, string.len(tostring(feet))+1)
local index = 0
for c in m:gmatch"." do
if tonumber(c) ~= nil then
break
end
index = index + 1
end
m = m:sub(index+1)
inches = numeric_prefix(m, true)
num = round((feet * 0.3048) + (inches * 0.0254),2)
elseif m:sub(-2) == "ft" or m:sub(-1) == "\'" or m:sub(-4) == "feet" then
feet = num
num = round((feet * 0.3048),2)
else
feet = num
m = string.sub(measurement, string.len(tostring(feet))+1)
local index = 0
for c in m:gmatch"." do
if tonumber(c) ~= nil then
break
end
index = index + 1
end
if index ~= 0 then
--crappy data case. 7'6 or 7ft6
m = m:sub(index+1)
inches = numeric_prefix(m, true)
if inches then
num = round((feet * 0.3048) + (inches * 0.0254),2)
else
num = round((feet * 0.3048),2)
end
end
end
return round(num,2)
end
end
return nil
end
--returns 1 if you should filter this way 0 otherwise
function filter_tags_generic(kv)
if (kv["highway"] == "construction" or kv["highway"] == "proposed") then
return 1
end
--figure out what basic type of road it is
local forward = highway[kv["highway"]]
local ferry = kv["route"] == "ferry"
local rail = kv["route"] == "shuttle_train"
local access = access[kv["access"]]
kv["emergency_forward"] = "false"
kv["emergency_backward"] = "false"
if (ferry == true or rail == true or kv["highway"]) then
if (kv["access"] == "emergency" or kv["emergency"] == "yes" or kv["service"] == "emergency_access") then
kv["emergency_forward"] = "true"
kv["emergency_tag"] = "true"
end
if kv["emergency"] == "no" then
kv["emergency_tag"] = "false"
end
end
if forward then
for k,v in pairs(forward) do
kv[k] = v
end
if kv["impassable"] == "yes" or access == "false" or (kv["access"] == "private" and (kv["emergency"] == "yes" or kv["service"] == "emergency_access")) then
kv["auto_forward"] = "false"
kv["truck_forward"] = "false"
kv["bus_forward"] = "false"
kv["pedestrian"] = "false"
kv["bike_forward"] = "false"
kv["auto_backward"] = "false"
kv["truck_backward"] = "false"
kv["bus_backward"] = "false"
kv["bike_backward"] = "false"
end
--check for auto_forward overrides
kv["auto_forward"] = motor_vehicle[kv["motorcar"]] or motor_vehicle[kv["motor_vehicle"]] or kv["auto_forward"]
kv["auto_tag"] = motor_vehicle[kv["motorcar"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for truck_forward override
kv["truck_forward"] = truck[kv["hgv"]] or motor_vehicle[kv["motor_vehicle"]] or kv["truck_forward"]
kv["truck_tag"] = truck[kv["hgv"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for bus_forward overrides
kv["bus_forward"] = bus[kv["bus"]] or psv[kv["psv"]] or psv[kv["lanes:psv:forward"]] or motor_vehicle[kv["motor_vehicle"]] or kv["bus_forward"]
kv["bus_tag"] = bus[kv["bus"]] or psv[kv["psv"]] or psv[kv["lanes:psv:forward"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for ped overrides
kv["pedestrian"] = foot[kv["foot"]] or foot[kv["pedestrian"]] or kv["pedestrian"]
kv["foot_tag"] = foot[kv["foot"]] or foot[kv["pedestrian"]] or nil
--check for bike_forward overrides
kv["bike_forward"] = bicycle[kv["bicycle"]] or cycleway[kv["cycleway"]] or bicycle[kv["bicycle_road"]] or bicycle[kv["cyclestreet"]] or kv["bike_forward"]
kv["bike_tag"] = bicycle[kv["bicycle"]] or cycleway[kv["cycleway"]] or bicycle[kv["bicycle_road"]] or bicycle[kv["cyclestreet"]] or nil
else
--if its a ferry and these tags dont show up we want to set them to true
local default_val = tostring(ferry)
if ferry == false and rail == true then
default_val = tostring(rail)
end
if ((ferry == false and rail == false) or kv["impassable"] == "yes" or access == "false" or (kv["access"] == "private" and (kv["emergency"] == "yes" or kv["service"] == "emergency_access"))) then
kv["auto_forward"] = "false"
kv["truck_forward"] = "false"
kv["bus_forward"] = "false"
kv["pedestrian"] = "false"
kv["bike_forward"] = "false"
kv["auto_backward"] = "false"
kv["truck_backward"] = "false"
kv["bus_backward"] = "false"
kv["bike_backward"] = "false"
default_val = "false"
else
--check for auto_forward overrides
kv["auto_forward"] = motor_vehicle[kv["motorcar"]] or motor_vehicle[kv["motor_vehicle"]] or default_val
kv["auto_tag"] = motor_vehicle[kv["motorcar"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for truck_forward override
kv["truck_forward"] = truck[kv["hgv"]] or kv["truck_forward"] or motor_vehicle[kv["motor_vehicle"]] or default_val
kv["truck_tag"] = truck[kv["hgv"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for bus_forward overrides
kv["bus_forward"] = bus[kv["bus"]] or psv[kv["psv"]] or psv[kv["lanes:psv:forward"]] or motor_vehicle[kv["motor_vehicle"]] or default_val
kv["bus_tag"] = bus[kv["bus"]] or psv[kv["psv"]] or psv[kv["lanes:psv:forward"]] or motor_vehicle[kv["motor_vehicle"]] or nil
--check for ped overrides
kv["pedestrian"] = foot[kv["foot"]] or foot[kv["pedestrian"]] or default_val
kv["foot_tag"] = foot[kv["foot"]] or foot[kv["pedestrian"]] or nil
--check for bike_forward overrides
kv["bike_forward"] = bicycle[kv["bicycle"]] or cycleway[kv["cycleway"]] or bicycle[kv["bicycle_road"]] or bicycle[kv["cyclestreet"]] or default_val
kv["bike_tag"] = bicycle[kv["bicycle"]] or cycleway[kv["cycleway"]] or bicycle[kv["bicycle_road"]] or bicycle[kv["cyclestreet"]] or nil
end
end
--TODO: handle Time conditional restrictions if available for HOVs with oneway = reversible
if ((kv["access"] == "permissive" or kv["access"] == "hov") and kv["oneway"] == "reversible") then
-- for now enable only for buses if the tag exists and they are allowed.
if (kv["bus_forward"] == "true") then
kv["auto_forward"] = "false"
kv["truck_forward"] = "false"
kv["pedestrian"] = "false"
kv["bike_forward"] = "false"
else
return 1
end
end
--service=driveway means all are routable
if kv["service"] == "driveway" and kv["access"] == nil then
kv["auto_forward"] = "true"
kv["truck_forward"] = "true"
kv["bus_forward"] = "true"
kv["pedestrian"] = "true"
kv["bike_forward"] = "true"
end
--check the oneway-ness and traversability against the direction of the geom
if ((kv["oneway"] == "yes" and kv["oneway:bicycle"] == "no") or kv["bicycle:backward"] == "yes" or kv["bicycle:backward"] == "no") then
kv["bike_backward"] = "true"
end
if kv["bike_backward"] == nil or kv["bike_backward"] == "false" then
kv["bike_backward"] = bike_reverse[kv["cycleway"]] or bike_reverse[kv["cycleway:left"]] or bike_reverse[kv["cycleway:right"]] or "false"
end
if kv["bike_backward"] == "true" then
oneway_bike = oneway[kv["oneway:bicycle"]]
if (oneway_bike == "false" and kv["bicycle:backward"] == "yes") then
oneway_bike = "true"
end
end
if ((kv["oneway"] == "yes" and kv["oneway:bus"] == "no") or kv["bus:backward"] == "yes" or kv["bus:backward"] == "designated") then
kv["bus_backward"] = "true"
end
if kv["bus_backward"] == nil or kv["bus_backward"] == "false" then
kv["bus_backward"] = bus_reverse[kv["busway"]] or bus_reverse[kv["busway:left"]] or bus_reverse[kv["busway:right"]] or psv[kv["lanes:psv:backward"]] or "false"
end
if kv["bus_backward"] == "true" then
oneway_bus = oneway[kv["oneway:bus"]]
if (oneway_bus == "false" and kv["bus:backward"] == "yes") then
oneway_bus = "true"
end
end
local oneway_reverse = kv["oneway"]
local oneway_norm = oneway[kv["oneway"]]
if kv["junction"] == "roundabout" then
oneway_norm = "true"
kv["roundabout"] = "true"
else
kv["roundabout"] = "false"
end
kv["oneway"] = oneway_norm
if oneway_norm == "true" then
kv["auto_backward"] = "false"
kv["truck_backward"] = "false"
kv["emergency_backward"] = "false"
if kv["bike_backward"] == "true" then
if (oneway_bike == "true") then --bike only in reverse on a bike path.
kv["bike_forward"] = "false"
elseif oneway_bike == "false" then --bike in both directions on a bike path.
kv["bike_forward"] = "true"
end
end
if kv["bus_backward"] == "true" then
if (oneway_bus == "true") then --bus only in reverse on a bus path.
kv["bus_forward"] = "false"
elseif oneway_bus == "false" then --bus in both directions on a bus path.
kv["bus_forward"] = "true"
end
end
elseif oneway_norm == nil or oneway_norm == "false" then
kv["auto_backward"] = kv["auto_forward"]
kv["truck_backward"] = kv["truck_forward"]
kv["emergency_backward"] = kv["emergency_forward"]
if (kv["bike_backward"] == "false" and kv["oneway:bicycle"] ~= "-1" and
(kv["oneway:bicycle"] == nil or oneway[kv["oneway:bicycle"]] == false)) then
kv["bike_backward"] = kv["bike_forward"]
end
if (kv["bus_backward"] == "false" and kv["oneway:bus"] ~= "-1" and
(kv["oneway:bus"] == nil or oneway[kv["oneway:bus"]] == false)) then
kv["bus_backward"] = kv["bus_forward"]
end
end
--Bike forward / backward overrides.
if ((shared[kv["cycleway:both"]] or separated[kv["cycleway:both"]] or dedicated[kv["cycleway:both"]]) or
((shared[kv["cycleway:right"]] or separated[kv["cycleway:right"]] or dedicated[kv["cycleway:right"]]) and
(shared[kv["cycleway:left"]] or separated[kv["cycleway:left"]] or dedicated[kv["cycleway:left"]]))) then
kv["bike_forward"] = "true"
kv["bike_backward"] = "true"
end
if (kv["busway"] == "lane" or (kv["busway:left"] == "lane" and kv["busway:right"] == "lane")) then
kv["bus_forward"] = "true"
kv["bus_backward"] = "true"
end
--flip the onewayness
if oneway_reverse == "-1" then
local forwards = kv["auto_forward"]
kv["auto_forward"] = kv["auto_backward"]
kv["auto_backward"] = forwards
forwards = kv["truck_forward"]
kv["truck_forward"] = kv["truck_backward"]
kv["truck_backward"] = forwards
forwards = kv["emergency_forward"]
kv["emergency_forward"] = kv["emergency_backward"]
kv["emergency_backward"] = forwards
forwards = kv["bus_forward"]
kv["bus_forward"] = kv["bus_backward"]
kv["bus_backward"] = forwards
forwards = kv["bike_forward"]
kv["bike_forward"] = kv["bike_backward"]
kv["bike_backward"] = forwards
end
if kv["oneway:bicycle"] == "-1" then
local forwards = kv["bike_forward"]
kv["bike_forward"] = kv["bike_backward"]
kv["bike_backward"] = forwards
end
if kv["oneway:bus"] == "-1" then
local forwards = kv["bus_forward"]
kv["bus_forward"] = kv["bus_backward"]
kv["bus_backward"] = forwards
end
-- bus only logic
if kv["lanes:bus"] == "1" then
kv["bus_forward"] = "true"
kv["bus_backward"] = "false"
elseif kv["lanes:bus"] == "2" then
kv["bus_forward"] = "true"
kv["bus_backward"] = "true"
end
--if none of the modes were set we are done looking at this
if kv["auto_forward"] == "false" and kv["truck_forward"] == "false" and kv["bus_forward"] == "false" and kv["bike_forward"] == "false" and kv["emergency_forward"] == "false" and
kv["auto_backward"] == "false" and kv["truck_backward"] == "false" and kv["bus_backward"] == "false" and kv["bike_backward"] == "false" and kv["emergency_backward"] == "false" and
kv["pedestrian"] == "false" then
if kv["highway"] ~= "bridleway" then --save bridleways for country access logic.
return 1
end
end
--toss actual areas
if kv["area"] == "yes" then
return 1
end
delete_tags = { 'FIXME', 'note', 'source' }
for i,k in ipairs(delete_tags) do
kv[k] = nil
end
--set a few flags
local road_class = road_class[kv["highway"]]
if kv["highway"] == nil and ferry then
road_class = 2 --TODO: can we weight based on ferry types?
elseif kv["highway"] == nil and (kv["railway"] or kv["route"] == "shuttle_train") then
road_class = 2 --TODO: can we weight based on rail types?
elseif road_class == nil then --service and other = 7
road_class = 7
end
kv["road_class"] = road_class
kv["default_speed"] = default_speed[kv["road_class"]]
--lower the default speed for driveways
if kv["service"] == "driveway" then
kv["default_speed"] = math.floor(tonumber(kv["default_speed"]) * 0.5)
end
local use = use[kv["service"]]
if kv["highway"] then
if kv["highway"] == "track" then
use = 3
elseif kv["highway"] == "cycleway" then
use = 20
elseif kv["pedestrian"] == "false" and kv["auto_forward"] == "false" and kv["auto_backward"] == "false" and (kv["bike_forward"] == "true" or kv["bike_backward"] == "true") then
use = 20
elseif (kv["highway"] == "footway" and kv["footway"] == "sidewalk") then
use = 24
elseif kv["highway"] == "footway" then
use = 25