logo Netzschleuder network catalog, repository, and centrifuge

History of os_open_roads

The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.

[entries] Lay out the spatial networks with hfd_layout() instead of cfd_layout() by Tiago de Paula Peixoto cc3bcb0
Changed: none
diff --git a/entries/os_open_roads/__init__.py b/entries/os_open_roads/__init__.py
index 11e09bb..291a8c7 100644
--- a/entries/os_open_roads/__init__.py
+++ b/entries/os_open_roads/__init__.py
@@ -186,6 +186,6 @@ def parse(alts=None):
     yield None, g
 
 def get_pos(g, sbm_fit):
-    # Spatial network: laid out with the default parameters of cfd_layout(),
+    # Spatial network: laid out with the default parameters of hfd_layout(),
     # without the partition of the SBM fit
-    return cfd_layout(g)
+    return hfd_layout(g)
[entries] Add the date when each entry was added, and remove icon_hash by Tiago de Paula Peixoto beff7c9
The dates are those of the commits that first added the entries' files
(2020-08-11 for the entries of the initial commit); renamed entries keep
the date of their first name.

Changed: none
diff --git a/entries/os_open_roads/__init__.py b/entries/os_open_roads/__init__.py
index 1f52eb4..11e09bb 100644
--- a/entries/os_open_roads/__init__.py
+++ b/entries/os_open_roads/__init__.py
@@ -50,7 +50,7 @@ url = ['https://www.ordnancesurvey.co.uk/products/os-open-roads',
        'https://api.os.uk/downloads/v1/products/OpenRoads']
 citation = [('Ordnance Survey, "OS Open Roads." Dataset, release 2026-10 (2026)', 'https://www.ordnancesurvey.co.uk/products/os-open-roads')]
 upstream_license = ("Open Government Licence v3.0", "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/")
-icon_hash = None
+date_added = '2026-10-31'
 
 # The GeoPackage of the whole of Great Britain. It is replaced in place by
 # each release (in April and October); the one fetched here is the release
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) by Tiago de Paula Peixoto bc3dbbd
The lists of properties at the end of the descriptions marked edge
properties with "Edge" but left node properties unmarked, or grouped
them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property
was often unclear. Every item now starts with (Node), (Edge) or (Graph),
followed by the property names, a colon and the explanation, one item
per property or group of properties; qualifications (kinds of nodes,
networks) follow the names in parentheses. Properties that were only
named got a short explanation, and a few items that named the wrong
kind of property were corrected.
diff --git a/entries/os_open_roads/__init__.py b/entries/os_open_roads/__init__.py
index ba3d3b5..1f52eb4 100644
--- a/entries/os_open_roads/__init__.py
+++ b/entries/os_open_roads/__init__.py
@@ -28,8 +28,23 @@ Nodes are the road nodes and edges are the road links; the network is undirected
 
 The network has the following properties:
 
