From 24e502c635aa1ae695c4bf32d4d3ea4a50fe8578 Mon Sep 17 00:00:00 2001 From: Davide Cester Date: Tue, 21 Nov 2023 10:00:02 +0100 Subject: [PATCH 1/3] MOD: new grouped tagging system for train protection --- signals.mml | 21 +++++---- sql/functions.sql | 104 ++++++++++++++++++++++++++++++++++++------- train_protection.mss | 43 ++++++++---------- 3 files changed, 119 insertions(+), 49 deletions(-) diff --git a/signals.mml b/signals.mml index 7796e02f..f2092761 100644 --- a/signals.mml +++ b/signals.mml @@ -98,11 +98,13 @@ Layer: NULL AS construction_usage, NULL AS construction_service, NULL AS preserved_railway, NULL AS preserved_service, NULL AS preserved_usage, - pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs, - 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 + train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, + 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, + 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 FROM (SELECT way, railway, usage, + tags->'railway:train_protection' AS train_protection, tags->'railway:pzb' AS pzb, railway_null_to_no(tags->'railway:lzb') AS lzb, tags->'railway:zsi127' as zsi127, @@ -113,7 +115,6 @@ Layer: tags->'railway:atc' AS atc, tags->'railway:kvb' AS kvb, tags->'railway:tvm' AS tvm, - tags->'railway:scmt' AS scmt, tags->'railway:asfa' AS asfa, railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc, railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs, @@ -142,11 +143,13 @@ Layer: NULL AS construction_usage, NULL AS construction_service, NULL AS preserved_railway, NULL AS preserved_service, NULL AS preserved_usage, - pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs, - 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 + train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, + 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, + 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 FROM (SELECT way, railway, usage, + tags->'railway:train_protection' AS train_protection, tags->'railway:pzb' AS pzb, railway_null_to_no(tags->'railway:lzb') AS lzb, tags->'railway:zsi127' AS zsi127, @@ -157,7 +160,6 @@ Layer: tags->'railway:atc' AS atc, tags->'railway:kvb' AS kvb, tags->'railway:tvm' AS tvm, - tags->'railway:scmt' AS scmt, tags->'railway:asfa' AS asfa, railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc, railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs, @@ -186,8 +188,9 @@ Layer: construction_usage, construction_service, preserved_railway, preserved_service, preserved_usage, - pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, scmt, asfa, ptc, etcs, construction_etcs, - 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 + train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, + 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, + 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 FROM (SELECT way, railway, usage, service, @@ -198,6 +201,7 @@ Layer: tags->'construction:usage' AS construction_usage, tags->'construction:service' AS construction_service, tags->'preserved:railway' AS preserved_railway, tags->'preserved:service' AS preserved_service, tags->'preserved:usage' AS preserved_usage, + tags->'railway:train_protection' AS train_protection, tags->'railway:pzb' AS pzb, railway_null_to_no(tags->'railway:lzb') AS lzb, tags->'railway:zsi127' AS zsi127, @@ -208,7 +212,6 @@ Layer: tags->'railway:atc' AS atc, tags->'railway:kvb' AS kvb, tags->'railway:tvm' AS tvm, - tags->'railway:scmt' AS scmt, tags->'railway:asfa' AS asfa, railway_null_or_zero_to_no(tags->'railway:ptc') AS ptc, railway_null_or_zero_to_no(tags->'railway:etcs') AS etcs, diff --git a/sql/functions.sql b/sql/functions.sql index bc765015..ced363a2 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -307,8 +307,8 @@ $$ LANGUAGE plpgsql; -- Get rank by train protection a track is equipped with --- Other code expects 1 for no protection, 0 for default/unknown CREATE OR REPLACE FUNCTION railway_train_protection_rank( + train_protection TEXT, pzb TEXT, lzb TEXT, atb TEXT, @@ -318,57 +318,129 @@ CREATE OR REPLACE FUNCTION railway_train_protection_rank( atc TEXT, kvb TEXT, tvm TEXT, - scmt TEXT, asfa TEXT, ptc TEXT, zsi127 TEXT, etcs TEXT, construction_etcs TEXT) RETURNS INTEGER AS $$ BEGIN + /* Continental systems. */ IF etcs <> 'no' THEN RETURN 10; END IF; IF ptc <> 'no' THEN RETURN 10; - END IF; + END IF; IF construction_etcs <> 'no' THEN RETURN 9; END IF; - IF asfa = 'yes' THEN - RETURN 8; + /* National systems. */ + IF POSITION('SCMT' IN train_protection) > 0 THEN + RETURN 6; END IF; - IF scmt = 'yes' THEN - RETURN 7; + IF asfa = 'yes' THEN + RETURN 6; END IF; IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN RETURN 6; END IF; IF kvb = 'yes' THEN - RETURN 5; + RETURN 6; END IF; IF atc = 'yes' THEN - RETURN 5; + RETURN 6; END IF; IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN - RETURN 4; - END IF; - IF zsi127 = 'yes' THEN - RETURN 3; + RETURN 6; END IF; IF lzb = 'yes' THEN - RETURN 3; + RETURN 6; END IF; IF pzb = 'yes' THEN - RETURN 2; + RETURN 6; END IF; - 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 + /* Regional systems. */ + IF zsi127 = 'yes' THEN + RETURN 3; + END IF; + /* No system. */ + 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 RETURN 1; END IF; + /* No information. */ RETURN 0; END; $$ LANGUAGE plpgsql; +-- Get which train protection system has to be rendered. +-- Overlaps are not foreseen but the logic could be handled here. +CREATE OR REPLACE FUNCTION railway_train_protection_rendered( + train_protection TEXT, + pzb TEXT, + lzb TEXT, + atb TEXT, + atb_eg TEXT, + atb_ng TEXT, + atb_vv TEXT, + atc TEXT, + kvb TEXT, + tvm TEXT, + asfa TEXT, + ptc TEXT, + zsi127 TEXT, + etcs TEXT, + construction_etcs TEXT) RETURNS TEXT AS $$ +BEGIN + /* Continental systems. They are not supposed to overlap any soon. */ + IF etcs <> 'no' THEN + RETURN 'etcs'; + END IF; + IF ptc <> 'no' THEN + RETURN 'ptc'; + END IF; + IF construction_etcs <> 'no' THEN + RETURN 'etcs_construction'; + END IF; + /* National systems. Possible overlaps, the order here decides priority. */ + IF POSITION('SCMT' IN train_protection) > 0 THEN + RETURN 'scmt'; + END IF; + IF asfa = 'yes' THEN + RETURN 'asfa'; + END IF; + IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN + RETURN 'tvm'; + END IF; + IF kvb = 'yes' THEN + RETURN 'kvb'; + END IF; + IF atc = 'yes' THEN + RETURN 'atc'; + END IF; + IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN + RETURN 'atb'; + END IF; + IF lzb = 'yes' THEN + RETURN 'lzb'; + END IF; + IF pzb = 'yes' THEN + RETURN 'pzb'; + END IF; + /* Regional systems. */ + IF zsi127 = 'yes' THEN + RETURN 'zsi127'; + END IF; + /* No system. */ + 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 + RETURN 'none'; + END IF; + /* No information. */ + RETURN 'unknown'; +END; +$$ LANGUAGE plpgsql; + + -- Get name for labelling in standard style depending whether it is a bridge, a tunnel or none of these two. CREATE OR REPLACE FUNCTION railway_label_name(name TEXT, tags HSTORE, tunnel TEXT, bridge TEXT) RETURNS TEXT AS $$ BEGIN diff --git a/train_protection.mss b/train_protection.mss index a86e5fd3..6102b701 100644 --- a/train_protection.mss +++ b/train_protection.mss @@ -60,48 +60,43 @@ [zoom>=13]["railway"="light_rail"], [zoom>=11]["railway"="tram"]["service"=null], [zoom>=13]["railway"="tram"] { - ["rank"=1] { /* shortcut: SQL functions set rank=1 for 'no protection' */ + ["train_protection_rendered"="none"] { line-color: @no_train_protection_color; } - ["pzb"="yes"] { + ["train_protection_rendered"="etcs"] { + line-color: @etcs_color; + } + ["train_protection_rendered"="etcs_construction"] { + line-color: @etcs_construction_color; + } + ["train_protection_rendered"="scmt"] { + line-color: @scmt_color; + } + ["train_protection_rendered"="pzb"] { line-color: @pzb_color; } - ["lzb"="yes"] { + ["train_protection_rendered"="lzb"] { line-color: @lzb_color; } - ["atb"="yes"], - ["atb_eg"="yes"], - ["atb_ng"="yes"], - ["atb_vv"="yes"] { + ["train_protection_rendered"="atb"] { line-color: @atb_color; } - ["atc"="yes"] { + ["train_protection_rendered"="atc"] { line-color: @atc_color; } - ["scmt"="yes"] { - line-color: @scmt_color; - } - ["asfa"="yes"] { + ["train_protection_rendered"="asfa"] { line-color: @asfa_color; } - ["kvb"="yes"] { + ["train_protection_rendered"="kvb"] { line-color: @kvb_color; } - ["tvm"="yes"], - ["tvm"="430"], - ["tvm"="300"] { + ["train_protection_rendered"="tvm"] { line-color: @tvm_color; } - ["etcs"!="no"] { - line-color: @etcs_color; - } - ["construction_etcs"!="no"] { - line-color: @etcs_construction_color; - } - ["ptc"!="no"] { + ["train_protection_rendered"="ptc"] { line-color: @ptc_color; } - ["zsi127"="yes"] { + ["train_protection_rendered"="zsi127"] { line-color: @zsi127_color; } ["railway"="construction"] { From 0b4cc674b91e45caac9f35e5a830edcbc035029d Mon Sep 17 00:00:00 2001 From: Davide Cester Date: Thu, 7 Dec 2023 13:16:19 +0100 Subject: [PATCH 2/3] DEL: removed function railway_train_protection_rank() --- signals.mml | 10 +++---- sql/functions.sql | 67 ----------------------------------------------- 2 files changed, 3 insertions(+), 74 deletions(-) diff --git a/signals.mml b/signals.mml index f2092761..e8502e0b 100644 --- a/signals.mml +++ b/signals.mml @@ -99,7 +99,6 @@ Layer: NULL AS preserved_railway, NULL AS preserved_service, NULL AS preserved_usage, train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, - 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, 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 FROM (SELECT @@ -123,7 +122,7 @@ Layer: WHERE railway = 'rail' AND usage IN ('main', 'branch') AND service IS NULL ) AS r ORDER BY - rank NULLS LAST + train_protection_rendered NULLS LAST ) AS openrailwaymap_line_low properties: maxzoom: 7 @@ -144,7 +143,6 @@ Layer: NULL AS preserved_railway, NULL AS preserved_service, NULL AS preserved_usage, train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, - 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, 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 FROM (SELECT @@ -168,7 +166,7 @@ Layer: WHERE railway = 'rail' AND usage = 'main' AND service IS NULL ) AS r ORDER BY - rank NULLS LAST + train_protection_rendered NULLS LAST ) AS railway_line_med properties: minzoom: 8 @@ -189,7 +187,6 @@ Layer: preserved_railway, preserved_service, preserved_usage, train_protection, pzb, lzb, zsi127, atb, atb_eg, atb_ng, atb_vv, atc, kvb, tvm, asfa, ptc, etcs, construction_etcs, - 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, 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 FROM (SELECT @@ -221,8 +218,7 @@ Layer: WHERE railway IN ('rail', 'tram', 'light_rail', 'subway', 'narrow_gauge', 'disused', 'construction', 'preserved') ) AS r ORDER BY - layer, - rank NULLS LAST + layer, train_protection_rendered NULLS LAST ) AS railway_line_fill properties: minzoom: 9 diff --git a/sql/functions.sql b/sql/functions.sql index ced363a2..fc915d71 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -306,73 +306,6 @@ END; $$ LANGUAGE plpgsql; --- Get rank by train protection a track is equipped with -CREATE OR REPLACE FUNCTION railway_train_protection_rank( - train_protection TEXT, - pzb TEXT, - lzb TEXT, - atb TEXT, - atb_eg TEXT, - atb_ng TEXT, - atb_vv TEXT, - atc TEXT, - kvb TEXT, - tvm TEXT, - asfa TEXT, - ptc TEXT, - zsi127 TEXT, - etcs TEXT, - construction_etcs TEXT) RETURNS INTEGER AS $$ -BEGIN - /* Continental systems. */ - IF etcs <> 'no' THEN - RETURN 10; - END IF; - IF ptc <> 'no' THEN - RETURN 10; - END IF; - IF construction_etcs <> 'no' THEN - RETURN 9; - END IF; - /* National systems. */ - IF POSITION('SCMT' IN train_protection) > 0 THEN - RETURN 6; - END IF; - IF asfa = 'yes' THEN - RETURN 6; - END IF; - IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN - RETURN 6; - END IF; - IF kvb = 'yes' THEN - RETURN 6; - END IF; - IF atc = 'yes' THEN - RETURN 6; - END IF; - IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN - RETURN 6; - END IF; - IF lzb = 'yes' THEN - RETURN 6; - END IF; - IF pzb = 'yes' THEN - RETURN 6; - END IF; - /* Regional systems. */ - IF zsi127 = 'yes' THEN - RETURN 3; - END IF; - /* No system. */ - 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 - RETURN 1; - END IF; - /* No information. */ - RETURN 0; -END; -$$ LANGUAGE plpgsql; - - -- Get which train protection system has to be rendered. -- Overlaps are not foreseen but the logic could be handled here. CREATE OR REPLACE FUNCTION railway_train_protection_rendered( From 759d3ae8006019005b8b04a705773951cfee7e51 Mon Sep 17 00:00:00 2001 From: Davide Cester Date: Fri, 8 Dec 2023 17:01:02 +0100 Subject: [PATCH 3/3] MOD: added CTCS and TVM with the new tagging, recolored PTC --- sql/functions.sql | 17 +++++++++++++---- train_protection.mss | 8 ++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sql/functions.sql b/sql/functions.sql index fc915d71..a1cfd2dc 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -329,6 +329,9 @@ BEGIN IF etcs <> 'no' THEN RETURN 'etcs'; END IF; + IF POSITION('CTCS' IN train_protection) > 0 THEN + RETURN 'ctcs'; + END IF; IF ptc <> 'no' THEN RETURN 'ptc'; END IF; @@ -339,12 +342,15 @@ BEGIN IF POSITION('SCMT' IN train_protection) > 0 THEN RETURN 'scmt'; END IF; - IF asfa = 'yes' THEN - RETURN 'asfa'; - END IF; + IF POSITION('TVM' IN train_protection) > 0 THEN + RETURN 'tvm'; + END IF; IF tvm = 'yes' OR tvm = '430' OR tvm = '300' THEN RETURN 'tvm'; END IF; + IF asfa = 'yes' THEN + RETURN 'asfa'; + END IF; IF kvb = 'yes' THEN RETURN 'kvb'; END IF; @@ -354,7 +360,7 @@ BEGIN IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN RETURN 'atb'; END IF; - IF lzb = 'yes' THEN + IF lzb = 'yes' THEN RETURN 'lzb'; END IF; IF pzb = 'yes' THEN @@ -365,6 +371,9 @@ BEGIN RETURN 'zsi127'; END IF; /* No system. */ + IF train_protection = 'none' THEN + RETURN 'none'; + END IF; 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 RETURN 'none'; END IF; diff --git a/train_protection.mss b/train_protection.mss index 6102b701..f76594c8 100644 --- a/train_protection.mss +++ b/train_protection.mss @@ -11,9 +11,10 @@ @atc_color: #6600cc; @scmt_color: #dd11ff; @asfa_color: #ff9092; -@kvb_color: #66cc33; +@kvb_color: #88cc00; @tvm_color: #009966; -@ptc_color: #cc0033; +@ptc_color: #44cc66; +@ctcs_color: #ee0000; @etcs_color: blue; @etcs_construction_color: #87CEFA; @@ -69,6 +70,9 @@ ["train_protection_rendered"="etcs_construction"] { line-color: @etcs_construction_color; } + ["train_protection_rendered"="ctcs"] { + line-color: @ctcs_color; + } ["train_protection_rendered"="scmt"] { line-color: @scmt_color; }