pythonnetworkxosmnxgml-geographic-markup-lan

How to create a NetworkX graph from a Geographic Markup Language file?


I wish to create a road network graph in NetworkX/OSMnx from the Ordinance Surveys' (OS') Open Roads dataset which I have downloaded as a Geographic Markup Language (GML) file. After an embarrassingly long time, and thanks to this answer, I realised that this GML file format is not the same as the Graph Modelling Language that NetworkX/OSMnx accept and have a built-in function for.

These file formats are completely new to me and so I wanted to ask if there is any way to load the OS' Open Road data, that is in GML format, into NetworkX/OSMnx so I can perform some network analysis on it? Ideally, this would be using Python.

Alternatively, I have managed to use OSMnx directly to create a road network from Open Street Maps data, but I wanted to see if the OS Open Road data was a bit more complete.


Solution

  • OSMnx is designed to work with OpenStreetMap data. If you can massage your input data into an OSM-like format, it may be possible to load them with the graph_from_gdfs function. You will need one layer of nodes and one layer of edges. Then the steps would look something like:

    1. Use ogr2ogr to convert your GML node and edge files to GeoPackage layers
    2. Load your node and edge GeoPackage layers with GeoPandas as GeoDataFrames
    3. Ensure these GeoDataFrames have the required index and columns
    4. Use OSMnx's graph_from_gdfs function to convert the GeoDataFrames to a NetworkX MultiDiGraph