-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcyclemaps.lua
More file actions
217 lines (164 loc) · 9.35 KB
/
cyclemaps.lua
File metadata and controls
217 lines (164 loc) · 9.35 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
-- override many of the defaults in process.lua
-- shift everything down and add cycleway to 4-7
z4RoadValues = Set { }
z5RoadValues = Set { "cycleway" }
-- there is no z6RoadValues
z7RoadValues = Set { "motorway", "trunk", "primary" }
-- add cyclefriendly to zoom 11
z11RoadValues = Set { "tertiary", "tertiary_link", "busway", "bus_guideway", "cyclefriendly" }
-- add bicycle_repair_station compressed_air drinking_water
poiTags["amenity"] = Set { "arts_centre", "bank", "bar", "bbq", "bicycle_parking", "bicycle_rental", "bicycle_repair_station", "biergarten", "bus_station", "cafe", "cinema", "clinic", "college", "community_centre", "compressed_air", "courthouse", "dentist", "doctors", "drinking_water", "embassy", "fast_food", "ferry_terminal", "fire_station", "food_court", "fuel", "grave_yard", "hospital", "ice_cream", "kindergarten", "library", "marketplace", "motorcycle_parking", "nightclub", "nursing_home", "parking", "pharmacy", "place_of_worship", "police", "post_box", "post_office", "prison", "pub", "public_building", "recycling", "restaurant", "school", "shelter", "swimming_pool", "taxi", "telephone", "theatre", "toilets", "townhall", "university", "veterinary", "waste_basket" }
-- REMOVE cycleway from pathValues
pathValues = Set { "footway", "bridleway", "path", "steps", "pedestrian", "platform" }
-- create poiRanks variable
poiRanks = { bicycle=2, bicycle_repair_station=4, compressed_air=5, toilet=5, drinking_water=5, bicycle_rental=5, bicycle_parking=6 }
function IsCycleway(highway)
if highway == "construction" then return false end
local bicycle = Find("bicycle")
if bicycle == "no" or bicycle == "private" or bicycle == "permit" then
return false
end
local cycleway = Find("cycleway")
local cyclewayLeft = Find("cycleway:left")
local cyclewayRight = Find("cycleway:right")
local cyclewayBoth = Find("cycleway:both")
if cycleway == "separate" or cyclewayLeft == "separate" or cyclewayRight == "separate" or cyclewayBoth == "separate" then
return false
end
if highway == "cycleway" then return true end
local mtb = Find("mtb:scale")
if mtb ~= "" and mtb ~= "6" or
Holds("mtb:scale:imba") or Holds("mtb:type") or bicycle == "mtb" or Find("route") == "mtb" then
return true
end
if cycleway == "lane" or cycleway == "opposite_lane" or cycleway == "opposite" or cycleway == "share_busway" or cycleway == "opposite_share_busway" or cycleway == "shared" or cycleway == "track" or cycleway == "opposite_track" or
cyclewayLeft == "lane" or cyclewayLeft == "opposite_lane" or cyclewayLeft == "opposite" or cyclewayLeft == "share_busway" or cyclewayLeft == "opposite_share_busway" or cyclewayLeft == "shared" or cyclewayLeft == "track" or cyclewayLeft == "opposite_track" or
cyclewayRight == "lane" or cyclewayRight == "opposite_lane" or cyclewayRight == "opposite" or cyclewayRight == "share_busway" or cyclewayRight == "opposite_share_busway" or cyclewayRight == "shared" or cyclewayRight == "track" or cyclewayRight == "opposite_track" or
cyclewayBoth == "lane" or cyclewayBoth == "opposite_lane" or cyclewayBoth == "opposite" or cyclewayBoth == "share_busway" or cyclewayBoth == "opposite_share_busway" or cyclewayBoth == "shared" or cyclewayBoth == "track" or cyclewayBoth == "opposite_track" then
return true
end
if Find("oneway") == "yes" and Find("oneway:bicycle") == "no" then return true end
local unpaved = GetSurface() == "unpaved"
if unpaved or highway == "pedestrian" or highway == "living_street" or highway == "path" or highway == "footway" or highway == "steps" or highway == "bridleway" or highway == "corridor" or highway == "track" then
-- special logic for sidewalks: bicycle=yes is enough for CycleFriendly but not Cycleway unless it's unpaved or 3m wide
local width = tonumber(Find("width"))
if bicycle == "yes" and (unpaved or width ~= nil and width >= 3 or highway ~= "footway" or Find("footway") ~= "sidewalk") then
return true
end
if bicycle == "permissive" or bicycle == "customers" or bicycle == "designated" or
Holds("ramp:bicycle") and Find("ramp:bicycle") ~= "no" or
GetCycleRouteType() ~= "" then
return true
end
end
-- todo sport can have multiple values. match against (;|^)cycling(;|$)
if Find("sport") == "cycling" then return true end
return false
end
-- 60kph is 37.3mph
function IsMaxSpeedLow(maxSpeed)
return maxSpeed ~= nil and maxSpeed <= 60
end
-- there's like, a lot of room, or we're not sure how wide it is
function IsWideOrUnknown()
local lanes = tonumber(Find("lanes"))
-- we're not sure how wide it is, or there's 3+ lanes
if lanes == nil or lanes < 1 or lanes > 2 then return true end
local oneway = Find("oneway")
-- it's one way and there are 2+ lanes
if oneway == "yes" and lanes > 1 then return true end
-- 3.75m is 12.3 feet
local width = tonumber(Find("width"))
if width ~= nil and (lanes == 1 and width < 3.75 or lanes == 2 and width < 7.5) then return false end
local width = tonumber(Find("width:carriageway"))
if width ~= nil and (lanes == 1 and width < 3.75 or lanes == 2 and width < 7.5) then return false end
return true
end
-- 40kph is 24.8mph
function IsMaxSpeedVeryLow(maxSpeed)
return maxSpeed ~= nil and maxSpeed <= 40
end
function GetMaxSpeed()
local maxSpeed = Find("maxspeed")
local maxSpeed, count = string.gsub(maxSpeed, " ?mph", "")
if count > 0 then
local maxSpeed = tonumber(maxSpeed)
if maxSpeed ~= nil then return maxSpeed * 1.609344 else return nil end
end
local maxSpeed, count = string.gsub(maxSpeed, " ?kph", "")
return tonumber(maxSpeed)
end
function IsCycleFriendly(highway)
if highway == "construction" then return false end
local bicycle = Find("bicycle")
if bicycle == "no" or bicycle == "private" or bicycle == "permit" then return false end
if Find("cycleway") == "separate" or
Find("cycleway:left") == "separate" or
Find("cycleway:right") == "separate" or
Find("cycleway:both") == "separate" then return false end
if bicycle == "customers" or bicycle == "designated" then return true end
if Find("cycleway") == "shared_lane" or
Find("cycleway:left") == "shared_lane" or
Find("cycleway:right") == "shared_lane" or
Find("cycleway:both") == "shared_lane" then return true end
if GetCycleRouteType() ~= "" then return true end
if bicylce == "dismount" then
return true
end
if bicycle == "yes" or bicycle == "permissive" then
local maxSpeed = GetMaxSpeed()
if highway == "residential" or highway == "service" or highway == "unclassified" or
IsMaxSpeedLow(maxSpeed) and IsWideOrUnknown() or
IsMaxSpeedVeryLow(maxSpeed) then
return true
end
end
-- special logic for sidewalks: bicycle=yes is enough for CycleFriendly but not Cycleway
if bicycle == "yes" and highway == "footway" and Find("footway") == "sidewalk" then
return true
end
return false
end
-- run GetSurface() instead: this only gets run if nothing useful was found in the surface field
function GetSurfaceHelper()
local highway = Find("highway")
local smoothness = Find("smoothness")
if smoothness == "excellent" or smoothness == "good" or Holds("crossing") or Find("footway") == "crossing" or Find("footway") == "access_aisle" then return "paved"
elseif Holds("mtb:scale") or Holds("mtb:scale:imba") or Holds("mtb:type") or Find("bicycle") == "mtb" or Find("route") == "mtb" then return "unpaved"
elseif highway == "motorway" or highway == "trunk" or highway == "primary" or highway == "secondary" or highway == "tertiary" or highway == "unclassified" or highway == "residential" or highway == "living_street" or highway == "road" or highway == "service" or highway == "motorway_link" or highway == "trunk_link" or highway == "primary_link" or highway == "secondary_link" or highway == "tertiary_link" or highway == "raceway" or highway == "steps" or highway == "cycleway" then return "paved"
elseif highway == "track" or Holds("tracktype") and Find("tracktype") ~= "grade1" then return "unpaved"
elseif smoothness == "very_bad" or smoothness == "horrible" or smoothness == "very_horrible" or smoothness == "impassible" then return "unpaved"
elseif Holds("hiking") and Find("hiking") ~= "no" then return "unpaved"
elseif Holds("sac_scale") and Find("sac_scale") ~= "strolling" then return "unpaved"
end
return ""
end
-- scan a route that is type==route and (route==bicycle or route==mtb)
function ScanCycleRoute()
-- see tilemaker/docs/RELATIONS.md . . . when Accept() is called, the relation data is added to FindInRelation for the ways
Accept()
end
-- see ScanCycleRoute() above for how these values are added to the ways
function GetCycleRouteType()
-- also check the legacy tags?
-- using a variable here so we can reset the relations
local routeType = ""
while true do
local relationId = NextRelation()
if not relationId then break end
if FindInRelation("icn") == "yes" or FindInRelation("icn_ref") ~= "" then routeType="icn"; break end
if FindInRelation("ncn") == "yes" or FindInRelation("ncn_ref") ~= "" then routeType="ncn"; break end
if FindInRelation("rcn") == "yes" or FindInRelation("rcn_ref") ~= "" then routeType="rcn"; break end
if FindInRelation("lcn") == "yes" or FindInRelation("lcn_ref") ~= "" then routeType="lcn"; break end
if FindInRelation("route") == "bicycle" then routeType="bicycle"; break end
end
RestartRelations()
return routeType
end
function CycleRouteLayer()
Layer("cycleroute", false)
Attribute("type", GetCycleRouteType())
Attribute("class", Find("network"))
Attribute("ref", Find("ref"))
Attribute("name", Find("name"))
end