Skip to content

Configuration examples

Matt Walker edited this page Oct 10, 2018 · 30 revisions

OS MasterMap Topo

Styling

OS MasterMap Topo in PostgreSQL

Once you've loaded the data into PostgreSQL you may want to render it in something like QGIS, GeoServer or MapServer.

The Ordnance Survey/OSMM Topography Layer stylesheet repository contains style sheets for OS MasterMap Topography Layer for QGIS, GeoServer & ESRI.

As of OSMM Topo v9 Loader now pre-populates style_code and style_description columns during load with the values required by the OS styling avoiding the need to run the OS SQL scripts. This allows you to skip to Chapter 8: HOW TO USE THE STYLESHEETS of the Getting Started Guide.

Below is a screen shot of OSMM Topography Layer (schema version 9) in QGIS. screen shot of OSMM Topography layer in QGIS

MapServer

A sample MapServer mapfile for OS MasterMap is in the extras directory of the main Loader repository.

OS MasterMap National Load

Tim Martin at the Ordnance Survey provided details of using Loader to load national cover of OS MasterMap into PostgreSQL over on the OSGeo UK mailing list: http://lists.osgeo.org/pipermail/uk/2011-August/000422.html

Output OS MasterMap Topo to ESRI Shapefile with QGIS attributes

To output data in Shapefile format you will want to specify ESRI Shapefile in the OGR command and if loading OS MasterMap there is an alternative prep_cmd to prepare the data and an accompanying gfs file to specify attributes and their names:

# Specify ESRI Shapefile as the format that ogr2ogr should output to and
# use the $output_dir token to specify the folder that the Shapefiles will be written to
ogr_cmd=ogr2ogr -append -skipfailures -f 'ESRI Shapefile' $output_dir $file_path

# Use the Use the Sharefile / QGIS specific preparation routine
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_osmm_topo_qgis

# Use the Sharefile / QGIS specific gfs file which specifies short column names,
# list attributes such as Descriptive Term as a comma separated list and some QGIS
# specific attributes for displaying labels
gfs_file=../gfs/osmm_topo_shape_qgis.gfs

Ordnance Survey OSMM Highways Network to PostgreSQL/PostGIS

WIP support for loading OSMM Highways Network. The basic feature types (tables) are loaded including lookup tables.

ogr2ogr --config GML_EXPOSE_FID YES --config PG_LIST_ALL_TABLES YES --config GML_GFS_TEMPLATE $gfs_file -append -skipfailures -f PostgreSQL PG:'dbname=postgis active_schema=public host=localhost user=postgres password=postgres' $file_path

# OS Highways specific preparation
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_osmm_highways

# Use the specific Highways gfs file tailored to loading into PostgreSQL
gfs_file=../gfs/osmm_highways_postgres_mega.gfs

Config notes

  • ogr_cmd
    • --config GML_EXPOSE_FID YES
      • The gml:id attribute is rewritten as fid by the preparation command, this ensures that a fid column is created and populated with it's value
    • --config PG_LIST_ALL_TABLES YES
      • Ensures all tables are loaded including those without geometry
    • --config GML_GFS_TEMPLATE $gfs_file
      • Specify the .gfs file directly (required when there is no prep_cmd).
      • Note: 016624f or later is currently required to use the --config GML_GFS_TEMPLATE $gfs_file option within the ogr_cmd.
  • gfs_file
    • The .gfs file is based on the released Highways data, as structure of sample data differs from the released data the .gfs file may need editing to be compatible with the sample data (remove insert| from the ElementPath value)

VectorMap District to PostgreSQL/PostGIS

To load VectorMap District you need to specify a suitable prep_cmd to prepare the GML for loading and a corresponding gfs file:

# Use the basic GML preparation routine
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_vmd

# Use the specific VML gfs file tailored to loading into PostgreSQL
gfs_file=../gfs/vmd_postgres.gfs

VectorMap Local to PostgreSQL/PostGIS

Currently there is basic support for loading OS VectorMap Local with no value add. To load VectorMap Local you need to specify a suitable prep_cmd to prepare the GML for loading and a suitable gfs file:

# Use the basic GML preparation routine
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_vml

# Use the specific VML gfs file tailored to loading into PostgreSQL
gfs_file=../gfs/vml_postgres.gfs

The loaded data is compatible with the Ordnance Survey VML QGIS styles.

OS VML styled with QGIS styles

Ordnance Survey ITN to PostgreSQL/PostGIS

Currently there is basic support for loading OS ITN. The basic feature types (tables) are loaded including lookup tables such as Road and RoadNodeInformation.