-- Nodes: `node_id`, the id of the road node; `form_of_road_node`, its kind (`junction`, `road end`, `pseudo node`, or `roundabout`); `easting` and `northing`, its position in the British National Grid (EPSG:27700, meters); `latitude` and `longitude`, converted to WGS84 (with the Helmert transformation, accurate to a few meters).
-- Edges: `link_id`, the id of the road link; `length`, its length (m); `road_classification`, the classification of the road (`Motorway`, `A Road`, `B Road`, `Classified Unnumbered`, `Unclassified`, `Not Classified` or `Unknown`); `road_classification_number`, the road number (e.g. `M1`, `A40`); `road_function`, its function (`Motorway`, `A Road`, `B Road`, `Minor Road`, `Local Road`, `Local Access Road`, `Restricted Local Access Road` or `Secondary Access Road`); `form_of_way`, its physical form (`Single Carriageway`, `Dual Carriageway`, `Collapsed Dual Carriageway`, `Slip Road`, `Roundabout`, `Shared Use Carriageway` or `Guided Busway`); `name_1` and `name_2`, the names of the road, with their languages `name_1_lang` and `name_2_lang` (given only for bilingual names: `name_1` in Welsh, `cym`, or Scottish Gaelic, `gla`, and `name_2` in English, `eng`); `road_structure`, `Road In Tunnel` for the 525 links in tunnels (empty otherwise); `fictitious`, whether the link is fictitious (false for all links in this release); `loop`, whether the link is a loop (the self-loops); `primary_route`, whether the road is part of the primary route network; `trunk_road`, whether it is a trunk road."""
+- (Node) `node_id`: the id of the road node.
+- (Node) `form_of_road_node`: its kind (`junction`, `road end`, `pseudo node`, or `roundabout`).
+- (Node) `easting` and `northing`: its position in the British National Grid (EPSG:27700, meters).
+- (Node) `latitude` and `longitude`: converted to WGS84 (with the Helmert transformation, accurate to a few meters).
+- (Edge) `link_id`: the id of the road link.
+- (Edge) `length`: its length (m).
+- (Edge) `road_classification`: the classification of the road (`Motorway`, `A Road`, `B Road`, `Classified Unnumbered`, `Unclassified`, `Not Classified` or `Unknown`).
+- (Edge) `road_classification_number`: the road number (e.g. `M1`, `A40`).
+- (Edge) `road_function`: its function (`Motorway`, `A Road`, `B Road`, `Minor Road`, `Local Road`, `Local Access Road`, `Restricted Local Access Road` or `Secondary Access Road`).
+- (Edge) `form_of_way`: its physical form (`Single Carriageway`, `Dual Carriageway`, `Collapsed Dual Carriageway`, `Slip Road`, `Roundabout`, `Shared Use Carriageway` or `Guided Busway`).
+- (Edge) `name_1`, `name_2`: the names of the road.
+- (Edge) `name_1_lang`, `name_2_lang`: the languages of `name_1` and `name_2` (given only for bilingual names: `name_1` in Welsh, `cym`, or Scottish Gaelic, `gla`, and `name_2` in English, `eng`).
+- (Edge) `road_structure`: `Road In Tunnel` for the 525 links in tunnels (empty otherwise).
+- (Edge) `fictitious`: whether the link is fictitious (false for all links in this release).
+- (Edge) `loop`: whether the link is a loop (the self-loops).
+- (Edge) `primary_route`: whether the road is part of the primary route network.
+- (Edge) `trunk_road`: whether it is a trunk road."""
 tags = ['Transportation', 'Roads', 'Spatial', 'Weighted', 'Multigraph', 'Metadata']
 url = ['https://www.ordnancesurvey.co.uk/products/os-open-roads',
        'https://api.os.uk/downloads/v1/products/OpenRoads']
