Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

2. Conversion of Ordnance Survey ITN

jktulu edited this page Sep 6, 2018 · 1 revision

Introduction

As part of OpenTripPlanner, it is necessary that data on the road network is provided in one of several specific formats. The most easily consumed is the OpenSteetMap .osm format. While .osm data can easily be sourced, for example from geofabrik.de/, the goal here is to use Ordnance Survey ITN network data. While the OpenStreetMap data are convenient, less is known as to the provenance and completeness of the data. Further, it was possible to source Annual Snapshots of the Ordnance Survey ITN data which could be tied in with the time periods for which the timetables are valid. If you choose to use OpenStreetMap data, the following steps are not necessary. The instructions will make use of QGIS2 (QGIS3 not supported), PostgreSQL + PostGIS and Python.

Import Ordnance Survey ITN data into PostgreSQL

Prior to beginning, a PostgreSQL database needs to be available with the postgis extension installed. The PostGIS extension provides spatial functionality to the standard database. Details for setting up PostgreSQL and PostGIS can be found here. Note, the postgres.app programe for mac does not support PostGIS.

The first step in importing the Ordnance Survey ITN data is to install the OS Translator 2 plugin for QGIS. The tool facilitates loading the ITN data directly into the PostgreSQL database.

Once installed, it is necessary that several files within the plugins be updated such that the correct variables are imported.

First, the following file should be edited to include the following code block. C:\Users\Jens\.qgis2\python\plugins\OSTranslatorII\utils.py

def build_args
  	...
          else:
              args.insert(0, '-append')
  	    # add! :
              args.extend(['--config', 'PG_LIST_ALL_TABLES', 'YES'])

Second, based on [https://www.github.com/wrass/ITN-QGIS-pgRouting], it is suggested that the configuration file for the ITN converter file be updated. The file can be found at %userprofile%.qgis2\python\plugins\OSTranslatorII\gfs\OS Mastermap ITN (v7).gfs in Windows. You should insert the following code at line 603.

<PropertyDefn>
    <Name>environmentqualifier_classification</Name>
    <ElementPath>environmentQualifier|classification</ElementPath>
    <Type>StringList</Type>
  </PropertyDefn>
  <PropertyDefn>
    <Name>environmentqualifier_instruction</Name>
    <ElementPath>environmentQualifier|instruction</ElementPath>
    <Type>StringList</Type>
  </PropertyDefn>

Once the above edits to the plugin are complete, the following steps should be taken.

  1. Create a connection to the postgresql database in QGIS.
  2. Restart QGIS. Otherwise the conenction will not appear in the OS Translator tool.
  3. Set the parameters as follows
    1. Label doesn't matter
    2. Dataset = 'OS Mastermap ITN (v7)'
    3. Connection set to your postgresql database
    4. Schema should be set. here we use the format itn_<year>
    5. select create spatial index, remove duplicates and import boundary.
    6. Set the input directory as the file containing the appropriate ITN gml data.
  4. The tool will run and if successful, a new schema will have been created in the database with the appropriates data files.

Convert the PostgreSQL ITN data to a 'routing table'

From the same directory, you can open and run the create_ihm_network_dataset.sql file. Prior to running this, you should update the file dates (The default is 2016). The file reads in the itn_year schema and outputs to the itn__out schema.

Convert the ITN routing data to an osm file.

Once complete, the final stage is to convert the PostgreSQL routing table to an OpenStreetMap style .osm file. The script ihm_python_ogr2ogr_script.python can be used to convert the database data to an .osm file. You will need to update the working directory, the directory where the scripts are installed and the output directory. Also ensure that the table names and schemas are correct.

Finally, this file can be run using the Mac Terminal or alternatively Annaconda Prompt on Windows. You should first set the working direction in the terminal/prompt to the directory where the python script is downloaded.

Clone this wiki locally