@@ -12,24 +12,24 @@ ignore_in_grid = { ["ferry"] = true }
1212restriction_exception_tags = { " motorcar" , " motor_vehicle" , " vehicle" }
1313
1414speed_profile = {
15- [" motorway" ] = 90 ,
16- [" motorway_link" ] = 75 ,
17- [" trunk" ] = 85 ,
18- [" trunk_link" ] = 70 ,
19- [" primary" ] = 65 ,
20- [" primary_link" ] = 60 ,
21- [" secondary" ] = 55 ,
22- [" secondary_link" ] = 50 ,
23- [" tertiary" ] = 40 ,
24- [" tertiary_link" ] = 30 ,
25- [" unclassified" ] = 25 ,
26- [" residential" ] = 25 ,
27- [" living_street" ] = 10 ,
28- [" service" ] = 15 ,
15+ [" motorway" ] = 90 ,
16+ [" motorway_link" ] = 75 ,
17+ [" trunk" ] = 85 ,
18+ [" trunk_link" ] = 70 ,
19+ [" primary" ] = 65 ,
20+ [" primary_link" ] = 60 ,
21+ [" secondary" ] = 55 ,
22+ [" secondary_link" ] = 50 ,
23+ [" tertiary" ] = 40 ,
24+ [" tertiary_link" ] = 30 ,
25+ [" unclassified" ] = 25 ,
26+ [" residential" ] = 25 ,
27+ [" living_street" ] = 10 ,
28+ [" service" ] = 15 ,
2929-- ["track"] = 5,
30- [" ferry" ] = 5 ,
31- [" shuttle_train" ] = 10 ,
32- [" default" ] = 50
30+ [" ferry" ] = 5 ,
31+ [" shuttle_train" ] = 10 ,
32+ [" default" ] = 50
3333}
3434
3535take_minimum_of_speeds = false
@@ -43,171 +43,158 @@ u_turn_penalty = 20
4343-- End of globals
4444
4545function get_exceptions (vector )
46- for i ,v in ipairs (restriction_exception_tags ) do
47- vector :Add (v )
48- end
49- end
50-
51- local function parse_maxspeed (source )
52- if source == nil then
53- return 0
54- end
55- local n = tonumber (source :match (" %d*" ))
56- if n == nil then
57- n = 0
58- end
59- if string.match (source , " mph" ) or string.match (source , " mp/h" ) then
60- n = (n * 1609 )/ 1000 ;
61- end
62- return math.abs (n )
46+ for i ,v in ipairs (restriction_exception_tags ) do
47+ vector :Add (v )
48+ end
6349end
6450
6551function node_function (node )
66- local barrier = node .tags :Find (" barrier" )
67- local access = Access .find_access_tag (node , access_tags_hierachy )
68- local traffic_signal = node .tags :Find (" highway" )
69-
70- -- flag node if it carries a traffic light
71-
72- if traffic_signal == " traffic_signals" then
73- node .traffic_light = true ;
52+ local barrier = node .tags :Find (" barrier" )
53+ local access = Access .find_access_tag (node , access_tags_hierachy )
54+ local traffic_signal = node .tags :Find (" highway" )
55+
56+ -- flag node if it carries a traffic light
57+
58+ if traffic_signal == " traffic_signals" then
59+ node .traffic_light = true ;
60+ end
61+
62+ -- parse access and barrier tags
63+ if access and access ~= " " then
64+ if access_tag_blacklist [access ] then
65+ node .bollard = true
66+ end
67+ elseif barrier and barrier ~= " " then
68+ if barrier_whitelist [barrier ] then
69+ return
70+ else
71+ node .bollard = true
72+ end
7473 end
75-
76- -- parse access and barrier tags
77- if access and access ~= " " then
78- if access_tag_blacklist [access ] then
79- node .bollard = true
80- end
81- elseif barrier and barrier ~= " " then
82- if barrier_whitelist [barrier ] then
83- return
84- else
85- node .bollard = true
86- end
87- end
88- return 1
74+ return 1
8975end
9076
9177
9278function way_function (way , numberOfNodesInWay )
9379
94- -- A way must have two nodes or more
95- if (numberOfNodesInWay < 2 ) then
96- return 0 ;
80+ -- A way must have two nodes or more
81+ if (numberOfNodesInWay < 2 ) then
82+ return 0 ;
83+ end
84+
85+ -- First, get the properties of each way that we come across
86+ local highway = way .tags :Find (" highway" )
87+ local name = way .tags :Find (" name" )
88+ local ref = way .tags :Find (" ref" )
89+ local junction = way .tags :Find (" junction" )
90+ local route = way .tags :Find (" route" )
91+ local maxspeed = parseMaxspeed (way .tags :Find ( " maxspeed" ) )
92+ local barrier = way .tags :Find (" barrier" )
93+ local oneway = way .tags :Find (" oneway" )
94+ local cycleway = way .tags :Find (" cycleway" )
95+ local duration = way .tags :Find (" duration" )
96+ local service = way .tags :Find (" service" )
97+ local area = way .tags :Find (" area" )
98+ local access = Access .find_access_tag (way , access_tags_hierachy )
99+
100+ -- Second, parse the way according to these properties
101+
102+ if ignore_areas and (" yes" == area ) then
103+ return 0
104+ end
105+
106+ -- Check if we are allowed to access the way
107+ if access_tag_blacklist [access ] then
108+ return 0
97109 end
98-
99- -- First, get the properties of each way that we come across
100- local highway = way .tags :Find (" highway" )
101- local name = way .tags :Find (" name" )
102- local ref = way .tags :Find (" ref" )
103- local junction = way .tags :Find (" junction" )
104- local route = way .tags :Find (" route" )
105- local maxspeed = parse_maxspeed (way .tags :Find ( " maxspeed" ) )
106- local barrier = way .tags :Find (" barrier" )
107- local oneway = way .tags :Find (" oneway" )
108- local cycleway = way .tags :Find (" cycleway" )
109- local duration = way .tags :Find (" duration" )
110- local service = way .tags :Find (" service" )
111- local area = way .tags :Find (" area" )
112- local access = Access .find_access_tag (way , access_tags_hierachy )
113-
114- -- Second, parse the way according to these properties
115-
116- if ignore_areas and (" yes" == area ) then
117- return 0
118- end
119-
120- -- Check if we are allowed to access the way
121- if access_tag_blacklist [access ] then
122- return 0
123- end
124110
125- -- Set the name that will be used for instructions
126- if " " ~= ref then
127- way .name = ref
128- elseif " " ~= name then
129- way .name = name
111+ -- Set the name that will be used for instructions
112+ if " " ~= ref then
113+ way .name = ref
114+ elseif " " ~= name then
115+ way .name = name
130116-- else
131117-- way.name = highway -- if no name exists, use way type
132- end
133-
134- if " roundabout" == junction then
135- way .roundabout = true ;
136- end
137-
138- -- Handling ferries and piers
139- if (speed_profile [route ] ~= nil and speed_profile [route ] > 0 ) then
140- if durationIsValid (duration ) then
141- way .duration = math.max ( parseDuration (duration ), 1 );
142- end
143- way .direction = Way .bidirectional
144- if speed_profile [route ] ~= nil then
145- highway = route ;
146- end
147- if tonumber (way .duration ) < 0 then
148- way .speed = speed_profile [highway ]
149- end
150- end
151-
152- -- Set the avg speed on the way if it is accessible by road class
153- if (speed_profile [highway ] ~= nil and way .speed == - 1 ) then
154- if 0 == maxspeed then
155- maxspeed = math.huge
156- end
157- way .speed = math.min (speed_profile [highway ], maxspeed )
158- end
159-
160- -- Set the avg speed on ways that are marked accessible
161- if " " ~= highway and access_tag_whitelist [access ] and way .speed == - 1 then
162- if 0 == maxspeed then
163- maxspeed = math.huge
164- end
165- way .speed = math.min (speed_profile [" default" ], maxspeed )
166- end
167-
168- if durationIsValid (duration ) then
169- way .duration = math.max ( parseDuration (duration ), 1 );
170- end
171-
118+ end
119+
120+ if " roundabout" == junction then
121+ way .roundabout = true ;
122+ end
172123
173- -- Set access restriction flag if access is allowed under certain restrictions only
174- if access ~= " " and access_tag_restricted [access ] then
175- way .is_access_restricted = true
124+ -- Handling ferries and piers
125+ if (speed_profile [route ] ~= nil and speed_profile [route ] > 0 ) then
126+ if durationIsValid (duration ) then
127+ way .duration = math.max ( parseDuration (duration ), 1 );
128+ end
129+ way .direction = Way .bidirectional
130+ if speed_profile [route ] ~= nil then
131+ highway = route ;
132+ end
133+ if tonumber (way .duration ) < 0 then
134+ way .speed = speed_profile [highway ]
135+ end
136+ end
137+
138+ -- Set the avg speed on the way if it is accessible by road class
139+ if (speed_profile [highway ] ~= nil and way .speed == - 1 ) then
140+ if maxspeed > speed_profile [highway ] then
141+ way .speed = maxspeed
142+ else
143+ if 0 == maxspeed then
144+ maxspeed = math.huge
145+ end
146+ way .speed = math.min (speed_profile [highway ], maxspeed )
176147 end
148+ end
149+
150+ -- Set the avg speed on ways that are marked accessible
151+ if " " ~= highway and access_tag_whitelist [access ] and way .speed == - 1 then
152+ if 0 == maxspeed then
153+ maxspeed = math.huge
154+ end
155+ way .speed = math.min (speed_profile [" default" ], maxspeed )
156+ end
157+
158+ if durationIsValid (duration ) then
159+ way .duration = math.max ( parseDuration (duration ), 1 );
160+ end
177161
178- -- Set access restriction flag if service is allowed under certain restrictions only
179- if service ~= " " and service_tag_restricted [service ] then
180- way .is_access_restricted = true
181- end
182-
183- -- Set direction according to tags on way
184- if obey_oneway then
185- if oneway == " no" or oneway == " 0" or oneway == " false" then
186- way .direction = Way .bidirectional
187- elseif oneway == " -1" then
188- way .direction = Way .opposite
189- elseif oneway == " yes" or oneway == " 1" or oneway == " true" or junction == " roundabout" or highway == " motorway_link" or highway == " motorway" then
190- way .direction = Way .oneway
191- else
192- way .direction = Way .bidirectional
193- end
194- else
195- way .direction = Way .bidirectional
196- end
197-
198- -- Override general direction settings of there is a specific one for our mode of travel
162+ -- Set access restriction flag if access is allowed under certain restrictions only
163+ if access ~= " " and access_tag_restricted [access ] then
164+ way .is_access_restricted = true
165+ end
166+
167+ -- Set access restriction flag if service is allowed under certain restrictions only
168+ if service ~= " " and service_tag_restricted [service ] then
169+ way .is_access_restricted = true
170+ end
199171
200- if ignore_in_grid [highway ] ~= nil and ignore_in_grid [highway ] then
201- way .ignore_in_grid = true
202- end
203- way .type = 1
204- return 1
172+ -- Set direction according to tags on way
173+ if obey_oneway then
174+ if oneway == " no" or oneway == " 0" or oneway == " false" then
175+ way .direction = Way .bidirectional
176+ elseif oneway == " -1" then
177+ way .direction = Way .opposite
178+ elseif oneway == " yes" or oneway == " 1" or oneway == " true" or junction == " roundabout" or highway == " motorway_link" or highway == " motorway" then
179+ way .direction = Way .oneway
180+ else
181+ way .direction = Way .bidirectional
182+ end
183+ else
184+ way .direction = Way .bidirectional
185+ end
186+
187+ -- Override general direction settings of there is a specific one for our mode of travel
188+ if ignore_in_grid [highway ] ~= nil and ignore_in_grid [highway ] then
189+ way .ignore_in_grid = true
190+ end
191+ way .type = 1
192+ return 1
205193end
206194
207195-- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT
208-
209196function node_vector_function (vector )
210- for v in vector .nodes do
211- node_function (v )
212- end
197+ for v in vector .nodes do
198+ node_function (v )
199+ end
213200end
0 commit comments