Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOD: new grouped tagging system for train protection #118

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions signals.mml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ 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_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,
Expand All @@ -113,7 +114,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,
Expand All @@ -122,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
Expand All @@ -142,11 +142,12 @@ 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_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,
Expand All @@ -157,7 +158,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,
Expand All @@ -166,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
Expand All @@ -186,8 +186,8 @@ 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_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,
Expand All @@ -198,6 +198,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,
Expand All @@ -208,7 +209,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,
Expand All @@ -218,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
Expand Down
66 changes: 40 additions & 26 deletions sql/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ END;
$$ 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(
-- 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,
Expand All @@ -318,53 +319,66 @@ 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 $$
construction_etcs TEXT) RETURNS TEXT AS $$
BEGIN
/* Continental systems. They are not supposed to overlap any soon. */
IF etcs <> 'no' THEN
RETURN 10;
RETURN 'etcs';
END IF;
IF POSITION('CTCS' IN train_protection) > 0 THEN
RETURN 'ctcs';
END IF;
IF ptc <> 'no' THEN
RETURN 10;
END IF;
IF construction_etcs <> 'no' THEN
RETURN 9;
RETURN 'ptc';
END IF;
IF asfa = 'yes' THEN
RETURN 8;
IF construction_etcs <> 'no' THEN
RETURN 'etcs_construction';
END IF;
IF scmt = 'yes' THEN
RETURN 7;
/* National systems. Possible overlaps, the order here decides priority. */
IF POSITION('SCMT' IN train_protection) > 0 THEN
RETURN 'scmt';
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 6;
RETURN 'tvm';
END IF;
IF asfa = 'yes' THEN
RETURN 'asfa';
END IF;
IF kvb = 'yes' THEN
RETURN 5;
RETURN 'kvb';
END IF;
IF atc = 'yes' THEN
RETURN 5;
RETURN 'atc';
END IF;
IF COALESCE(atb, atb_eg, atb_ng, atb_vv) = 'yes' THEN
RETURN 4;
END IF;
IF zsi127 = 'yes' THEN
RETURN 3;
RETURN 'atb';
END IF;
IF lzb = 'yes' THEN
RETURN 3;
RETURN 'lzb';
END IF;
IF pzb = 'yes' THEN
RETURN 2;
RETURN 'pzb';
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
RETURN 1;
/* Regional systems. */
IF zsi127 = 'yes' THEN
RETURN 'zsi127';
END IF;
RETURN 0;
/* 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;
/* No information. */
RETURN 'unknown';
END;
$$ LANGUAGE plpgsql;

Expand Down
51 changes: 25 additions & 26 deletions train_protection.mss
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"="ctcs"] {
line-color: @ctcs_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"] {
Expand Down