Skip to content

Instantly share code, notes, and snippets.

@anisotropi4
Last active July 4, 2020 15:11
Show Gist options
  • Save anisotropi4/8d3bc849f7468c1cfc8e917be2ad3494 to your computer and use it in GitHub Desktop.
Save anisotropi4/8d3bc849f7468c1cfc8e917be2ad3494 to your computer and use it in GitHub Desktop.
Network Model (ELR) offsets
Released license:MIT
height:780
border:no
Network Model Engineering Line of Route (ELR) offsets
Script are released under the MIT license
Contains FOI reference data:
The data is protected under copyright as set out here https://www.whatdotheyknow.com/request/643748/response/1539326/attach/2/FOI202000232%20Response.pdf.

Network Model (ELR) offsets

Under the UK Freedom of Information Act (FOIA) 2000 request FOI2020/00232 Network Rail have published Network Model Engineering Line of Route (ELR) offsets as WG84 longitude and latitude links.

These scripts extracts these links convert these to link and point GeoJSON layers. The script also creates ESRI Shape files.

Creating the datafiles and associate GeoJSON format report

Once the dependencies to create the report are met run the script:

$ ./prepublish

This will download the report and create ESRI Shape files in the shp, as well as a Leaflet JavaScript visualisation using the network model data in GeoJSON format.

Dependencies

These are environment and project dependencies.

python dependencies

For ease of use manage package python packages dependencies with a local virtual environment venv:

$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt

If missing install the python virtualenv package

$ sudo apt install virtualenv

Data License

FOI reference data:

The data is protected under copyright as set out here.

This indicates that the data may be used for activities such as private study and non-commerial research and any other purpose authorised by exception in current law. Any other re-use such as commerical publication would require permission of the copyright holder.

<!DOCTYPE html>
<html>
<head>
<title>Network Model Engineering Line of Route (ELR) offsets</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-control" content="No-Cache">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico"/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src="http://d3js.org/d3.v5.min.js"></script>
<div id="map" style="width: 1340px; height: 780px"></div>
</head>
<body>
<div id='map'></div>
<script type="text/javascript">
var radius = 3;
var weight = 1;
var linewidth = 2;
var log2 = Math.log(2.0);
var minZoom = 3;
var maxZoom = 18;
var map = L.map('map').setView([54.533, -2.53], 6);
L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: maxZoom,
minZoom: minZoom,
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'osm.standard'
}).addTo(map);
var files = ["network-node.json", "network-link.json"];
files.forEach(render);
function render(file, index) {
d3.json(file).then(function(d) {
function onEachFeature(feature, layer) {
var this_feature = feature.properties;
var popupContent;
if (this_feature.ELR)
popupContent = this_feature.ELR;
var lookup = {
"Track_ID": "ID",
"TRACK_STATUS": "Status",
"Mileage_From": "From",
"Mileage_To": "To",
"Mileage": "Mileage",
}
var k = Object.keys(this_feature).filter(i=>(i in lookup))
for (var i = 0; i < k.length; i++) {
if (k[i] in this_feature)
popupContent += '<br>' + lookup[k[i]] + ': ' + this_feature[k[i]];
}
layer.bindPopup(popupContent);
};
L.geoJSON(d, {
style: function(feature) {
switch (feature.geometry.type) {
case 'Point':
return {
color: 'Green',
radius: radius,
weight: weight
};
case 'LineString':
return {
color: 'Blue',
weight: linewidth
};
case 'MultiLineString':
return {
color: c,
weight: linewidth
};
case 'MultiPolygon':
return {
weight: linewidth,
opacity: 1.0,
color: "Green",
fillColor: "Green",
fillOpacity: 0.2
};
case 'GeometryCollection':
return {
radius: radius,
weight: linewidth,
opacity: 1.0,
color: "Green",
fillColor: "GreenYellow",
fillOpacity: 0.2
};
default:
return {
weight: weight
};
}
},
onEachFeature: onEachFeature,
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
opacity: 1,
fillOpacity: 0.8
});
}
}).addTo(map);
});
}
</script>
</body>
</html>
MIT License
Copyright (c) 2020 Will Deakin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment