From cf4c40edb35c9bfc7c2bc15676e09ef07008aaab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= <skunk@xover.mud.at>
Date: Sat, 16 Mar 2019 07:58:21 +0100
Subject: [PATCH 1/3] railway-gauge: show gauges of railway

---
 index.json         |  3 ++
 railway-gauge.json | 77 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 railway-gauge.json

diff --git a/index.json b/index.json
index ba5a57d..be443ad 100644
--- a/index.json
+++ b/index.json
@@ -317,6 +317,9 @@
                         {
                             "id": "railway-maxspeed"
                         },
+                        {
+                            "id": "railway-gauge"
+                        },
                         {
                             "id": "railway-routes"
                         }
diff --git a/railway-gauge.json b/railway-gauge.json
new file mode 100644
index 0000000..090a5d0
--- /dev/null
+++ b/railway-gauge.json
@@ -0,0 +1,77 @@
+{
+    "type": "overpass",
+    "name": {
+        "en": "Railway gauge"
+    },
+    "query": {
+        "11": "way[railway=rail][railway!~'^(platform|abandoned|disused|station|proposed|subway_entrance)$'][usage~'^(main|branch)$'];",
+        "14": "way[railway][railway!~'^(platform|abandoned|disused|station|proposed|subway_entrance)$'];"
+    },
+    "feature": {
+        "pre": "{% set gauges = tags.gauge|split(';') %}",
+        "title": "{% if tags.ref %}{{ localizedTag(tags, 'ref') }} - {% endif %}{{ localizedTag(tags, 'name')|default(localizedTag(tags, 'operator'))|default(trans('unnamed')) }}",
+        "description": "{{ tags.gauge|default(trans('unknown'))|enumerate }}",
+        "body": [
+            "{{ tagTrans('railway', tags.railway) }}<br/>",
+            "{% if tags.operator %}{{ keyTrans('operator') }}: {{ localizedTag(tags, 'operator') }}<br>{% endif %}",
+            "{% if tags.usage %}{{ keyTrans('usage') }}: {{ tagTrans('usage', tags.usage)|default(trans('unknown')) }}<br/>{% endif %}",
+            "{% if tags.service %}{{ keyTrans('service') }}: {{ tagTrans('service', tags.service ) }}<br/>{% endif %}",
+            "{{ keyTrans('gauge') }}: {{ tags.gauge|default(trans('unknown'))|enumerate }}<br/>",
+            "{% if tags.electrified == 'no' %}{{ keyTrans('electrified') }}: {{ tagTrans('electrified', 'no') }}{% elseif tags.electrified %}{{ keyTrans('electrified') }}: {{ tagTrans('electrified', tags.electrified) }}, {{ keyTrans('voltage') }}: {{ tags.voltage|default(trans('unknown')) }}, {{ keyTrans('frequency') }}: {{ tags.frequency|default(trans('unknown')) }}<br/>{% endif %}"
+        ],
+        "markerSymbol": null,
+        "listMarkerSymbol": "line",
+        "styles": "{% if gauges|length < 2 %}default{% else %}{% for i, v in gauges %}{% if i != 0 %},{% endif %}gauge{{ i }}{% endfor %}{% endif %}",
+        "style": {
+            "width": "3",
+            "color": "{% if tags.gauge %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[0] / 2000) }}{% else %}#404040{% endif %}"
+        },
+        "style:gauge0": {
+            "width": "3",
+            "lineCap": "butt",
+            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[0] / 2000) }}",
+            "dashArray": "5,{{ (gauges|length - 1) * 5 }}"
+        },
+        "style:gauge1": {
+            "width": "3",
+            "lineCap": "butt",
+            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[1] / 2000) }}",
+            "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
+            "dashOffset": "5"
+        },
+        "style:gauge2": {
+            "width": "3",
+            "lineCap": "butt",
+            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[2] / 2000) }}",
+            "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
+            "dashOffset": "10"
+        },
+        "style:gauge3": {
+            "width": "3",
+            "lineCap": "butt",
+            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[3] / 2000) }}",
+            "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
+            "dashOffset": "15"
+        }
+    },
+    "info": [
+        "<table>",
+        "  {% set color = '#404040' %}",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': color })|raw }}</td>",
+        "    <td>{{ trans('unknown') }}</td>",
+        "  </tr>",
+        "{% for i in range(0, 1800, 250) %}",
+        "  {% set color = colorInterpolate([ '#00ff00', '#0000ff' ], i / 2000) %}",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': color })|raw }}</td>",
+        "    <td>{{ i }}mm</td>",
+        "  </tr>",
+        "{% endfor %}",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': '#0000ff' })|raw }}</td>",
+        "    <td>>2000mm</td>",
+        "  </tr>",
+        "</table>"
+    ]
+}

From 45250b6652c4558dd63eefdbb1f6f569f28b27e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= <skunk@xover.mud.at>
Date: Sat, 16 Mar 2019 21:52:27 +0100
Subject: [PATCH 2/3] railway-gauge: check illegal values

---
 railway-gauge.json | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/railway-gauge.json b/railway-gauge.json