# In order to successfully load the lookup tables which do not have
# geometry the config option PG_LIST_ALL_TABLES must be set
ogr_cmd=ogr2ogr --config PG_LIST_ALL_TABLES YES --config GML_EXPOSE_FID NO -append -skipfailures -f PostgreSQL PG:'dbname=postgis active_schema=public host=localhost user=postgres password=postgres' $file_path

# Use the ITN specific GML preparation routine
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_osmm_itn

# Use the specific ITN gfs file tailored to loading into PostgreSQL
gfs_file=../gfs/osmm_itn_postgres.gfs

AddressBase Premium to PostgreSQL/PostGIS

In order to load Ordnance Survey AddressBase Premium data you must use the appropriate prep command to prepare the data for loading and associated gfs file:

# Use the OS AddressBase Premium preparation logic
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_addressbase_premium

# OS AddressBase Premium gfs file to specify appropriate schema for the data
gfs_file=../gfs/addressbase_premium.gfs

The preparation involves:

  • Splitting out the various features that relate to the main BasicLandPropertyUnit and Street tables into standalone tables with either UPRN or USRN columns to allow them to be joined, only the BasicLandPropertyUnit and Street tables have geometry
  • Converting Street geometry to MultiPoint where the first point is the start point for the Street and the second is the end point

OS MasterMap Sites Layer to PostgreSQL/PostGIS

To load OS MasterMap Sites Layer you need to use the supplied gfs file to define the tables and their columns together with the generic prep_osgml.prep_osgml preperation class, the relevent configuration is as follows:

# Use the generic OS GML preparation logic
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_osgml

# Use the sites gfs to define the table structure
gfs_file=../gfs/osmm_sites_postgres.gfs

OS MasterMap Networks Water Layer

OS MasterMap Networks – Water Layer is a digital representation of the watercourses in Great Britain as a series of links and nodes that create a network.

# Use specific prep_osmm_water logic in prep_osgml.py
prep_cmd=python prepgml4ogr.py $file_path prep_osgml.prep_osmm_water

# Use the water layerwater layer  gfs with the required attributes and geometry types
gfs_file=../gfs/osmm_water_postgres.gfs

Notes:

  • Supports 3D geometry for WatercourseLink features when loaded into a format that supports 3D such as PostGIS
  • Includes start / end node attributes on WatercourseLink features to allow links and nodes to be related
  • Certain attributes make use of GML code lists requiring a value be looked up in an external code list via a URL. Loader currently does not support fetching the remote code lists but instead attempts to derive a suitable value from the fragment of the URL

OS Open Map - Local

The most detailed street-level open data vector mapping product available, OS Open Map – Local is a great backdrop over which to display and analyse your data. - https://www.ordnancesurvey.co.uk/business-and-government/products/os-open-map-local.html

A relatively simple dataset that requires no preparation logic before loading with ogr2ogr. The attributes found in gfs/osopenmap.gfs match those found in the sample Shapefiles so that the OS supplied QGIS styles are able to be used unchanged. Sample config:

# Leave the prep_cmd unset
prep_cmd=

# Specify the OS Open Map - Local gfs with the required attributes and geometry types
gfs_file=../gfs/osopenmap.gfs

Police Neighbourhood Crime Boundaries to PostgreSQL/PostGIS

You can download the latest zip file of Police Neighbourhood Crime Boundaries from http://data.police.uk/data/kmls/. To load it, extract the zip file contents and set up a suitable config file for your output data or database. The following command will generate attribute data for the neighbourhood name (=name) and forcename (=description):

# Load all KML files into a single table called neighbourhood in British National Grid
ogr_cmd=ogr2ogr -append -skipfailures -f PostgreSQL PG:'dbname=policeuk host=localhost user=postgres password=postgres' -nln neighbourhood -t_srs EPSG:27700 -s_srs EPSG:4326 $file_path

# Use the basic GML preparation routine
prep_cmd=python prepgml4ogr.py $file_path prep_policekml.prep_kml

Output to MapInfo TAB

To output data in MapInfo TAB format you simply need to specify MapInfo File as the format in the OGR command:

# Specify MapInfo File as the output format
# and use the $output_dir token to specify the folder that the Shapefiles will be written to
ogr_cmd=ogr2ogr -append -skipfailures -f "MapInfo File" $output_dir/$base_file_name $file_path

Note: OGR does not support updating / appending to MapInfo TAB files so you may want to use the $base_file_name to specify a folder in which to write the output for each source file as shown above. The individual tables can then be stitched together for display using a seamless table.

Paths on Windows

When specifying paths for the src_dir, tmp_dir etc. on Windows it should be fine to simply use a single backslash to separate the parts of the path such as: C:\Temp. However when specifying paths for the ogr_cmd or prep_cmd you should escape the backslashes to ensure that the correct path is used, so instead of C:\Temp use C:\\Temp (use two backslashes).