From 4214bd3c0b9e9013ce3742f06959a6cbe1767360 Mon Sep 17 00:00:00 2001 From: Davide Cester Date: Tue, 21 Nov 2023 10:00:02 +0100 Subject: [PATCH] MOD: new grouped tagging system for train protection --- signals.mml | 21 +++++---- sql/functions.sql | 104 ++++++++++++++++++++++++++++++++++++------- train_protection.mss | 47 ++++++++++--------- 3 files changed, 123 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..81490ccd 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. They are not supposed to overlap any soon. */ 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. Possible overlaps, the order here decides priority. */ + 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. Possible overlaps, the order here decides priority. */ + 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..e5d4e329 100644 --- a/train_protection.mss +++ b/train_protection.mss @@ -14,6 +14,7 @@ @kvb_color: #66cc33; @tvm_color: #009966; @ptc_color: #cc0033; +@ctcs_color: orange; @etcs_color: blue; @etcs_construction_color: #87CEFA; @@ -60,48 +61,46 @@ [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"="ctcs"] { + line-color: @ctcs_color; + } + ["train_protection_rendered"="zsi127"] { line-color: @zsi127_color; } ["railway"="construction"] {