-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess-sve01.lua
More file actions
5007 lines (4736 loc) · 248 KB
/
process-sve01.lua
File metadata and controls
5007 lines (4736 loc) · 248 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
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
-- ----------------------------------------------------------------------------
-- process-sve01.lua
--
-- Copyright (C) 2024-2026 Andy Townsend
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
-- ----------------------------------------------------------------------------
-- Code common to several projects is in "shared_lua.lua".
-- That file is in the "SomeoneElse-style" repository, but needs to be
-- available on the standard lua path when this script is invoked. An easy way
-- to do that is to copy it to a local shared area on that path:
-- cp /home/${local_filesystem_user}/src/SomeoneElse-style/shared_lua.lua -
-- /usr/local/share/lua/5.3/
-- ----------------------------------------------------------------------------
require "shared_lua_vector"
local utf8 = require "utf8"
-- Nodes will only be processed if one of these keys is present
node_keys = { "abandoned:railway", "addr:housenumber", "advertising", "aerialway", "aeroway", "amenity", "attraction",
"barrier", "boundary",
"canoe", "climbing", "craft", 'defensive_works',
"disused:amenity", "disused:building", "disused:highway", "disused:landuse", "disused:man_made",
"disused:military", "disused:pub", "disused:railway", "disused:shop", "disused:tourism", "disused:waterway",
"emergency", "entrance", "ford", "geological", "golf", "harbour", "hazard",
"healthcare", "highway", "historic", "historic:railway", "information", "junction",
"landuse", "lcn_ref", "leisure", "man_made", "marker",
"military", "natural", "ncn_milepost",
"office", "outlet", "pipeline", "pitch", "place",
"place_of_worship", "playground", "police", "power", "railway", "ruined:building", "ruins:building",
"seamark:type", "shop", "sport", "tourism", "tunnel", "was:amenity", "waterway", "whitewater", "zoo" }
-- Initialize Lua logic
function init_function()
end
-- Finalize Lua logic()
function exit_function()
end
-- ------------------------------------------------------------------------------
-- Main entry point for processing nodes
--
-- The parameter here is an object that describes one node. See:
-- https://github.com/systemed/tilemaker/blob/master/docs/CONFIGURATION.md#principal-lua-functions
-- Note that "node" is an object with specific methods, unlike the array that is
-- passed to similar code in osm2pgsql's pgsql lua calls.
--
-- "generic_before_function" handles things like "unusual" tags that we want to
-- replace across the board.
-- Then any processing that only applies to nodes is done.
-- Finally "generic_after_function" handles everything else, including most of
-- the "move OSM tags to vector layers"
-- ------------------------------------------------------------------------------
function node_function()
local nodet = {}
nodet.way_area = 0
update_table( nodet )
generic_before_function( nodet )
-- ----------------------------------------------------------------------------
-- Node-specific code
-- Consolidate some "ford" values into "yes".
-- This is here rather than in "generic" because "generic" is called after this
-- There is a similar section in way-only.
-- ----------------------------------------------------------------------------
if (( nodet.ford == "tidal_causeway" ) or
( nodet.ford == "ford" ) or
( nodet.ford == "intermittent" ) or
( nodet.ford == "seasonal" ) or
( nodet.ford == "stream" ) or
( nodet.ford == "tidal" ) or
( nodet.ford == "boat" )) then
nodet.ford = "yes"
end
if ( nodet.ford == "yes" ) then
nodet.highway = "ford"
nodet.ford = nil
end
if ( nodet.ford == "stepping_stones" ) then
nodet.barrier = "stepping_stones"
nodet.ford = nil
end
-- ----------------------------------------------------------------------------
-- Map non-linear unknown (and some known) barriers to bollard
-- ----------------------------------------------------------------------------
if (( nodet.barrier == "yes" ) or
( nodet.barrier == "barrier" ) or
( nodet.barrier == "tank_trap" ) or
( nodet.barrier == "dragons_teeth" ) or
( nodet.barrier == "bollards" ) or
( nodet.barrier == "bus_trap" ) or
( nodet.barrier == "car_trap" ) or
( nodet.barrier == "rising_bollard" ) or
( nodet.barrier == "steps" ) or
( nodet.barrier == "step" ) or
( nodet.barrier == "post" ) or
( nodet.man_made == "post" ) or
( nodet.man_made == "marker_post" ) or
( nodet.man_made == "boundary_post" ) or
( nodet.man_made == "concrete_post" ) or
( nodet.barrier == "stone" ) or
( nodet.barrier == "hoarding" ) or
( nodet.barrier == "sump_buster" ) or
( nodet.barrier == "gate_pier" ) or
( nodet.barrier == "gate_post" ) or
( nodet.man_made == "gate_post" ) or
( nodet.man_made == "gatepost" ) or
( nodet.barrier == "pole" ) or
( nodet.barrier == "planter" ) or
( nodet.man_made == "planter" ) or
( nodet.barrier == "log" ) or
( nodet.barrier == "tree" )) then
nodet.barrier = "bollard"
end
-- ----------------------------------------------------------------------------
-- Render barrier=chain on nodes as horse_stile. At least sone of the time
-- it's correct.
-- ----------------------------------------------------------------------------
if ( nodet.barrier == "chain" ) then
nodet.barrier = "horse_stile"
end
-- ----------------------------------------------------------------------------
-- Render barrier=v_stile on nodes as stile.
-- ----------------------------------------------------------------------------
if ( nodet.barrier == "v_stile" ) then
nodet.barrier = "stile"
end
-- ----------------------------------------------------------------------------
-- highway=turning_loop on nodes to turning_circle
-- "turning_loop" is mostly used on nodes, with one way in UK/IE data.
-- ----------------------------------------------------------------------------
if ( nodet.highway == "turning_loop" ) then
nodet.highway = "turning_circle"
end
-- ----------------------------------------------------------------------------
-- Before we start doing comparisons that include natural=rock, make sure
-- that we have caught them all.
--
-- The code to do this is shared between nodes and ways here (vector) and also
-- raster.
-- ----------------------------------------------------------------------------
consolidate_rock_t( nodet )
-- ----------------------------------------------------------------------------
-- Change natural=bare_rock and natural=rocks on nodes to natural=rock
-- So that an icon (the all-black, non-climbing boulder one) is displayed
-- ----------------------------------------------------------------------------
if (( nodet.natural == "bare_rock" ) or
( nodet.natural == "rocks" ) or
( nodet.natural == "stones" )) then
nodet.natural = "rock"
end
-- ----------------------------------------------------------------------------
-- A natural=cliff et al node can't be drawn as a linear cliff, but we can
-- treat it as a locality.
-- ----------------------------------------------------------------------------
if ((( nodet.natural == "cliff" ) or
( nodet.natural == "ridge" ) or
( nodet.natural == "arch" ) or
( nodet.natural == "strait" ) or
( nodet.natural == "mountain_range" ) or
( nodet.natural == "gully" )) and
(( nodet.place == nil ) or
( nodet.place == "" ))) then
nodet.place = "locality"
nodet.natural = nil
end
-- ----------------------------------------------------------------------------
-- If lcn_ref exists (for example as a location in a local cycling network),
-- render it via a "man_made" tag if there's no other tags on that node.
-- ----------------------------------------------------------------------------
if (( nodet.lcn_ref ~= nil ) and
( nodet.lcn_ref ~= "" ) and
(( nodet.ref == nil ) or
( nodet.ref == "" ))) then
nodet.man_made = "lcn_ref"
nodet.ref = nodet.lcn_ref
nodet.lcn_ref = nil
end
-- ----------------------------------------------------------------------------
-- We treat node islands as just localities.
-- ----------------------------------------------------------------------------
if (( nodet.place == "island" ) or
( nodet.place == "islet" )) then
nodet.place = "locality"
end
-- ----------------------------------------------------------------------------
-- All node highway=platform are actually highway=bus_stop
-- ----------------------------------------------------------------------------
if ( nodet.highway == "platform" ) then
nodet.highway = "bus_stop_pole"
end
-- ------------------------------------------------------------------------------
-- The "place" layer is mostly node-specific (islands and area localities are
-- a thing - see "wr_after_place( wayt )" below).
-- For the rest, it'd be nice to be able to process relations, ways and nodes,
-- knowing that there would be only one OSM feature per real-world element, but
-- unfortunately this is not the case.
--
-- * Lots of places (from "city" downwards) have both relations, and occasionally
-- ways, and nodes.
-- * Lots of places only have nodes.
-- * Many fewer places only have relations or ways.
-- Example https://www.openstreetmap.org/way/243794759
-- * Where a real-world place has an OSM relation and a node, the names sometimes
-- do not match (Galway).
-- * Where a real-world place has an OSM relation and a node, the place values
-- sometimes do not match (Appledore).
--
-- The least-worst approach is therefore to only write out the "place" layer
-- based on nodes.
-- ------------------------------------------------------------------------------
n_after_place( nodet )
-- ------------------------------------------------------------------------------
-- If the node is an artwork, guidepost, route marker, ncn milepost or an
-- explicit lcn_ref, let's try and process the relations that it is part of.
-- This doesn't just look for e.g. "guidepost_type"; any relation membership of
-- a matching network type will be processed.
-- ------------------------------------------------------------------------------
if (( nodet.tourism == "artwork" ) or
( nodet.tourism == "informationmarker" ) or
( nodet.tourism == "informationprowmarker" ) or
( nodet.tourism == "informationroutemarker" ) or
( nodet.tourism == "informationncndudgeon" ) or
( nodet.tourism == "informationncnmccoll" ) or
( nodet.tourism == "informationncnmills" ) or
( nodet.tourism == "informationncnrowe" ) or
( nodet.tourism == "informationncnunknown" ) or
( nodet.tourism == "informationartwork" ) or
( nodet.tourism == "informationstele" ) or
( nodet.man_made == "lcn_ref" )) then
nodet.nwnrelationlist = ""
nodet.nhnrelation_in_list = false
nodet.ncnrelationlist = ""
while true do
local relation_id, relation_role = NextRelation()
if ( not relation_id ) then
break
end
-- ------------------------------------------------------------------------------
-- We're processing a relation in the list that this node is a member of, but
-- it might have a silly name. We have a couple of "fix_silly_..." functions to
-- change known examples of those to sensible versions, so create a lua table
-- with the information they need to be able to do that.
-- ------------------------------------------------------------------------------
local relation_namet = {}
relation_namet.name = FindInRelation( "name" )
relation_namet.operator = FindInRelation( "operator" )
fix_silly_nt_names_t( relation_namet )
fix_silly_rwn_names_t( relation_namet )
local relation_ref = FindInRelation( "ref" )
local relation_network = FindInRelation( "network" )
-- ------------------------------------------------------------------------------
-- We use ref rather than name on iwns here ...
-- ------------------------------------------------------------------------------
if (( relation_network == "iwn" ) and
( relation_ref ~= nil )) then
relation_namet.name = relation_ref
end
-- ------------------------------------------------------------------------------
-- ... and we use name rather than ref on the "special cased" lcns below.
-- ------------------------------------------------------------------------------
if (( relation_network == "lcn" ) and
( relation_namet.name ~= nil )) then
relation_ref = relation_namet.name
end
-- ------------------------------------------------------------------------------
-- Some markers have a role that indicates that they are not on the relation, so
-- we put brackets around the name.
-- Currently no other roles listed at
-- https://taginfo.openstreetmap.org/relations/route#roles
-- are special-cased.
-- ------------------------------------------------------------------------------
if ( relation_role == "marker_brackets" ) then
relation_namet.name = "(" .. relation_namet.name .. ")"
relation_ref = "(" .. relation_ref .. ")"
end
-- ------------------------------------------------------------------------------
-- Create a list of walking route relations that this node is a member of...
-- ------------------------------------------------------------------------------
if ((( relation_network == "iwn" ) or
( relation_network == "nwn" ) or
( relation_network == "rwn" ) or
( relation_network == "lwn" ) or
( relation_network == "lwn;lcn" ) or
( relation_network == "lwn;lcn;lhn" )) and
( relation_namet.name ~= nil ) and
( relation_namet.name ~= "" ) and
( relation_namet.name ~= "()" )) then
if ( nodet.nwnrelationlist == "" ) then
nodet.nwnrelationlist = relation_namet.name
else
nodet.nwnrelationlist = nodet.nwnrelationlist .. ", " .. relation_namet.name
end
end
-- ------------------------------------------------------------------------------
-- Append any horse route relations, and set a flag so that it can be displayed
-- in a different colour
-- ------------------------------------------------------------------------------
if (( relation_network == "nhn" ) or
( relation_network == "rhn" ) or
( relation_network == "ncn;nhn;nwn" )) then
nodet.nhnrelation_in_list = true
if ( nodet.nwnrelationlist == "" ) then
nodet.nwnrelationlist = relation_namet.name
else
nodet.nwnrelationlist = nodet.nwnrelationlist .. ", " .. relation_namet.name
end
end
-- ----------------------------------------------------------------------------
-- Similarly for cycle networks.
-- Most LCNs are ignored, but we special-case a couple worth-including.
-- Unlike with relation display, we don't exclude obviously silly refs, as
-- these are not expected to appear on guideposts.
-- We use "ref" rather than "name" for these.
-- ----------------------------------------------------------------------------
if ((( relation_network == "ncn" ) or
( relation_network == "rcn" ) or
(( relation_network == "lcn" ) and
(( relation_namet.name == "Solar System Route" ) or
( relation_namet.name == "Orbital Route" )))) and
( relation_ref ~= nil ) and
( relation_ref ~= "" ) and
( relation_ref ~= "()" )) then
if ( nodet.ncnrelationlist == "" ) then
nodet.ncnrelationlist = relation_ref
else
nodet.ncnrelationlist = nodet.ncnrelationlist .. ", " .. relation_ref
end
end
end
end
-- ----------------------------------------------------------------------------
-- "junction=yes" nodes with a name and no other highway tags.
-- ----------------------------------------------------------------------------
if (( nodet.junction == "yes" ) and
( nodet.name ~= nil ) and
( nodet.name ~= "" ) and
(( nodet.highway == nil ) or
( nodet.highway == "" ))) then
nodet.highway = "motorway_junction"
nodet.junction = nil
end
-- ----------------------------------------------------------------------------
-- Assume that a "junction=roundabout" node that is not any other sort of
-- "highway" is a mini roundabout.
-- If it is some other sort of "highway" then assume that it is not really a
-- roundabout.
-- ----------------------------------------------------------------------------
if ( nodet.junction == "roundabout" ) then
if (( nodet.highway == nil ) or
( nodet.highway == "" )) then
nodet.highway = "mini_roundabout"
end
nodet.junction = nil
end
-- ----------------------------------------------------------------------------
-- node waterway=fish_pass are changed to waterway=weir
-- ----------------------------------------------------------------------------
if ( nodet.waterway == "fish_pass" ) then
nodet.waterway = "weir"
nodet.usage = nil
end
-- ----------------------------------------------------------------------------
-- node piers are changed to "man_made=pointpier" to make the processing logic
-- easier.
-- ----------------------------------------------------------------------------
if ( nodet.man_made == "pier" ) then
nodet.man_made = "pointpier"
end
-- ------------------------------------------------------------------------------
-- (end of the node-specific code)
--
-- Actually writing out nodes (and polygons) is done in "generic_after_function"
-- ------------------------------------------------------------------------------
generic_after_function( nodet )
end -- node_function()
-- ------------------------------------------------------------------------------
-- Main entry point for processing ways
-- The parameter here is an object that describes one way. See:
-- https://github.com/systemed/tilemaker/blob/master/docs/CONFIGURATION.md#principal-lua-functions
-- Note that "node" is an object with specific methods, unlike the array that is
-- passed to similar code in osm2pgsql's pgsql lua calls.
--
-- "generic_before_function" handles things like "unusual" tags that we want to
-- replace across the board.
-- Then any processing that only applies to ways is done.
-- Finally "generic_after_function" handles everything else, including most of
-- the "move OSM tags to vector layers"
-- ------------------------------------------------------------------------------
function way_function()
local wayt = {}
wayt.is_closed = IsClosed()
if ( wayt.is_closed ) then
wayt.way_area = Area()
else
wayt.way_area = 0
end
update_table( wayt )
generic_before_function( wayt )
-- ----------------------------------------------------------------------------
-- Way-specific code
-- Consolidate some "ford" values into "yes".
-- This is here rather than in "generic" because "generic" is called after this
-- There is a similar section in way-only.
-- ----------------------------------------------------------------------------
if (( wayt.ford == "tidal_causeway" ) or
( wayt.ford == "ford" ) or
( wayt.ford == "intermittent" ) or
( wayt.ford == "seasonal" ) or
( wayt.ford == "stream" ) or
( wayt.ford == "tidal" ) or
( wayt.ford == "boat" )) then
wayt.ford = "yes"
end
-- ----------------------------------------------------------------------------
-- If a highway has tidal=yes but not yet a ford or bridge tag, add ford=yes
-- ----------------------------------------------------------------------------
if (( wayt.tidal == "yes" ) and
( wayt.highway ~= nil ) and
( wayt.highway ~= "" ) and
(( wayt.ford == nil ) or
( wayt.ford == "" )) and
(( wayt.bridge == nil ) or
( wayt.bridge == "" ))) then
wayt.ford = "yes"
end
-- ----------------------------------------------------------------------------
-- "barrier=gate" on a way is a dark line; on bridleways it looks
-- "sufficiently different" to mark fords out.
-- ----------------------------------------------------------------------------
if (( wayt.ford == "yes" ) or
( wayt.ford == "stepping_stones" ))then
wayt.barrier = "ford"
end
-- ----------------------------------------------------------------------------
-- Treat a linear "door" and some other linear barriers as "gate"
-- ----------------------------------------------------------------------------
if (( wayt.barrier == "door" ) or
( wayt.barrier == "swing_gate" )) then
wayt.barrier = "gate"
wayt.waterway = nil
end
-- ----------------------------------------------------------------------------
-- Map linear tank traps, and some others, to wall
-- ----------------------------------------------------------------------------
if (( wayt.barrier == "tank_trap" ) or
( wayt.barrier == "dragons_teeth" ) or
( wayt.barrier == "obstruction" ) or
( wayt.barrier == "sea_wall" ) or
( wayt.barrier == "flood_wall" ) or
( wayt.barrier == "block" ) or
( wayt.barrier == "haha" ) or
( wayt.barrier == "jersey_barrier" ) or
( wayt.barrier == "retaining_wall" )) then
wayt.barrier = "wall"
end
-- ----------------------------------------------------------------------------
-- Map linear unknown and other barriers to fence.
-- In some cases this is a bit of a stretch - you can walk up some steps, or
-- through a cycle barrier for example. Fence was chosen as the "current
-- minimal thickness linear barrier". If a narrower one is introduced it
-- would make sense to make traversable ones in this list to that.
-- ----------------------------------------------------------------------------
if (( wayt.barrier == "yes" ) or
( wayt.barrier == "barrier" ) or
( wayt.barrier == "bollard" ) or
( wayt.barrier == "steps" ) or
( wayt.barrier == "step" ) or
( wayt.barrier == "hoarding" ) or
( wayt.barrier == "horse_stile" ) or
( wayt.barrier == "chain" ) or
( wayt.barrier == "stile" ) or
( wayt.barrier == "v_stile" ) or
( wayt.barrier == "cycle_barrier" ) or
( wayt.barrier == "handrail" ) or
( wayt.barrier == "water_gate" ) or
( wayt.barrier == "rope" ) or
( wayt.barrier == "tyres" )) then
wayt.barrier = "fence"
end
if (( wayt.barrier == "planter" ) or
( wayt.man_made == "planter" )) then
wayt.barrier = "wall"
if ( wayt.is_closed ) then
wayt.landuse = "grass"
end
end
if (( wayt.public_transport == "platform" ) and
( wayt.highway ~= "platform" ) and
( wayt.highway ~= "bus_stop" ) and
( wayt.railway ~= "platform" )) then
wayt.highway = "platform"
end
-- ----------------------------------------------------------------------------
-- Map sinkholes mapped as ways to a non-area cliff.
-- It's pot luck whether the triangles will appear on the right side of the
-- cliff, but by chance most of the few UK ones do seem to be drawn the
-- "correct" way around.
-- ----------------------------------------------------------------------------
if ( wayt.natural == "sinkhole" ) then
wayt.natural = "cliff"
wayt.area = "no"
end
-- ----------------------------------------------------------------------------
-- Add building=roof on shelter and bicycle_parking ways if no building tag
-- already.
-- ----------------------------------------------------------------------------
if ((( wayt.amenity == "shelter" ) or
( wayt.amenity == "bicycle_parking" )) and
(( wayt.building == nil ) or
( wayt.building == "" )) and
( wayt.covered ~= "no" )) then
wayt.building = "roof"
end
-- ----------------------------------------------------------------------------
-- A "leisure=track" can be either a linear or an area feature
-- https://wiki.openstreetmap.org/wiki/Tag%3Aleisure%3Dtrack
-- Assign a highway tag (gallop or leisuretrack) so that linear features can
-- be explicitly rendered.
-- "sport" is often (but not always) used to separate different types of
-- leisure tracks.
--
-- If on an area, on raster the way will go into planet_osm_polygon and the highway
-- feature won't be rendered (because both leisuretrack and gallop are only
-- processed as linear features) but the leisure=track will be (as an area).
--
-- Additionally force anything that is "oneway" to not be an area feature
-- ----------------------------------------------------------------------------
if ( wayt.leisure == "track" ) then
if (( wayt.sport == "equestrian" ) or
( wayt.sport == "horse_racing" )) then
wayt.highway = "gallop"
else
if ((( wayt.sport == "motor" ) or
( wayt.sport == "karting" ) or
( wayt.sport == "motor;karting" )) and
(( wayt.area == nil ) or
( wayt.area == "" ) or
( wayt.area == "no" ))) then
wayt.highway = "raceway"
else
wayt.highway = "leisuretrack"
end
end
if ( wayt.oneway == "yes" ) then
wayt.area = "no"
end
end
-- ----------------------------------------------------------------------------
-- highway=turning_loop on ways to service road
-- "turning_loop" is mostly used on nodes, with one way in UK/IE data.
-- ----------------------------------------------------------------------------
if ( wayt.highway == "turning_loop" ) then
wayt.highway = "service"
wayt.service = "driveway"
end
-- ----------------------------------------------------------------------------
-- Before we start doing comparisons that include natural=rock, make sure
-- that we have caught them all.
--
-- The code to do this is shared between nodes and ways here (vector) and also
-- raster.
-- ----------------------------------------------------------------------------
consolidate_rock_t( wayt )
-- ----------------------------------------------------------------------------
-- natural=rock on ways to natural=bare_rock
-- ----------------------------------------------------------------------------
if ( wayt.natural == "rock" ) then
wayt.natural = "bare_rock"
end
-- ----------------------------------------------------------------------------
-- Render tidal rocks with more blue
-- ----------------------------------------------------------------------------
if (( wayt.natural == "bare_rock" ) and
(( wayt.tidal == "yes" ) or
( wayt.wetland == "tidalflat" ) or
( wayt.water == "tidal" ))) then
wayt.natural = "tidal_rock"
end
-- ----------------------------------------------------------------------------
-- Where amenity=watering_place has been used on a way and there's no
-- "natural" tag already, apply "natural=water".
-- ----------------------------------------------------------------------------
if (( wayt.amenity == "watering_place" ) and
(( wayt.natural == nil ) or
( wayt.natural == "" ))) then
wayt.amenity = nil
wayt.natural = "water"
end
-- ----------------------------------------------------------------------------
-- Before processing footways, turn certain corridors into footways
--
-- Note that https://wiki.openstreetmap.org/wiki/Key:indoor defines
-- indoor=corridor as a closed way. highway=corridor is not documented there
-- but is used for corridors. We'll only process layer or level 0 (or nil)
--
-- The assignment of local variables is done by the example code, I'm guessing
-- for reasons of speed.
-- ----------------------------------------------------------------------------
fix_corridors_t( wayt )
-- ----------------------------------------------------------------------------
-- Consolidate some rare highway types into ones we can display.
-- ----------------------------------------------------------------------------
process_golf_tracks_t( wayt )
-- ----------------------------------------------------------------------------
-- Remove landuse=military from non-closed ways
-- This is because while the linear raster rendering code doesn't even see this
-- because it's in a different table, the vector code sees everything in land1
-- or land2, regardless of geometry.
-- ----------------------------------------------------------------------------
if (( not wayt.is_closed ) and
( wayt.landuse == "military" )) then
wayt.landuse = nil
end
-- ----------------------------------------------------------------------------
-- Dam areas. Extract as an explicit area feature.
-- ----------------------------------------------------------------------------
if (( wayt.waterway == "dam" ) and
( wayt.is_closed ) and
(( wayt.building == nil ) or
( wayt.building == "" ))) then
wayt.waterway = "damarea"
end
-- ----------------------------------------------------------------------------
-- barrier=hedge hedges. If there is no area key set (i.e. "area=yes" was not
-- explicitly set) assume that area=no. Earlier in the shared lua, we've set
-- linear hedges around other areas (e.g. meadows) as "hedgeline".
-- ----------------------------------------------------------------------------
if (( wayt.barrier == "hedge" ) and
(( wayt.area == nil ) or
( wayt.area == "" ))) then
wayt.area = "no"
end
-- ----------------------------------------------------------------------------
-- linear place=locality are a special case - we treat them as named linear
-- features and use natural=valley to show the name.
-- ----------------------------------------------------------------------------
if (( wayt.place == "locality" ) and
(( wayt.natural == nil ) or
( wayt.natural == "" ))) then
if ( not wayt.is_closed ) then
wayt.natural = "valley"
wayt.place = nil
end
end
-- ----------------------------------------------------------------------------
-- A natural=strait way is handled as a locality if it is closed and a valley
-- if it is not.
-- ----------------------------------------------------------------------------
if ((( wayt.natural == "strait" ) or
( wayt.natural == "mountain_range" ) or
( wayt.natural == "gully" )) and
(( wayt.place == nil ) or
( wayt.place == "" ))) then
if ( wayt.is_closed ) then
wayt.place = "locality"
wayt.natural = nil
else
wayt.natural = "valley"
end
end
-- ----------------------------------------------------------------------------
-- Non-closed parking area ways may actually really be something else.
-- ----------------------------------------------------------------------------
if (( wayt.amenity == "parking" ) and
( wayt.highway == "service" )) then
if ( wayt.is_closed ) then
wayt.highway = nil
else
wayt.amenity = nil
wayt.landuse = nil
end
end
-- ----------------------------------------------------------------------------
-- way waterway=fish_pass are changed to "waterway=drain"
-- Closed fish_pass ways have "area=yes" added.
-- A number of closed "waterway=drain" ways are _not_ areas.
-- ----------------------------------------------------------------------------
if ( wayt.waterway == "fish_pass" ) then
wayt.usage = nil
if ( wayt.is_closed ) then
wayt.natural = "water"
wayt.water = "fish_pass"
else
wayt.waterway = "drain"
end
end
-- ----------------------------------------------------------------------------
-- Treat ladders that have been mapped as ways as steps.
-- ----------------------------------------------------------------------------
if ( wayt.highway == "ladder" ) then
wayt.highway = "steps"
end
-- ----------------------------------------------------------------------------
-- (end of the way-specific code)
--
-- Linear transportation layer
-- ----------------------------------------------------------------------------
wr_after_transportation( wayt )
-- ----------------------------------------------------------------------------
-- Linear waterway layer
-- ----------------------------------------------------------------------------
way_after_waterway( wayt )
-- ----------------------------------------------------------------------------
-- The linearbarrier layer shouldn't have points in it, so we process that
-- here. There are some checks for "not a polygon" here for e.g. hedges.
-- ----------------------------------------------------------------------------
way_after_linearbarrier( wayt )
-- ----------------------------------------------------------------------------
-- After dealing with linear aeroways we need to deal with area ones in
-- "generic_after_function", but we don't want that to have a go at showing
-- linear ones as areas, so we remove those here. We do want it to do points,
-- which the "generic_after_function( nodet )" call above will do.
--
-- If something is a runway and is a closed way we can assume that what has
-- been mapped is the outline of the area of the linear runway (because
-- although "circular runways" are a concept -
-- https://en.wikipedia.org/wiki/Endless_runway - they are not not a thing
-- right now. However, closed circular taxiways are very much a thing, and
-- so we also check the "area" tag there. Unless area=yes is explicitly set,
-- we assume that a taxiway is linear.
-- ----------------------------------------------------------------------------
if (( not wayt.is_closed ) and
(( wayt.aeroway == "grass_runway" ) or
( wayt.aeroway == "runway" ) or
( wayt.aeroway == "taxiway" ))) then
wayt.aeroway = nil
end
if (( wayt.aeroway == "taxiway" ) and
( wayt.area ~= "yes" )) then
wayt.aeroway = nil
end
-- ----------------------------------------------------------------------------
-- The only way and relation places that we're interested in are islands and
-- localities.
-- Islets have been changed to islands in the shared lua.
-- Some other features have been set to localities.
-- ----------------------------------------------------------------------------
wr_after_place( wayt )
-- ----------------------------------------------------------------------------
-- Actually writing out most other nodes (and polygons) is done
-- in "generic_after_function"
--
-- Linear features should have been handled above.
-- ----------------------------------------------------------------------------
generic_after_function( wayt )
end -- way_function()
-- ------------------------------------------------------------------------------
-- Only certain relations are accepted.
-- See https://github.com/systemed/tilemaker/blob/master/docs/RELATIONS.md#stage-1-accepting-relations
-- Accept all route relations.
-- Once done, relation_function() will be called for each one.
-- ------------------------------------------------------------------------------
function relation_scan_function()
if (( Find("type") == "route" ) or
( Find("type") == "boundary" )) then
Accept()
end
end -- relation_scan_function()
-- ------------------------------------------------------------------------------
-- Main entry point for processing relations
-- See https://github.com/systemed/tilemaker/blob/master/docs/RELATIONS.md#writing-relation-geometries
-- ------------------------------------------------------------------------------
function relation_function()
local relationt = {}
relationt.is_closed = IsClosed()
if ( relationt.is_closed ) then
relationt.way_area = Area()
else
relationt.way_area = 0
end
update_table( relationt )
-- ------------------------------------------------------------------------------
-- In "relation_scan_function()" we've tried to accept route and boundary
-- relations only. However, I've noticed that "type=site" relations with some
-- sort of geometry also come through. An example is:
-- https://www.openstreetmap.org/relation/18135701
-- relations such as this can be suppressed here by doing something like:
--
-- if ( relationt.type ~= "site" ) then
-- rf_2( relationt )
-- end
--
-- See https://taginfo.openstreetmap.org/relations for a list of types in use.
-- However, having site relations with a geometry being processed as
-- multipolygons is something of an unexpected feature rather than a bug, so
-- these are not suppressed here.
-- ------------------------------------------------------------------------------
rf_2( relationt )
end -- relation_function()
function rf_2( relationt )
generic_before_function( relationt )
-- ----------------------------------------------------------------------------
-- Relation-specific code
-- ----------------------------------------------------------------------------
if (( relationt.type == "multipolygon" ) and
( relationt.junction == "yes" )) then
relationt.type = nil
end
-- ----------------------------------------------------------------------------
-- Note that we're not doing any per-member processing for routes - we just
-- add a highway type to the relation and ensure that the style rules for it
-- handle it sensibly, as it's going to be overlaid over other highway types.
-- "ldpnwn" is used to allow for future different processing of different
-- relations.
--
-- Name handling for cycle routes makes a special case of the National Byway.
--
-- MTB routes are processed only if they are not also another type of cycle
-- route (including LCN, which isn't actually shown in this rendering).
--
-- Processing routes,
-- Walking networks first.
-- We use "ref" rather than "name" on IWNs but not others.
-- We use "colour" as "name" if "colour" is set and "name" is not.
-- ----------------------------------------------------------------------------
if (relationt.type == "route") then
if (( relationt.network == "iwn" ) and
( relationt.ref ~= nil )) then
relationt.name = relationt.ref
end
if ((( relationt.network == "iwn" ) or
( relationt.network == "nwn" ) or
( relationt.network == "rwn" ) or
( relationt.network == "lwn" ) or
( relationt.network == "lwn;lcn" ) or
( relationt.network == "lwn;lcn;lhn" )) and
((( relationt.name ~= nil ) and
( relationt.name ~= "" )) or
(( relationt.colour ~= nil ) and
( relationt.colour ~= "" )))) then
if ((( relationt.name == nil ) or
( relationt.name == "" )) and
(( relationt.colour ~= nil ) and
( relationt.colour ~= "" ))) then
relationt.name = relationt.colour
end
relationt.highway = "ldpnwn"
-- ----------------------------------------------------------------------------
-- For the English/Welsh National trails:
-- These have a known operator, and there are a limited number of them.
-- * We add a "ref" here designed to be shown withing a black and white
-- "shield".
-- * We also consolidate names so that "names" like "King Charles III
-- England Coast Path: Folkestone to Ramsgate" get changed to just
-- "England Coast Path"
--
-- This is done in code shared with raster.
-- ----------------------------------------------------------------------------
fix_silly_nt_names_t( relationt )
-- ----------------------------------------------------------------------------
-- Some "regional" trails are also split into portions and given silly names
-- such as "Trans-Pennine Trail (Warrington to Ashton-upon-Mersey)".
-- We remove the silly part of the name, also in code shared with raster.
-- ----------------------------------------------------------------------------
fix_silly_rwn_names_t( relationt )
end -- walking
-- ----------------------------------------------------------------------------
-- Cycle networks
-- Most LCNs are ignored, but we special-case a couple worth-including.
-- We exclude some obviously silly refs.
-- We use "ref" rather than "name".
-- We handle loops on the National Byway and append (r) on other RCNs.
-- ----------------------------------------------------------------------------
if ((( relationt.network == "ncn" ) or
( relationt.network == "rcn" ) or
(( relationt.network == "lcn" ) and
(( relationt.name == "Solar System Route" ) or
( relationt.name == "Orbital Route" )))) and
((( relationt.state == nil ) or
( relationt.state == "" )) or
(( relationt.state ~= "proposed" ) and
( relationt.state ~= "construction" ) and
( relationt.state ~= "abandoned" )))) then
relationt.highway = "ldpncn"
if ( relationt.ref == "N/A" ) then
relationt.ref = nil
end
if (( relationt.name ~= nil ) and
( relationt.name ~= "" ) and
( relationt.ref == "NB" ) and
( string.match( relationt.name, "Loop" ))) then
relationt.ref = relationt.ref .. " (loop)"
end
if (( relationt.ref ~= nil ) and
( relationt.ref ~= "" )) then
relationt.name = relationt.ref
end
if (( relationt.network == "rcn" ) and
( relationt.name ~= "NB" ) and
( relationt.name ~= "NB (loop)" )) then
if (( relationt.name == nil ) or
( relationt.name == "" )) then
relationt.name = "(r)"
else
relationt.name = relationt.name .. " (r)"
end
end