forked from shortbread-tiles/shortbread-tilemaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.lua
1179 lines (1112 loc) · 35.1 KB
/
process.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
-- SPDX-License-Identifier: FTWPL
-- Data processing for Geofabrik Vector Tiles schema
-- Copyright (c) 2021, Geofabrik GmBH
-- Licensed under FTWPL
-- Enter/exit Tilemaker
function init_function()
end
function exit_function()
end
node_keys = { "place", "highway", "railway", "aeroway", "amenity", "aerialway", "shop", "leisure", "tourism", "man_made", "historic", "emergency", "office", "addr:housenumber", "addr:housename" }
-- Management of accepted key-value pairs for the "pois" layer.
-- We write only whitelisted tags to the shape file.
-- A table listing all OSM values accepted for a given OSM key.
-- This is implemented by using the OSM values as keys in the Lua table and assigning the value true to them.
function Set(list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
-- Check if provided OSM tag value is accepted. If true, return it. If false, return nil.
---- We return an empty string because Tilemaker cannot write NULL values into vector tiles.
function valueAcceptedOrNil(set, osm_value)
if set[osm_value] then
return osm_value
end
return nil
end
function nilToEmptyStr(arg)
if arg == nil then
return ""
end
return arg
end
-- Process node tags
poi_amenity_values = Set { "police", "fire_station", "post_box", "post_office", "telephone",
"library", "townhall", "courthouse", "prison", "embassy", "community_centre", "nursing_home",
"arts_centre", "grave_yard", "marketplace", "recycling", "university", "school", "college", "public_building",
"pharmacy", "hospital", "clinic", "doctors", "dentist", "veterinary", "theatre", "nightclub", "cinema",
"restaurant", "fast_food", "cafe", "pub", "bar", "foot_court", "biergarten", "shelter",
"car_rental", "car_wash", "car_sharing", "bicycle_rental", "vending_machine", "bank", "atm",
"toilets", "bench", "drinking_water", "fountain", "hunting_stand", "waste_basket", "place_of_worship" }
catering_values = Set { "restaurant", "fast_food", "pub", "bar", "cafe" }
poi_leisure_values = Set { "playground", "dog_park", "sports_centre", "pitch", "swimming_pool", "water_park",
"golf_course", "stadium", "ice_rink" }
sport_values = Set { "pitch", "sports_centre" }
poi_tourism_values = Set { "hotel", "motel", "bed_and_breakfast", "guest_house", "hostel", "chalet",
"camp_site", "alpine_hut", "caravan_site", "information", "picnic_site", "viewpoint", "zoo", "theme_park" }
poi_shop_values = Set { "supermarket", "bakery", "kiosk", "mall", "department_store", "general",
"convenience", "clothes", "florist", "chemist", "books", "butcher", "shoes", "alcohol",
"beverages", "optician", "jewelry", "gift", "sports", "stationery", "outdoor", "mobile_phone",
"toys", "newsagent", "greengrocer", "beauty", "video", "car", "bicycle", "doityourself",
"hardware", "furniture", "computer", "garden_centre", "hairdresser", "travel_agency", "laundry",
"dry_cleaning" }
poi_man_made_values = Set { "surveillance", "tower", "windmill", "lighthouse", "wastewater_plant",
"water_well", "watermill", "water_works" }
poi_historic_values = Set { "monument", "memorial", "artwork", "castle", "ruins", "archaelogical_site",
"wayside_cross", "wayside_shrine", "battlefield", "fort" }
poi_emergency_values = Set { "phone", "fire_hydrant", "defibrillator" }
poi_highway_values = Set { "emergency_access_point" }
poi_office_values = Set { "diplomatic" }
inf_zoom = 99
function fillWithFallback(value1, value2, value3)
if value1 ~= "" then
return value1
end
if value2 ~= "" then
return value2
end
return value3
end
-- Set name, name_en, and name_de on any object
function setNameAttributes(obj)
local name = obj:Find("name")
local name_de = obj:Find("name:de")
local name_en = obj:Find("name:en")
obj:Attribute("name", fillWithFallback(name, name_en, name_de))
obj:Attribute("name_de", fillWithFallback(name_de, name, name_en))
obj:Attribute("name_en", fillWithFallback(name_en, name, name_de))
end
-- Return true if way is oneway
function isOneway(oneway)
return oneway == "yes" or oneway == "1" or oneway == "true" or oneway == "-1"
end
-- Return true if way is a reverse oneway
function isReverseOneway(oneway)
return oneway == "-1"
end
-- Add the value of an OSM key if it exists. If the object does not have that key, add NULL.
function addAttributeOrEmptyStr(obj, key)
local value = obj:Find(key)
if value ~= "" then
obj:Attribute(key, value)
else
obj:Attribute(key, "")
end
end
-- Replace nil by an empty string
function toEmptyStr(arg)
if arg == nil then
return ""
end
return arg
end
-- Add a boolean attribute if the OSM object has the provided key and its value is "yes".
-- Defaults to false/no.
function addAttributeBoolean(obj, key)
local value = obj:Find(key)
obj:AttributeBoolean(key, (value == "yes"))
end
-- Convert layer tag to a number between -7 and +7, defaults to 0.
function layerNumeric(way)
local layer = tonumber(way:Find("layer"))
if not (layer == nil) then
if layer > 7 then
layer = 7
elseif layer < -7 then
layer = -7
end
return layer
end
return 0
end
-- Set z_order
function setZOrder(way, is_rail, ignore_bridge)
local highway = way:Find("highway")
local railway = way:Find("railway")
local layer = tonumber(way:Find("layer"))
local zOrder = 0
local Z_STEP = 14
if not ignore_bridges and toBridgeBool(way) then
zOrder = zOrder + Z_STEP
elseif toTunnelBool(way) then
zOrder = zOrder - Z_STEP
end
if not (layer == nil) then
if layer > 7 then
layer = 7
elseif layer < -7 then
layer = -7
end
zOrder = zOrder + layer * Z_STEP
end
local hwClass = 0
if is_rail and railway == "rail" and not way:Holds("service") then
hwClass = 13
elseif is_rail and railway == "rail" then
hwClass = 12
elseif is_rail and (railway == "subway" or railway == "light_rail" or railway == "tram" or railway == "funicular" or railway == "monorail") then
hwClass = 11
elseif highway == "motorway" then
hwClass = 10
elseif highway == "trunk" then
hwClass = 9
elseif highway == "primary" then
hwClass = 8
elseif highway == "secondary" then
hwClass = 7
elseif highway == "tertiary" then
hwClass = 6
elseif highway == "unclassified" or highway == "residential" or highway == "road" or highway == "motorway_link" or highway == "trunk_link" or highway == "primary_link" or highway == "secondary_link" or highway == "tertiary_link" or highway == "busway" or highway == "bus_guideway" then
hwClass = 5
elseif highway == "living_street" or highway == "pedestrian" then
hwClass = 4
elseif highway == "service" then
hwClass = 3
elseif highway == "footway" or highway == "bridleway" or highway == "cycleway" or highway == "path" or highway == "track" then
hwClass = 2
elseif highway == "steps" or highway == "platform" then
hwClass = 1
end
zOrder = zOrder + hwClass
way:ZOrder(zOrder)
end
function process_place_layer(node)
local place = node:Find("place")
local mz = 99
local kind = place
local population = node:Find("population")
if place == "city" then
mz = 6
if population == "" then
population = "100000"
end
elseif place == "town" then
mz = 7
if population == "" then
population = "5000"
end
elseif place == "village" then
mz = 10
if population == "" then
population = "100"
end
elseif place == "hamlet" then
mz = 10
if population == "" then
population = "50"
end
elseif place == "suburb" then
mz = 10
if population == "" then
population = "1000"
end
elseif place == "quarter" then
mz = 10
if population == "" then
population = "500"
end
elseif place == "neighbourhood" then
mz = 10
if population == "" then
population = "100"
end
elseif place == "locality" or place == "island" then
mz = 10
if population == "" then
population = "0"
end
elseif place == "isolated_dwelling" or place == "farm" then
mz = 10
if population == "" then
population = "5"
end
end
if (place == "city" or place == "town" or place == "village" or place == "hamlet") and node:Holds("capital") then
local capital = node:Find("capital")
if capital == "yes" then
mz = 4
kind = "capital"
elseif capital == "4" then
mz = 4
kind = "state_capital"
end
end
if mz < 99 then
node:Layer("place_labels", false)
node:MinZoom(mz)
node:Attribute("kind", kind)
setNameAttributes(node)
local populationNum = tonumber(population)
if populationNum ~= nil then
node:AttributeNumeric("population", populationNum)
node:ZOrder(populationNum)
end
end
end
function process_public_transport_layer(obj, is_area)
local railway = obj:Find("railway")
local aeroway = obj:Find("aeroway")
local aerialway = obj:Find("aerialway")
local highway = obj:Find("highway")
local amenity = obj:Find("amenity")
local kind = ""
local mz = inf_zoom
if railway == "station" or railway == "halt" then
kind = railway
mz = 13
elseif railway == "tram_stop" then
kind = railway
mz = 14
elseif highway == "bus_stop" then
kind = highway
mz = 14
elseif amenity == "bus_station" then
kind = amenity
mz = 13
elseif amenity == "ferry_terminal" then
kind = amenity
mz = 12
elseif aerialway == "station" then
kind = "aerialway_station"
mz = 13
elseif aeroway == "aerodrome" then
kind = aeroway
mz = 11
elseif aeroway == "helipad" then
kind = aeroway
mz = 13
end
if is_area then
obj:LayerAsCentroid("public_transport")
else
obj:Layer("public_transport", false)
end
obj:MinZoom(11)
obj:Attribute("kind", kind)
local iata = obj:Find("iata")
if iata ~= "" then
obj:Attribute("iata", iata)
end
setNameAttributes(obj)
end
function node_function(node)
-- Layer place_labels
if node:Holds("place") and node:Holds("name") then
process_place_layer(node)
end
-- Layer street_labels_points
local highway = node:Find("highway")
if highway == "motorway_junction" then
node:Layer("street_labels_points", false)
node:MinZoom(12)
node:Attribute("kind", highway)
setNameAttributes(node)
node:Attribute("ref", node:Find("ref"))
end
-- Layer public_transport
local railway = node:Find("railway")
local aeroway = node:Find("aeroway")
local aerialway = node:Find("aerialway")
local amenity = node:Find("amenity")
local highway = node:Find("highway")
if railway == "station"
or railway == "halt"
or railway == "tram_stop"
or highway == "bus_stop"
or amenity == "bus_station"
or amenity == "ferry_terminal"
or aeroway == "aerodrome"
or aeroway == "helipad"
or aerialway == "station" then
process_public_transport_layer(node, false)
end
-- Layer pois
-- Abort here if it was written as POI because Tilemaker cannot write a feature to two layers.
if process_pois(node, false) then
return
end
-- Layer addresses
local housenumber = node:Find("addr:housenumber")
local housename = node:Find("addr:housename")
if housenumber ~= "" or housename ~= "" then
process_addresses(node, false)
end
end
function zmin_for_area(way, min_square_pixels, way_area)
-- Return minimum zoom level where the area of the way/multipolygon is larger than
-- the provided threshold.
local circumfence = 40052725.78
local zmin = (math.log((min_square_pixels * circumfence^2) / (2^16 * way_area))) / (2 * math.log(2))
return math.floor(zmin)
end
function zmin_for_length(way, min_length_pixels)
-- Return minimum zoom level where the length of a line is larger than
-- the provided threshold.
local length = way:Length()
local circumfence = 40052725.78
local zmin = (math.log((circumfence * min_length_pixels) / (2^8 * length))) / math.log(2)
return math.floor(zmin)
end
function process_water_polygons(way, way_area)
local waterway = way:Find("waterway")
local natural = way:Find("natural")
local water = way:Find("water")
local landuse = way:Find("landuse")
local mz = inf_zoom
local kind = ""
local is_river = (natural == "water" and water == "river") or waterway == "riverbank"
if landuse == "reservoir" or landuse == "basin" or (natural == "water" and not is_river) or natural == "glacier" then
mz = math.max(4, zmin_for_area(way, 0.01, way_area))
if mz >= 10 then
mz = math.max(10, zmin_for_area(way, 0.1, way_area))
end
if landuse == "reservoir" or landuse == "basin" then
kind = landuse
elseif natural == "water" or natural == "glacier" then
kind = natural
end
elseif is_river or waterway == "dock" or waterway == "canal" then
mz = math.max(4, zmin_for_area(way, 0.1, way_area))
kind = waterway
if kind == "" then
kind = water
end
end
if mz < inf_zoom then
local way_area = way_area
way:Layer("water_polygons", true)
way:MinZoom(mz)
way:Attribute("kind", kind)
way:AttributeNumeric("way_area", way_area)
way:ZOrder(way_area)
if way:Holds("name") then
way:LayerAsCentroid("water_polygons_labels")
way:MinZoom(14)
way:Attribute("kind", kind)
way:AttributeNumeric("way_area", way_area)
way:ZOrder(way_area)
setNameAttributes(way)
end
end
end
function process_water_lines(way)
local kind = way:Find("waterway")
local mz = inf_zoom
local mz_label = inf_zoom
-- skip if area > 0 (it's no line then)
mz = inf_zoom
if kind == "river" or kind == "canal" then
mz = math.max(9, zmin_for_length(way, 0.25))
mz_label = math.max(13, zmin_for_length(way, 0.25))
elseif kind == "canal" then
mz = 12
mz_label = 14
elseif kind == "drain" or kind == "stream" then
mz = 13
mz_label = 14
elseif kind == "ditch" then
mz = 14
mz_label = 14
end
if mz < inf_zoom then
local tunnel = toTunnelBool(way:Find("tunnel"), way:Find("covered"))
local bridge = toBridgeBool(way:Find("bridge"))
local layer = layerNumeric(way)
way:Layer("water_lines", false)
way:MinZoom(mz)
way:Attribute("kind", kind)
way:AttributeBoolean("tunnel", tunnel)
way:AttributeBoolean("bridge", bridge)
way:ZOrder(layer)
if way:Holds("name") then
way:Layer("water_lines_labels", false)
way:MinZoom(mz_label)
way:Attribute("kind", kind)
way:AttributeBoolean("tunnel", tunnel)
way:AttributeBoolean("bridge", bridge)
setNameAttributes(way)
way:ZOrder(layer)
end
end
end
-- Return value for kind field of pier_* layers.
function get_pier_featuretype(way)
local man_made = way:Find("man_made")
if man_made == "pier" or man_made == "breakwater" or man_made == "groyne" then
return man_made
end
return nil
end
function process_pier_lines(way)
local kind = get_pier_featuretype(way)
if kind ~= nil then
way:Layer("pier_lines", false)
way:MinZoom(12)
way:Attribute("kind", kind)
end
end
function process_pier_polygons(way)
local kind = get_pier_featuretype(way)
if kind ~= nil then
way:Layer("pier_polygons", true)
way:MinZoom(12)
way:Attribute("kind", kind)
end
end
function process_land(way)
local landuse = way:Find("landuse")
local natural = way:Find("natural")
local wetland = way:Find("wetland")
local leisure = way:Find("leisure")
local kind = ""
local mz = inf_zoom
if landuse == "forest" or natural == "wood" then
kind = "forest"
mz = 7
elseif landuse == "residential" or landuse == "industrial" or landuse == "commercial" or landuse == "retail" or landuse == "railway" or landuse == "landfill" or landuse == "brownfield" or landuse == "greenfield" or landuse == "farmyard" or landuse == "farmland" then
kind = landuse
mz = 10
elseif landuse == "grass" or landuse == "meadow" or landuse == "orchard" or landuse == "vineyard" or landuse == "allotments" or landuse == "village_green" or landuse == "recreation_ground" or landuse == "greenhouse_horticulture" or landuse == "plant_nursery" or landuse == "quarry" then
kind = landuse
mz = 11
elseif natural == "sand" or natural == "beach" then
kind = natural
mz = 10
elseif natural == "wood" or natural == "heath" or natural == "scrub" or natural == "grassland" or natural == "bare_rock" or natural == "scree" or natural == "shingle" or natural == "sand" or natural == "beach" then
kind = natural
mz = 11
elseif wetland == "swamp" or wetland == "bog" or wetland == "string_bog" or wetland == "wet_meadow" or wetland == "marsh" then
kind = wetland
mz = 11
elseif way:Find("amenity") == "grave_yard" then
kind = "grave_yard"
mz = 13
elseif landuse == "garages" then
kind = landuse
mz = 12
elseif leisure == "golf_course" or leisure == "park" or leisure == "garden" or leisure == "playground" or leisure == "miniature_golf" then
kind = leisure
mz = 11
elseif landuse == "cemetery" then
kind = "cemetery"
mz = 13
end
if mz < inf_zoom then
way:Layer("land", true)
way:MinZoom(mz)
way:Attribute("kind", kind)
end
end
function process_sites(way)
local kind = ""
local amenity = way:Find("amenity")
local military = way:Find("military")
local leisure = way:Find("leisure")
local landuse = way:Find("landuse")
local mz = inf_zoom
if amenity == "university" or amenity == "hospital" or amenity == "prison" or amenity == "parking" or amenity == "bicycle_parking" or amenity == "school" or amenity == "college" then
kind = amenity
mz = 14
elseif leisure == "sports_center" then
kind = leisure
mz = 14
elseif landuse == "construction" then
kind = landuse
mz = 14
elseif military == "danger_area" then
kind = military
mz = 14
end
if mz < inf_zoom then
way:Layer("sites", true)
way:MinZoom(mz)
way:Attribute("kind", kind)
end
end
function process_boundary_lines(way)
if way:Holds("type") then
return
end
local min_admin_level = 99
local disputedBool = false
while true do
local rel = way:NextRelation()
if not rel and min_admin_level == 99 then
return
elseif not rel then
break
end
local admin_level = way:FindInRelation("admin_level")
local boundary = way:FindInRelation("boundary")
local al = 99
if admin_level ~= nil and boundary == "administrative" then
al = tonumber(admin_level)
end
if al ~= nil and al >= 2 then
min_admin_level = math.min(min_admin_level, al)
end
if boundary == "disputed" then
disputedBool = true
end
end
local mz = inf_zoom
if min_admin_level == 2 then
mz = 0
elseif min_admin_level <= 4 then
mz = 7
end
local maritime = way:Find("maritime")
local natural = way:Find("natural")
local maritimeBool = false
if maritime == "yes" or natural == "coastline" then
maritimeBool = true
end
if way:Find("disputed") == "yes" then
disputedBool = true
end
if mz < inf_zoom then
way:Layer("boundaries", false)
way:MinZoom(mz)
way:AttributeNumeric("admin_level", min_admin_level)
way:AttributeBoolean("maritime", maritimeBool)
way:AttributeBoolean("disputed", disputedBool)
end
end
function toTunnelBool(tunnel, covered)
if tunnel == "yes" or tunnel == "culvert" or tunnel == "building_passage" or covered == "yes" then
return true
end
return false
end
function toBridgeBool(bridge)
if bridge == "yes" or bridge == "viaduct" or bridge == "boardwalk" or bridge == "cantilever" or bridge == "covered" or bridge == "low_water_crossing" or bridge == "movable" or bridge == "trestle" then
return true
end
return false
end
function process_streets(way)
local min_zoom_layer = 5
local mz = inf_zoom
local kind = ""
local highway = way:Find("highway")
local railway = way:Find("railway")
local aeroway = way:Find("aeroway")
local surface = way:Find("surface")
local bicycle = way:Find("bicycle")
local horse = way:Find("horse")
local tracktype = way:Find("tracktype")
local tunnelBool = toTunnelBool(way:Find("tunnel"), way:Find("covered"))
local covered = way:Find("covered")
local service = way:Find("service")
local bridgeBool = toBridgeBool(way:Find("bridge"))
local name = way:Find("name")
local rail = false
if name == "" then
name = way:Find("ref")
end
if highway ~= "" then
if highway == "motorway" or highway == "motorway_link" then
mz = min_zoom_layer
kind = "motorway"
elseif highway == "trunk" or highway == "trunk_link" then
mz = 6
kind = "trunk"
elseif highway == "primary" or highway == "primary_link" then
mz = 8
kind = "primary"
elseif highway == "secondary" or highway == "secondary_link" then
mz = 9
kind = "secondary"
elseif highway == "tertiary" or highway == "tertiary_link" then
mz = 10
kind = "tertiary"
elseif highway == "unclassified" or highway == "residential" or highway == "bus_guideway" or highway == "busway" then
mz = 12
kind = highway
elseif highway == "living_street" or highway == "pedestrian" or highway == "track" then
mz = 13
kind = highway
elseif highway == "service" then
mz = 14
kind = highway
elseif highway == "footway" or highway == "steps" or highway == "path" or highway == "cycleway" then
mz = 13
kind = highway
end
elseif (railway == "rail" or railway == "narrow_gauge") and service == "" then
kind = railway
rail = true
mz = 8
elseif ((railway == "rail" or railway == "narrow_gauge") and service ~= "")
or railway == "light_rail" or railway == "tram" or railway == "subway"
or railway == "funicular" or railway == "monorail" then
kind = railway
rail = true
mz = 10
elseif aeroway == "runway" then
kind = aeroway
mz = 11
elseif aeroway == "taxiway" then
kind = aeroway
mz = 13
end
if kind ~= "" and surface ~= "" then
if surface == "unpaved" or surface == "compacted" or surface == "dirt" or surface == "earth" or surface == "fine_gravel" or surface == "grass" or surface == "grass_paver" or surface == "gravel" or surface == "ground" or surface == "mud" or surface == "pebblestone" or surface == "salt" or surface == "woodchips" or surface == "clay" then
suface = "unpaved"
elseif surface == "paved" or surface == "asphalt" or surface == "cobblestone" or surface == "cobblestone:flattended" or surface == "sett" or surface == "concrete" or surface == "concrete:lanes" or surface == "concrete:plates" or surface == "paving_stones" then
suface = "unpaved"
else
surface = ""
end
end
local link = (highway == "motorway_link" or highway == "trunk_link" or highway == "primary_link" or highway == "secondary_link" or highway == "tertiary_link")
local layer = tonumber(way:Find("layer"))
if layer == nil then
layer = 0
end
local oneway = way:Find("oneway")
local onewayBool = not rail and isOneway(oneway)
local reverseOnewayBool = not rail and isReverseOneway(oneway)
if mz <= 13 then
way:Layer("streets_med", false)
way:MinZoom(mz)
way:Attribute("kind", kind)
way:AttributeBoolean("link", link)
way:Attribute("surface", surface)
way:AttributeBoolean("tunnel", tunnelBool)
way:AttributeBoolean("bridge", bridgeBool)
if tracktype ~= "" then
way:Attribute("tracktype", tracktype)
end
way:AttributeBoolean("rail", rail)
if service ~= "" then
way:Attribute("service", service)
end
setZOrder(way, rail, false)
end
if mz < inf_zoom then
way:Layer("streets", false)
way:MinZoom(mz)
way:Attribute("kind", kind)
way:AttributeBoolean("link", link)
way:Attribute("surface", surface)
way:Attribute("bicycle", bicycle)
way:Attribute("horse", horse)
way:AttributeBoolean("tunnel", tunnelBool)
way:AttributeBoolean("bridge", bridgeBool)
way:AttributeBoolean("oneway", onewayBool)
way:AttributeBoolean("oneway_reverse", reverseOnewayBool)
if tracktype ~= "" then
way:Attribute("tracktype", tracktype)
end
way:AttributeBoolean("rail", rail)
if service ~= "" then
way:Attribute("service", service)
end
setZOrder(way, rail, false)
end
if mz <= 10 then
way:Layer("streets_low", false)
way:MinZoom(mz)
way:Attribute("kind", kind)
way:AttributeBoolean("rail", rail)
setZOrder(way, rail, false)
end
end
function process_street_labels(way)
local highway = way:Find("highway")
local ref = way:Find("ref")
local name = way:Find("name")
local mz = inf_zoom
local kind = ""
if highway == "motorway" then
mz = 10
kind = highway
elseif highway == "trunk" or highway == "primary" then
mz = 12
kind = highway
elseif highway == "secondary" or highway == "tertiary" then
mz = 13
kind = highway
elseif highway == "motorway_link" then
mz = 13
kind = "motorway"
link = true
elseif highway == "trunk_link" then
mz = 13
kind = "trunk"
link = true
elseif highway == "primary_link" then
mz = 13
kind = "primary"
link = true
elseif highway == "secondary_link" then
mz = 13
kind = "secondary"
link = true
elseif highway == "tertiary_link" then
mz = 14
kind = "tertiary"
link = true
elseif highway == "unclassified" or highway == "residential" or highway == "busway" or highway == "bus_guideway" or highway == "living_street" or highway == "pedestrian" or highway == "track" or highway == "service" or highway == "footway" or highway == "steps" or highway == "path" or highway == "cycleway" then
mz = 14
kind = highway
end
local refs = ""
local rows = 0
local cols = 0
if mz < inf_zoom and ref ~= "" then
for word in string.gmatch(ref, "([^;]+);?") do
rows = rows + 1
cols = math.max(cols, string.len(word))
if rows == 1 then
refs = word
else
refs = refs .. "\n" .. word
end
end
elseif mz >= inf_zoom then
return
end
if (name ~= "" or refs ~= "") then
way:Layer("street_labels", false)
way:MinZoom(mz)
way:Attribute("kind", highway)
way:AttributeBoolean("tunnel", toTunnelBool(way))
way:Attribute("ref", refs)
way:AttributeNumeric("ref_rows", rows)
way:AttributeNumeric("ref_cols", cols)
setNameAttributes(way)
setZOrder(way, false, true)
end
end
function process_street_polygons(way)
local highway = way:Find("highway")
local aeroway = way:Find("area:aeroway")
local surface = way:Find("surface")
local service = way:Find("service")
local kind = nil
local mz = inf_zoom
if highway == "pedestrian" or highway == "service" then
mz = 14
kind = highway
elseif aeroway == "runway" then
mz = 11
kind = aeroway
elseif aeroway == "taxiway" then
mz = 13
kind = aeroway
end
if mz < inf_zoom then
way:Layer("street_polygons", true)
way:MinZoom(mz)
way:Attribute("kind", kind)
if surface ~= "" then
way:Attribute("surface", surface)
end
way:AttributeBoolean("tunnel", toTunnelBool(way:Find("tunnel"), way:Find("covered")))
way:AttributeBoolean("bridge", toBridgeBool(way:Find("bridge")))
way:AttributeBoolean("rail", false)
if service ~= "" then
way:Attribute("service", service)
end
setZOrder(way, rail, false)
if name ~= "" then
way:LayerAsCentroid("streets_polygons_labels")
setNameAttributes(way)
way:Attribute("kind", kind)
way:MinZoom(mz)
end
end
end
function process_aerialways(way)
local aerialway = way:Find("aerialway")
if aerialway == "cable_car" or aerialway == "gondola" or aerialway == "chair_lift" or aerialway == "drag_lift" or aerialway == "t-bar" or aerialway == "j-bar" or aerialway == "platter" or aerialway == "rope_tow" then
way:Layer("aerialways", false)
way:MinZoom(12)
way:Attribute("kind", aerialway)
end
end
function process_buildings(way)
local building = way:Find("building")
if building ~= "no" then
way:Layer("buildings", true)
way:MinZoom(14)
way:AttributeNumeric("dummy", 1)
end
end
function process_addresses(way, is_area)
if is_area then
way:LayerAsCentroid("addresses")
else
way:Layer("addresses", false)
end
way:MinZoom(14)
setAddressAttributes(way)
end
function setAddressAttributes(obj)
obj:Attribute("housename", obj:Find("addr:housename"))
obj:Attribute("housenumber", obj:Find("addr:housenumber"))
end
function process_ferries(way)
local mz = inf_zoom
if way:Find("route") == "ferry" then
local motor_vehicle = way:Find("motor_vehicle")
mz = 10
if motor_vehicle == "no" then
mz = 12
end
end
if mz < inf_zoom then
way:Layer("ferries", false)
way:MinZoom(mz)
way:Attribute("kind", "ferry")
setNameAttributes(way)
end
end
function process_bridges(way)
if way:Find("man_made") == "bridge" then
way:Layer("bridges", true)
way:MinZoom(12)
way:Attribute("kind", "bridge")
end
end
function process_dam(way, polygon)
if way:Find("waterway") == "dam" then
if polygon then
way:Layer("dam_polygons", true)
else
way:Layer("dam_lines", false)
end
way:MinZoom(12)
way:Attribute("kind", "dam")
end
end
-- Create "pois" layer
-- Returns true if the feature is written to that layer.
-- Returns false if it was no POI we are interested in.
function process_pois(obj, polygon)
local amenity = valueAcceptedOrNil(poi_amenity_values, obj:Find("amenity"))
local shop = valueAcceptedOrNil(poi_shop_values, obj:Find("shop"))
local tourism = valueAcceptedOrNil(poi_tourism_values, obj:Find("tourism"))
local man_made = valueAcceptedOrNil(poi_man_made_values, obj:Find("man_made"))
local historic = valueAcceptedOrNil(poi_historic_values, obj:Find("historic"))
local leisure = valueAcceptedOrNil(poi_leisure_values, obj:Find("leisure"))
local emergency = valueAcceptedOrNil(poi_emergency_values, obj:Find("emergency"))
local highway = valueAcceptedOrNil(poi_highway_values, obj:Find("highway"))
local office = valueAcceptedOrNil(poi_highway_values, obj:Find("office"))
if amenity == nil and shop == nil and tourism == nil and historic == nil and leisure == nil and emergency == nil and highway == nil and office == nil then
return false
end
if polygon then
obj:LayerAsCentroid("pois")
else
obj:Layer("pois", false)
end
obj:MinZoom(14)
obj:Attribute("amenity", nilToEmptyStr(amenity))
obj:Attribute("shop", nilToEmptyStr(shop))
obj:Attribute("tourism", nilToEmptyStr(tourism))
obj:Attribute("man_made", nilToEmptyStr(historic))
obj:Attribute("historic", nilToEmptyStr(historic))
obj:Attribute("leisure", nilToEmptyStr(leisure))
obj:Attribute("emergency", nilToEmptyStr(emergency))
obj:Attribute("highway", nilToEmptyStr(highway))
obj:Attribute("office", nilToEmptyStr(office))
if catering_values[amenity] then
addAttributeOrEmptyStr(obj, "cuisine")
end
if sport_values[leisure] then
addAttributeOrEmptyStr(obj, "sport")
end
if amenity == "vending_machine" then
addAttributeOrEmptyStr(obj, "vending")
end
if tourism == "information" then
addAttributeOrEmptyStr(obj, "information")
end
if man_made == "tower" then
addAttributeOrEmptyStr(obj, "tower:type")
end
if amenity == "recycling" then
addAttributeBoolean(obj, "recycling:glass_bottles")
addAttributeBoolean(obj, "recycling:paper")
addAttributeBoolean(obj, "recycling:clothes")
addAttributeBoolean(obj, "recycling:scrap_metal")
end
if amenity == "bank" then
addAttributeBoolean(obj, "atm")
end
if amenity == "place_of_worship" then
addAttributeOrEmptyStr(obj, "religion")
addAttributeOrEmptyStr(obj, "denomination")
end
setNameAttributes(obj)
setAddressAttributes(obj)
return true
end
function way_function(way)
local area = way:Area()
local area_tag = way:Find("area")