index 090a5d0..da217cb 100644
--- a/railway-gauge.json
+++ b/railway-gauge.json
@@ -24,38 +24,43 @@
         "styles": "{% if gauges|length < 2 %}default{% else %}{% for i, v in gauges %}{% if i != 0 %},{% endif %}gauge{{ i }}{% endfor %}{% endif %}",
         "style": {
             "width": "3",
-            "color": "{% if tags.gauge %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[0] / 2000) }}{% else %}#404040{% endif %}"
+            "color": "{% if tags.gauge %}{% if not tags.gauge|matches('^\\d+$') %}#ff0000{% else %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], tags.gauge / 2000) }}{% endif %}{% else %}#404040{% endif %}"
         },
         "style:gauge0": {
             "width": "3",
             "lineCap": "butt",
-            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[0] / 2000) }}",
+            "color": "{% if not gauges[0]|matches('^[0-9]+$') %}#ff0000{% else %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[0] / 2000) }}{% endif %}",
             "dashArray": "5,{{ (gauges|length - 1) * 5 }}"
         },
         "style:gauge1": {
             "width": "3",
             "lineCap": "butt",
-            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[1] / 2000) }}",
+            "color": "{% if not gauges[1]|matches('^[0-9]+$') %}#ff0000{% else %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[1] / 2000) }}{% endif %}",
             "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
             "dashOffset": "5"
         },
         "style:gauge2": {
             "width": "3",
             "lineCap": "butt",
-            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[2] / 2000) }}",
+            "color": "{% if not gauges[2]|matches('^\\d+$') %}#ff0000{% else %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[2] / 2000) }}{% endif %}",
             "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
             "dashOffset": "10"
         },
         "style:gauge3": {
             "width": "3",
             "lineCap": "butt",
-            "color": "{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[3] / 2000) }}",
+            "color": "{% if not gauges[3]|matches('^\\d+$') %}#ff0000{% else %}{{ colorInterpolate([ '#00ff00', '#0000ff' ], gauges[3] / 2000) }}{% endif %}",
             "dashArray": "5,{{ (gauges|length - 1) * 5 }}",
             "dashOffset": "15"
         }
     },
     "info": [
         "<table>",
+        "  {% set color = '#ff0000' %}",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': color })|raw }}</td>",
+        "    <td>{{ trans('illegal value') }}</td>",
+        "  </tr>",
         "  {% set color = '#404040' %}",
         "  <tr>",
         "    <td>{{ markerLine({ 'width': 3, 'color': color })|raw }}</td>",

From 744d1807e4b74f7964917e807f4f34bdd0ecd9ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= <skunk@xover.mud.at>
Date: Sat, 16 Mar 2019 21:52:43 +0100
Subject: [PATCH 3/3] railway-electrification: check illegal values

---
 railway-electrification.json | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/railway-electrification.json b/railway-electrification.json
index f54ba20..f116ad1 100644
--- a/railway-electrification.json
+++ b/railway-electrification.json
@@ -15,14 +15,18 @@
     "feature": {
         "pre": [
             "{% if tags.electrified and tags.electrified != 'no' %}",
-            "  {% if tags.voltage < 1000 %}",
+            "  {% if not tags.voltage is defined %}",
+            "    {% set color = '#7f7f7f' %}",
+            "  {% elseif not tags.voltage|matches('^[0-9]+$') %}",
+            "    {% set color = '#ff0000' %}",
+            "  {% elseif tags.voltage < 1000 %}",
             "    {% set color = colorInterpolate([ '#00ff00', 'blue' ], tags.voltage / 1000) %}",
             "  {% else %}",
-            "    {% set color = colorInterpolate([ 'blue', 'red' ], (tags.voltage - 1000) / 24000) %}",
+            "    {% set color = colorInterpolate([ 'blue', '#af0000' ], (tags.voltage - 1000) / 24000) %}",
             "  {% endif %}",
             "{% else %}",
-            "  {% set color='black' %}",
-            "{%endif %}",
+            "  {% set color = 'black' %}",
+            "{% endif %}",
             "",
             "{% if tags.service == 'yard' or tags.service == 'siding' or tags.service == 'spur' or tags.service == 'crossover' %}",
             "    {% set width=2 %}",
@@ -67,7 +71,7 @@
             "opacity": "1",
             "fill": null,
             "dashArray": [
-                "{% if not tags.electrified or tags.electrified == 'no' %}",
+                "{% if not tags.electrified is defined  %}",
                 "{% elseif tags.frequency == 0 %}",
                 "{% else %}",
                 "5,2",
@@ -97,7 +101,7 @@
         "{% endfor %}",
         "",
         "{% for i in range(3000, 25000, 2000) %}",
-        "  {% set color = colorInterpolate([ 'blue', 'red' ], (i - 1000) / 24000) %}",
+        "  {% set color = colorInterpolate([ 'blue', '#af0000' ], (i - 1000) / 24000) %}",
         "  <tr>",
         "    <td>{{ markerLine({ 'width': 3, 'color': color })|raw }}</td>",
         "    <td>{{ i }}V</td>",
@@ -113,6 +117,16 @@
         "    <td>{{ markerLine({ 'styles': [ 'casing', 'default' ], 'style:casing': { 'width': 3, 'color': 'white' }, 'style': { 'width': '3', 'dashArray': '5,2', 'lineCap': 'butt', 'color': color } })|raw }}</td>",
         "    <td>{{ trans('alternating current') }}</td>",
         "  </tr>",
+        "",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': '#7f7f7f' })|raw }}</td>",
+        "    <td>{{ trans('unknown') }}</td>",
+        "  </tr>",
+        "",
+        "  <tr>",
+        "    <td>{{ markerLine({ 'width': 3, 'color': '#ff0000' })|raw }}</td>",
+        "    <td>{{ trans('illegal value') }}</td>",
+        "  </tr>",
         "</table>"
     ]
 }