-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhab.lua
executable file
·412 lines (353 loc) · 12.7 KB
/
hab.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
-- YOU CAN NAME YOUR LAYERS WHATEVER YOU WANT
-- AS LONG AS THEY'RE NAMED THE SAME IN: CONFIG.JSON PROCESS.LUA AND JAVASCRIPT-STYLE
-- https://taginfo.openstreetmap.org/keys
node_keys = {
-- "Aerialway",
-- "Aeroway",
-- "Amenity",
-- "Barrier",
-- "Boundary",
-- "building",
-- "Craft",
-- "Emergency",
-- "Geological",
-- "Highway",
-- "Historic",
-- "Common Landuse Key Values",
-- "Other Landuse Key Values",
-- "Leisure",
-- "Man_made",
-- "Military",
-- "natural",
-- "Office",
"place",
-- "Power",
-- "Public Transport",
-- "Railway",
-- "Route",
-- "Shop",
-- "Sport",
-- "Telecom",
-- "Tourism",
-- "Waterway"
}
-- count number of elements of each type
G_COUNTS = {}
function init_function()
end
local function is_in (val, tab)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
function exit_function()
-- print number of elements of each type
for _k,_v in pairs(G_COUNTS)
do
print("\n")
print(_k)
for k,v in pairs(_v)
do
print("\t", k, v)
end
end
end
function node_function(node)
local place = node:Find("place")
local capital = node:Find("capital")
local admin_level = node:Find("admin_level")
local name = node:Find("name")
local aeroway = node:Find("aeroway")
-- local shop = node:Find("shop")
-- local amenity = node:Find("amenity")
-- place
if place ~= nil and place ~= "" then
node:Layer("place_label", false)
node:Attribute("name",name)
-- the main field for styling labels for different kinds of places is type.
-- possible values: 'city','town','village','hamlet','suburb','neighbourhood'
node:Attribute("type",place)
--The capital field allows distinct styling of labels or icons for the capitals of countries, regions, or states & provinces.
-- 2=National capital, 3=Regional capital (uncommon), 4=State/provincial capital
if capital ~="" then
if admin_level == 2 then
node:AttributeNumeric("capital",2)
end
if admin_level == 4 then
node:AttributeNumeric("capital",4)
end
end
-- The value number from 0 through 9, where 0 is the large end of the scale (eg New York City).
-- All places other than large cities will have a scalerank of null.
if place == "village" then
node:AttributeNumeric("scalerank",3)
end
if place == "town" then
node:AttributeNumeric("scalerank",5)
end
if place == "suburb" then
node:AttributeNumeric("scalerank",7)
end
if place == "city" then
node:AttributeNumeric("scalerank",9)
end
-- Therefore to reduce the label density to 4 labels per tile, you can add the filter [localrank=1].
node:AttributeNumeric("localrank",1)
-- The ldir field can be used as a hint for label offset directions at lower zoom levels.
node:Attribute("ldir","N")
end
end
-- the name "way_function" may be a little misleading at first
-- it handles not only ways, but anything that actually is a geometry of type "LINE" or "POLYGON"
-- ie. woods, parks, buildings ...
function way_function(way)
local layer = nil
local name = way:Find("name");
-- highway
local highway = way:Find("highway")
if highway ~= nil and highway ~= "" then
local class = highway
if G_COUNTS["highway"] == nil then G_COUNTS["highway"] = {} end
if G_COUNTS["highway"][class] == nil then G_COUNTS["highway"][class] = 0 end
if is_in( class, { "motorway", "trunk", "primary", "motorway_link", "trunk_link", "primary_link" } ) then
layer = "road_main"
way:Layer(layer, false)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["highway"][class] = G_COUNTS["highway"][class] + 1
end
if is_in( class, { "secondary", "road", "secondary_link", "road_link" } ) then
layer = "road_secondary"
way:Layer(layer, false)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["highway"][class] = G_COUNTS["highway"][class] + 1
end
if is_in( class, { "tertiary", "tertiary_link" } )
then
layer = "road_tertiary"
way:Layer(layer, false)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["highway"][class] = G_COUNTS["highway"][class] + 1
end
if is_in( class, {
"track",
"proposed",
"service",
-- "planned",
"residential",
"unclassified",
"living_street",
"path",
-- "yes",
-- "services",
-- "raceway",
-- "pedestrian",
-- "trunk",
-- "corridor",
"crossing"
-- "bus_stop",
-- "bridleway",
-- "platform",
-- "elevator",
-- "footway",
-- "steps",
-- "construction",
-- "rest_area",
-- "cycleway",
-- "abandoned",
-- "no",
} ) then
layer = "road_other"
way:Layer(layer, false)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["highway"][class] = G_COUNTS["highway"][class] + 1
end
end
-- road_label layer
if highway ~= nil and highway ~= "" and name ~= "" then
way:Layer("road_label", false)
way:Attribute("name",name)
if way:Find("ref") ~="" then
way:Attribute("ref",way:Find("ref"))
way:AttributeNumeric("reflen", string.len(way:Find("ref")))
end
way:AttributeNumeric("osm_id",tonumber(way:Id()))
way:Attribute("shield","default")
way:AttributeNumeric("len", 100)
way:AttributeNumeric("localrank", 3)
--"class","len","localrank","name","name_de","name_en","name_es","name_fr","name_ru","name_zh","osm_id","ref","reflen","shield"
--way:AttributeBoolean("oneway": "false")
if highway=="residential" then way:Attribute("class","street") end
if highway=="primary" or highway=="secondary" or highway=="tertiary" then
way:Attribute("class","main")
end
if highway=="primary_link" or highway=="secondary_link" then
way:Attribute("class","street")
end
end
-- -- route
-- local route = way:Find("route")
-- if route ~= nil and route ~= "" then
-- local class = route
-- if G_COUNTS["route"] == nil then G_COUNTS["route"] = {} end
-- if G_COUNTS["route"][class] == nil then G_COUNTS["route"][class] = 0 end
-- -- if is_in( class, { "wood", "scrub", "heath", "grassland", "fell", "bare_rock", "scree", "shingle", "sand", "mud" } )
-- layer = "route"
-- way:Layer(layer, false)
-- way:Attribute("class", class)
-- G_COUNTS["route"][class] = G_COUNTS["route"][class] + 1
-- end
-- building
local building = way:Find("building")
if building ~= nil and building ~= "" then
local class = building
if G_COUNTS["building"] == nil then G_COUNTS["building"] = {} end
if G_COUNTS["building"][class] == nil then G_COUNTS["building"][class] = 0 end
layer = "building"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["building"][class] = G_COUNTS["building"][class] + 1
end
-- landuse
local landuse = way:Find("landuse")
if landuse ~= nil and landuse ~= "" then
local class = landuse
if G_COUNTS["landuse"] == nil then G_COUNTS["landuse"] = {} end
if G_COUNTS["landuse"][class] == nil then G_COUNTS["landuse"][class] = 0 end
-- if is_in( class, { "wood", "scrub", "heath", "grassland", "fell", "bare_rock", "scree", "shingle", "sand", "mud" } )
layer = "landuse"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["landuse"][class] = G_COUNTS["landuse"][class] + 1
end
-- Natural
local natural = way:Find("natural")
if natural ~= nil and natural ~= "" then
local class = natural
if G_COUNTS["natural"] == nil then G_COUNTS["natural"] = {} end
if G_COUNTS["natural"][class] == nil then G_COUNTS["natural"][class] = 0 end
-- if is_in( class, { "wood", "forest", "scrub", "heath", "grassland", "fell", "bare_rock", "scree", "shingle", "sand", "mud" } )
if is_in( class, { "wood", "forest", "scrub" } ) then -- just higher trees
layer = "wood"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
elseif is_in( class, { "heath", "grassland", "fell" } ) then
layer = "bush"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
elseif is_in( class, { "bare_rock", "scree", "shingle", "sand", "meadow" } ) then
layer = "soil"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
elseif is_in( class, { "water", "wetland", "bay" } )then
layer = "water"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
elseif is_in( class, { "mud" } )then
layer = "mud"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
else
layer = "natural_other"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["natural"][class] = G_COUNTS["natural"][class] + 1
end
end
-- waterway
local waterway = way:Find("waterway")
if waterway ~= nil and waterway ~= "" then
local class = waterway
if G_COUNTS["waterway"] == nil then G_COUNTS["waterway"] = {} end
if G_COUNTS["waterway"][class] == nil then G_COUNTS["waterway"][class] = 0 end
-- if is_in( class, { "yes", "water", "river", "riverbank", "stream", "reservoir", "moat", "pond", "canal" } )
if is_in( class, { "yes", "water", "riverbank", "reservoir", "moat", "pond", "canal" } ) then
layer = "water"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["waterway"][class] = G_COUNTS["waterway"][class] + 1
elseif is_in( class, { "river", "stream", "canal" } ) then
layer = "river"
way:Layer(layer, false)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["waterway"][class] = G_COUNTS["waterway"][class] + 1
end
end
-- aeroway
local aeroway = way:Find("aeroway")
if aeroway ~= nil and aeroway ~= "" then
local class = aeroway
if G_COUNTS["aeroway"] == nil then G_COUNTS["aeroway"] = {} end
if G_COUNTS["aeroway"][class] == nil then G_COUNTS["aeroway"][class] = 0 end
if is_in( class, { "aerodrome", "apron"} )then
layer = "aeroway"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["aeroway"][class] = G_COUNTS["aeroway"][class] + 1
else
layer = "aeroway_other"
way:Layer(layer, true)
way:Attribute("class", class)
if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["aeroway"][class] = G_COUNTS["aeroway"][class] + 1
end
end
-- boundary
-- local boundary = way:Find("boundary")
-- if boundary ~= nil and boundary == "administrative" then
-- local class = boundary
-- local admin_level = way:Find("admin_level")
-- if G_COUNTS["admin_level"] == nil then G_COUNTS["admin_level"] = {} end
-- if admin_level ~= nil and admin_level ~= "" then
-- if G_COUNTS["boundary"] == nil then G_COUNTS["boundary"] = {} end
-- if G_COUNTS["boundary"][class] == nil then G_COUNTS["boundary"][class] = 0 end
-- if G_COUNTS["admin_level"][admin_level] == nil then G_COUNTS["admin_level"][admin_level] = 0 end
-- G_COUNTS["admin_level"][admin_level] = G_COUNTS["admin_level"][admin_level] + 1
-- layer = "admin"
-- way:Layer(layer, false)
-- way:Attribute("class", class)
-- if name ~= nil and name ~= "" then
-- way:Attribute("name",name)
-- end
-- way:AttributeNumeric("admin_level", admin_level)
-- G_COUNTS["boundary"][class] = G_COUNTS["boundary"][class] + 1
-- end -- admin level
-- end
-- railway
local railway = way:Find("railway")
if railway ~= nil and railway == "rail" then
local class = railway
if G_COUNTS["railway"] == nil then G_COUNTS["railway"] = {} end
if G_COUNTS["railway"][class] == nil then G_COUNTS["railway"][class] = 0 end
layer = "railway"
way:Layer(layer, false)
way:Attribute("class", class)
-- if name ~= nil and name ~= "" then way:Attribute("name",name) end
G_COUNTS["railway"][class] = G_COUNTS["railway"][class] + 1
end
if layer == nil then
-- way:Layer("default", false)
end
end