Skip to content

Commit 24e502c

Browse files
committed
MOD: new grouped tagging system for train protection
1 parent 3b91755 commit 24e502c

File tree

3 files changed

+119
-49
lines changed

3 files changed

+119
-49
lines changed

signals.mml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ Layer:
9898
NULL AS construction_usage, NULL AS construction_service,
9999
NULL AS preserved_railway, NULL AS preserved_service,
100100
NULL AS preserved_usage,
101-
pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs,
102-
railway_train_protection_rank(pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, zsi127, etcs, construction_etcs) AS rank
101+
train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs,
102+
railway_train_protection_rank(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS rank,
103+
railway_train_protection_rendered(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS train_protection_rendered
103104
FROM
104105
(SELECT
105106
way, railway, usage,
107+
tags->'railway:train_protection' AS train_protection,
106108
tags->'railway:pzb' AS pzb,
107109
railway_null_to_no(tags->'railway:lzb') AS lzb,
108110
tags->'railway:zsi127' as zsi127,
@@ -113,7 +115,6 @@ Layer:
113115
tags->'railway:atc' AS atc,
114116
tags->'railway:kvb' AS kvb,
115117
tags->'railway:tvm' AS tvm,
116-
tags->'railway:scmt' AS scmt,
117118
tags->'railway:asfa' AS asfa,
118119
railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc,
119120
railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs,
@@ -142,11 +143,13 @@ Layer:
142143
NULL AS construction_usage, NULL AS construction_service,
143144
NULL AS preserved_railway, NULL AS preserved_service,
144145
NULL AS preserved_usage,
145-
pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs,
146-
railway_train_protection_rank(pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, zsi127, etcs, construction_etcs) AS rank
146+
train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs,
147+
railway_train_protection_rank(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS rank,
148+
railway_train_protection_rendered(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS train_protection_rendered
147149
FROM
148150
(SELECT
149151
way, railway, usage,
152+
tags->'railway:train_protection' AS train_protection,
150153
tags->'railway:pzb' AS pzb,
151154
railway_null_to_no(tags->'railway:lzb') AS lzb,
152155
tags->'railway:zsi127' AS zsi127,
@@ -157,7 +160,6 @@ Layer:
157160
tags->'railway:atc' AS atc,
158161
tags->'railway:kvb' AS kvb,
159162
tags->'railway:tvm' AS tvm,
160-
tags->'railway:scmt' AS scmt,
161163
tags->'railway:asfa' AS asfa,
162164
railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc,
163165
railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs,
@@ -186,8 +188,9 @@ Layer:
186188
construction_usage, construction_service,
187189
preserved_railway, preserved_service,
188190
preserved_usage,
189-
pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs,
190-
railway_train_protection_rank(pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, zsi127, etcs, construction_etcs) AS rank
191+
train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs,
192+
railway_train_protection_rank(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS rank,
193+
railway_train_protection_rendered(train_protection, pzb, lzb, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, zsi127, etcs, construction_etcs) AS train_protection_rendered
191194
FROM
192195
(SELECT
193196
way, railway, usage, service,
@@ -198,6 +201,7 @@ Layer:
198201
tags->'construction:usage' AS construction_usage, tags->'construction:service' AS construction_service,
199202
tags->'preserved:railway' AS preserved_railway, tags->'preserved:service' AS preserved_service,
200203
tags->'preserved:usage' AS preserved_usage,
204+
tags->'railway:train_protection' AS train_protection,
201205
tags->'railway:pzb' AS pzb,
202206
railway_null_to_no(tags->'railway:lzb') AS lzb,
203207
tags->'railway:zsi127' AS zsi127,
@@ -208,7 +212,6 @@ Layer:
208212
tags->'railway:atc' AS atc,
209213
tags->'railway:kvb' AS kvb,
210214
tags->'railway:tvm' AS tvm,
211-
tags->'railway:scmt' AS scmt,
212215
tags->'railway:asfa' AS asfa,
213216
railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc,
214217
railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs,

sql/functions.sql

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ $$ LANGUAGE plpgsql;
307307

308308

309309
-- Get rank by train protection a track is equipped with
310-
-- Other code expects 1 for no protection, 0 for default/unknown
311310
CREATE OR REPLACE FUNCTION railway_train_protection_rank(
311+
train_protection TEXT,
312312
pzb TEXT,
313313
lzb TEXT,
314314
atb TEXT,
@@ -318,57 +318,129 @@ CREATE OR REPLACE FUNCTION railway_train_protection_rank(
318318
atc TEXT,
319319
kvb TEXT,
320320
tvm TEXT,
321-
scmt TEXT,
322321
asfa TEXT,
323322
ptc TEXT,
324323
zsi127 TEXT,
325324
etcs TEXT,
326325
construction_etcs TEXT) RETURNS INTEGER AS $$
327326
BEGIN
327+
/* Continental systems. */
328328
IF etcs <> 'no' THEN
329329
RETURN 10;
330330
END IF;
331331
IF ptc <> 'no' THEN
332332
RETURN 10;
333-
END IF;
333+
END IF;
334334
IF construction_etcs <> 'no' THEN
335335
RETURN 9;
336336
END IF;
337-
IF asfa = 'yes' THEN
338-
RETURN 8;
337+
/* National systems. */
338+
IF POSITION('SCMT' IN train_protection) > 0 THEN
339+
RETURN 6;
339340
END IF;
340-
IF scmt = 'yes' THEN
341-
RETURN 7;
341+
IF asfa = 'yes' THEN
342+
RETURN 6;
342343
END IF;
343344
IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN
344345
RETURN 6;
345346
END IF;
346347
IF kvb = 'yes' THEN
347-
RETURN 5;
348+
RETURN 6;
348349
END IF;
349350
IF atc = 'yes' THEN
350-
RETURN 5;
351+
RETURN 6;
351352
END IF;
352353
IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN
353-
RETURN 4;
354-
END IF;
355-
IF zsi127 = 'yes' THEN
356-
RETURN 3;
354+
RETURN 6;
357355
END IF;
358356
IF lzb = 'yes' THEN
359-
RETURN 3;
357+
RETURN 6;
360358
END IF;
361359
IF pzb = 'yes' THEN
362-
RETURN 2;
360+
RETURN 6;
363361
END IF;
364-
IF (pzb = 'no' AND lzb = 'no' AND etcs = 'no') OR (atb = 'no' AND etcs = 'no') OR (atc = 'no' AND etcs = 'no') OR (scmt = 'no' AND etcs = 'no') OR (asfa = 'no' AND etcs = 'no') OR (kvb = 'no' AND tvm = 'no' AND etcs = 'no') OR (zsi127 = 'no') THEN
362+
/* Regional systems. */
363+
IF zsi127 = 'yes' THEN
364+
RETURN 3;
365+
END IF;
366+
/* No system. */
367+
IF (pzb = 'no' AND lzb = 'no' AND etcs = 'no') OR (atb = 'no' AND etcs = 'no') OR (atc = 'no' AND etcs = 'no') OR (asfa = 'no' AND etcs = 'no') OR (kvb = 'no' AND tvm = 'no' AND etcs = 'no') OR (zsi127 = 'no') THEN
365368
RETURN 1;
366369
END IF;
370+
/* No information. */
367371
RETURN 0;
368372
END;
369373
$$ LANGUAGE plpgsql;
370374

371375

376+
-- Get which train protection system has to be rendered.
377+
-- Overlaps are not foreseen but the logic could be handled here.
378+
CREATE OR REPLACE FUNCTION railway_train_protection_rendered(
379+
train_protection TEXT,
380+
pzb TEXT,
381+
lzb TEXT,
382+
atb TEXT,
383+
atb_eg TEXT,
384+
atb_ng TEXT,
385+
atb_vv TEXT,
386+
atc TEXT,
387+
kvb TEXT,
388+
tvm TEXT,
389+
asfa TEXT,
390+
ptc TEXT,
391+
zsi127 TEXT,
392+
etcs TEXT,
393+
construction_etcs TEXT) RETURNS TEXT AS $$
394+
BEGIN
395+
/* Continental systems. They are not supposed to overlap any soon. */
396+
IF etcs <> 'no' THEN
397+
RETURN 'etcs';
398+
END IF;
399+
IF ptc <> 'no' THEN
400+
RETURN 'ptc';
401+
END IF;
402+
IF construction_etcs <> 'no' THEN
403+
RETURN 'etcs_construction';
404+
END IF;
405+
/* National systems. Possible overlaps, the order here decides priority. */
406+
IF POSITION('SCMT' IN train_protection) > 0 THEN
407+
RETURN 'scmt';
408+
END IF;
409+
IF asfa = 'yes' THEN
410+
RETURN 'asfa';
411+
END IF;
412+
IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN
413+
RETURN 'tvm';
414+
END IF;
415+
IF kvb = 'yes' THEN
416+
RETURN 'kvb';
417+
END IF;
418+
IF atc = 'yes' THEN
419+
RETURN 'atc';
420+
END IF;
421+
IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN
422+
RETURN 'atb';
423+
END IF;
424+
IF lzb = 'yes' THEN
425+
RETURN 'lzb';
426+
END IF;
427+
IF pzb = 'yes' THEN
428+
RETURN 'pzb';
429+
END IF;
430+
/* Regional systems. */
431+
IF zsi127 = 'yes' THEN
432+
RETURN 'zsi127';
433+
END IF;
434+
/* No system. */
435+
IF (pzb = 'no' AND lzb = 'no' AND etcs = 'no') OR (atb = 'no' AND etcs = 'no') OR (atc = 'no' AND etcs = 'no') OR (asfa = 'no' AND etcs = 'no') OR (kvb = 'no' AND tvm = 'no' AND etcs = 'no') OR (zsi127 = 'no') THEN
436+
RETURN 'none';
437+
END IF;
438+
/* No information. */
439+
RETURN 'unknown';
440+
END;
441+
$$ LANGUAGE plpgsql;
442+
443+
372444
-- Get name for labelling in standard style depending whether it is a bridge, a tunnel or none of these two.
373445
CREATE OR REPLACE FUNCTION railway_label_name(name TEXT, tags HSTORE, tunnel TEXT, bridge TEXT) RETURNS TEXT AS $$
374446
BEGIN

train_protection.mss

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,48 +60,43 @@
6060
[zoom>=13]["railway"="light_rail"],
6161
[zoom>=11]["railway"="tram"]["service"=null],
6262
[zoom>=13]["railway"="tram"] {
63-
["rank"=1] { /* shortcut: SQL functions set rank=1 for 'no protection' */
63+
["train_protection_rendered"="none"] {
6464
line-color: @no_train_protection_color;
6565
}
66-
["pzb"="yes"] {
66+
["train_protection_rendered"="etcs"] {
67+
line-color: @etcs_color;
68+
}
69+
["train_protection_rendered"="etcs_construction"] {
70+
line-color: @etcs_construction_color;
71+
}
72+
["train_protection_rendered"="scmt"] {
73+
line-color: @scmt_color;
74+
}
75+
["train_protection_rendered"="pzb"] {
6776
line-color: @pzb_color;
6877
}
69-
["lzb"="yes"] {
78+
["train_protection_rendered"="lzb"] {
7079
line-color: @lzb_color;
7180
}
72-
["atb"="yes"],
73-
["atb_eg"="yes"],
74-
["atb_ng"="yes"],
75-
["atb_vv"="yes"] {
81+
["train_protection_rendered"="atb"] {
7682
line-color: @atb_color;
7783
}
78-
["atc"="yes"] {
84+
["train_protection_rendered"="atc"] {
7985
line-color: @atc_color;
8086
}
81-
["scmt"="yes"] {
82-
line-color: @scmt_color;
83-
}
84-
["asfa"="yes"] {
87+
["train_protection_rendered"="asfa"] {
8588
line-color: @asfa_color;
8689
}
87-
["kvb"="yes"] {
90+
["train_protection_rendered"="kvb"] {
8891
line-color: @kvb_color;
8992
}
90-
["tvm"="yes"],
91-
["tvm"="430"],
92-
["tvm"="300"] {
93+
["train_protection_rendered"="tvm"] {
9394
line-color: @tvm_color;
9495
}
95-
["etcs"!="no"] {
96-
line-color: @etcs_color;
97-
}
98-
["construction_etcs"!="no"] {
99-
line-color: @etcs_construction_color;
100-
}
101-
["ptc"!="no"] {
96+
["train_protection_rendered"="ptc"] {
10297
line-color: @ptc_color;
10398
}
104-
["zsi127"="yes"] {
99+
["train_protection_rendered"="zsi127"] {
105100
line-color: @zsi127_color;
106101
}
107102
["railway"="construction"] {

0 commit comments

Comments
 (0)