[entries] New entry: os_open_roads by Tiago de Paula Peixoto f8a3faf
diff --git a/entries/os_open_roads/__init__.py b/entries/os_open_roads/__init__.py
new file mode 100644
index 0000000..ba3d3b5
--- /dev/null
+++ b/entries/os_open_roads/__init__.py
@@ -0,0 +1,176 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2026 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+import shutil
+import sqlite3
+import struct
+
+title = "Great Britain road network (OS Open Roads, 2026)"
+description = """The road network of Great Britain (England, Scotland and Wales) from OS Open Roads, the open, generalized road network of Ordnance Survey: all the roads, from motorways to country lanes, as a topological network of road links between road nodes (junctions, ends of roads, and points where an attribute of the road changes), in the release of October 2026 (the data are replaced in place by new releases twice a year).
+
+Nodes are the road nodes and edges are the road links; the network is undirected (the direction of traffic is not given). Dual carriageways are represented by a single link where they run close together ("collapsed" dual carriageways). The network has parallel edges (50,119, e.g. links forming a small loop between the same two junctions) and 25,131 self-loops (loops, links that start and end at the same node), and 1,079 components (the largest with 3,330,078 of the 3,364,565 nodes; the others are mostly islands). The geometries of the links, the references to the road names and numbers of OS (TOIDs), and the 668 motorway junctions (points with their numbers, not attached to the nodes) are not included.
+
+The network has the following properties:
+
+- Nodes: `node_id`, the id of the road node; `form_of_road_node`, its kind (`junction`, `road end`, `pseudo node`, or `roundabout`); `easting` and `northing`, its position in the British National Grid (EPSG:27700, meters); `latitude` and `longitude`, converted to WGS84 (with the Helmert transformation, accurate to a few meters).
+- Edges: `link_id`, the id of the road link; `length`, its length (m); `road_classification`, the classification of the road (`Motorway`, `A Road`, `B Road`, `Classified Unnumbered`, `Unclassified`, `Not Classified` or `Unknown`); `road_classification_number`, the road number (e.g. `M1`, `A40`); `road_function`, its function (`Motorway`, `A Road`, `B Road`, `Minor Road`, `Local Road`, `Local Access Road`, `Restricted Local Access Road` or `Secondary Access Road`); `form_of_way`, its physical form (`Single Carriageway`, `Dual Carriageway`, `Collapsed Dual Carriageway`, `Slip Road`, `Roundabout`, `Shared Use Carriageway` or `Guided Busway`); `name_1` and `name_2`, the names of the road, with their languages `name_1_lang` and `name_2_lang` (given only for bilingual names: `name_1` in Welsh, `cym`, or Scottish Gaelic, `gla`, and `name_2` in English, `eng`); `road_structure`, `Road In Tunnel` for the 525 links in tunnels (empty otherwise); `fictitious`, whether the link is fictitious (false for all links in this release); `loop`, whether the link is a loop (the self-loops); `primary_route`, whether the road is part of the primary route network; `trunk_road`, whether it is a trunk road."""
+tags = ['Transportation', 'Roads', 'Spatial', 'Weighted', 'Multigraph', 'Metadata']
+url = ['https://www.ordnancesurvey.co.uk/products/os-open-roads',
+       'https://api.os.uk/downloads/v1/products/OpenRoads']
+citation = [('Ordnance Survey, "OS Open Roads." Dataset, release 2026-10 (2026)', 'https://www.ordnancesurvey.co.uk/products/os-open-roads')]
+upstream_license = ("Open Government Licence v3.0", "https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/")
+icon_hash = None
+
+# The GeoPackage of the whole of Great Britain. It is replaced in place by
+# each release (in April and October); the one fetched here is the release
+# of October 2026.
+archived_urls = {"oproad_gpkg_gb.zip": "https://api.os.uk/downloads/v1/products/OpenRoads/downloads?area=GB&format=GeoPackage&redirect"}
+files = [(("oproad_gpkg_gb.zip",), None, None)]
+
+def fetch_upstream(force=False):
+    return fetch_archived_files(__name__.split(".")[-1], archived_urls, force,
+                                tries=3)
+
+def gpkg_point(blob):
+    "The (x, y) coordinates of a GeoPackage point geometry."
+    flags = blob[3]
+    env = (0, 32, 48, 48, 64)[(flags >> 1) & 7]
+    wkb = blob[8 + env:]
+    order = "<" if wkb[0] == 1 else ">"
+    return struct.unpack(order + "dd", wkb[5:21])
+
+def osgb36_to_wgs84(E, N):
+    """Latitude and longitude (WGS84) of British National Grid coordinates
+    (EPSG:27700): inverse transverse Mercator projection on the Airy 1830
+    ellipsoid, followed by the Helmert transformation from OSGB36 to WGS84
+    (accurate to a few meters)."""
+    E = numpy.asarray(E, dtype=float)
+    N = numpy.asarray(N, dtype=float)
+    a, b = 6377563.396, 6356256.909
+    F0, lat0, lon0 = 0.9996012717, numpy.radians(49), numpy.radians(-2)
+    N0, E0 = -100000, 400000
+    e2 = 1 - b ** 2 / a ** 2
+    n = (a - b) / (a + b)
+    lat = lat0
+    M = 0
+    for i in range(10):
+        lat = (N - N0 - M) / (a * F0) + lat
+        M = b * F0 * ((1 + n + 5 / 4 * n ** 2 + 5 / 4 * n ** 3) * (lat - lat0)
+                      - (3 * n + 3 * n ** 2 + 21 / 8 * n ** 3) * numpy.sin(lat - lat0) * numpy.cos(lat + lat0)
+                      + (15 / 8 * n ** 2 + 15 / 8 * n ** 3) * numpy.sin(2 * (lat - lat0)) * numpy.cos(2 * (lat + lat0))
+                      - 35 / 24 * n ** 3 * numpy.sin(3 * (lat - lat0)) * numpy.cos(3 * (lat + lat0)))
+    s, c, t = numpy.sin(lat), numpy.cos(lat), numpy.tan(lat)
+    nu = a * F0 / numpy.sqrt(1 - e2 * s ** 2)
+    rho = a * F0 * (1 - e2) / (1 - e2 * s ** 2) ** 1.5
+    eta2 = nu / rho - 1
+    VII = t / (2 * rho * nu)
+    VIII = t / (24 * rho * nu ** 3) * (5 + 3 * t ** 2 + eta2 - 9 * t ** 2 * eta2)
+    IX = t / (720 * rho * nu ** 5) * (61 + 90 * t ** 2 + 45 * t ** 4)
+    X = 1 / (c * nu)
+    XI = 1 / (c * 6 * nu ** 3) * (nu / rho + 2 * t ** 2)
+    XII = 1 / (c * 120 * nu ** 5) * (5 + 28 * t ** 2 + 24 * t ** 4)
+    XIIA = 1 / (c * 5040 * nu ** 7) * (61 + 662 * t ** 2 + 1320 * t ** 4 + 720 * t ** 6)
+    dE = E - E0
+    lat = lat - VII * dE ** 2 + VIII * dE ** 4 - IX * dE ** 6
+    lon = lon0 + X * dE - XI * dE ** 3 + XII * dE ** 5 - XIIA * dE ** 7
+    # to cartesian coordinates (OSGB36, height 0)
+    s, c = numpy.sin(lat), numpy.cos(lat)
+    nu = a / numpy.sqrt(1 - e2 * s ** 2)
+    x = nu * c * numpy.cos(lon)
+    y = nu * c * numpy.sin(lon)
+    z = (1 - e2) * nu * s
+    # Helmert transformation to WGS84
+    tx, ty, tz, sc = 446.448, -125.157, 542.060, -20.4894e-6
+    rx, ry, rz = numpy.radians(numpy.array([0.1502, 0.2470, 0.8421]) / 3600)
+    x2 = tx + (1 + sc) * x - rz * y + ry * z
+    y2 = ty + rz * x + (1 + sc) * y - rx * z
+    z2 = tz - ry * x + rx * y + (1 + sc) * z
+    # back to latitude and longitude on the WGS84 ellipsoid
+    a, b = 6378137.0, 6356752.3142
+    e2 = 1 - b ** 2 / a ** 2
+    p = numpy.sqrt(x2 ** 2 + y2 ** 2)
+    lat = numpy.arctan2(z2, p * (1 - e2))
+    for i in range(10):
+        nu = a / numpy.sqrt(1 - e2 * numpy.sin(lat) ** 2)
+        lat = numpy.arctan2(z2 + e2 * nu * numpy.sin(lat), p)
+    return numpy.degrees(lat), numpy.degrees(numpy.arctan2(y2, x2))
+
+LINK_FIELDS = ["road_classification", "road_function", "form_of_way",
+               "road_classification_number", "name_1", "name_1_lang",
+               "name_2", "name_2_lang", "road_structure"]
+BOOL_FIELDS = ["fictitious", "loop", "primary_route", "trunk_road"]
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+    name = __name__.split(".")[-1]
+    os.makedirs("cache/temp", exist_ok=True)
+    with tempfile.NamedTemporaryFile(dir="cache/temp", suffix=".gpkg") as tmp:
+        with open_upstream_file(name, "oproad_gpkg_gb.zip:Data/oproad_gb.gpkg",
+                                "rb") as f:
+            shutil.copyfileobj(f, tmp, 1 << 24)
+        tmp.flush()
+        con = sqlite3.connect(tmp.name)
+        idx = {}
+        xy = []
+        form = []
+        for nid, geom, fr in con.execute("SELECT id, geometry, form_of_road_node "
+                                         "FROM road_node ORDER BY fid"):
+            idx[nid] = len(idx)
+            xy.append(gpkg_point(geom))
+            form.append(fr or "")
+        edges = []
+        eprops = defaultdict(list)
+        cols = ["id", "start_node", "end_node", "length", "length_uom"] + \
+            LINK_FIELDS + BOOL_FIELDS
+        for r in con.execute(f"SELECT {', '.join(cols)} FROM road_link ORDER BY fid"):
+            r = dict(zip(cols, r))
+            edges.append((idx[r["start_node"]], idx[r["end_node"]]))
+            if r["length_uom"] != "m":
+                raise ValueError(f"unexpected length unit: {r['length_uom']}")
+            eprops["link_id"].append(r["id"])
+            eprops["length"].append(r["length"])
+            for k in LINK_FIELDS:
+                eprops[k].append(r[k] or "")
+            for k in BOOL_FIELDS:
+                eprops[k].append(bool(r[k]))
+        con.close()
+    g = Graph(directed=False)
+    g.add_vertex(len(idx))
+    g.add_edge_list(edges)
+    del edges
+    xy = numpy.array(xy)
+    g.vp.node_id = g.new_vp("string", vals=list(idx))
+    g.vp.form_of_road_node = g.new_vp("string", vals=form)
+    g.vp.easting = g.new_vp("double", vals=xy[:, 0])
+    g.vp.northing = g.new_vp("double", vals=xy[:, 1])
+    lat, lon = osgb36_to_wgs84(xy[:, 0], xy[:, 1])
+    g.vp.latitude = g.new_vp("double", vals=lat)
+    g.vp.longitude = g.new_vp("double", vals=lon)
+    for k, vals in eprops.items():
+        t = ("double" if k == "length" else "bool" if k in BOOL_FIELDS
+             else "string")
+        g.ep[k] = g.new_ep(t, vals=vals)
+    yield None, g
+
+def get_pos(g, sbm_fit):
+    # Spatial network: laid out with the default parameters of cfd_layout(),
+    # without the partition of the SBM fit
+    return cfd_layout(g)