LogoLogo
OS Docs HomeOS NGDOS APIsOS Download ProductsMore than MapsContact Us
  • More than Maps
  • Geographic Data Visualisation
    • Guide to cartography
      • Introduction to cartography
      • Types of maps
      • Symbology
      • Colour
      • Text on maps
      • Generalisation
      • Coordinate reference systems
      • Projections
      • Scale
      • Map legends
      • Map layout
      • Relief representation
      • North arrows
    • Guide to data visualisation
      • Introduction to data visualisation
      • GeoDataViz design principles
      • Types of visualisation
      • Thematic mapping techniques
      • Data visualisation critique
      • Accessible data visualisation
      • Ethical data visualisation
      • Software
      • Data
    • GeoDataViz assets
      • GeoDataViz basemaps
      • Stylesheets
      • GeoDataViz virtual gallery
      • Equal area cartograms
      • How did I make that?
        • Apollo 11 Landing
        • North York Moors National Park, 70 years
        • Snowdonia National Park, 70 years
        • Great Britain's National Parks
        • Great Britain's Islands
        • Great Britain's AONB's and National Scenic Areas
        • Famous shipwrecks of Pembrokeshire
        • Trig pillars today
        • Britain's most complex motorway junctions
      • #30DayMapChallenge
  • Data in Action
    • Examples
  • Demonstrators
    • 🆕Product Viewer
    • Addressing & location demonstrators
      • Address Portfolio overview
      • Which address product should you use?
      • AddressBase
      • AddressBase Core
      • AddressBase Plus
      • AddressBase Premium
      • Address Classifications
      • Addressing Lifecycle
      • OS Emergency Services Gazetteer
      • What are Vertical Streets?
      • Why are there differences in boundaries?
    • Contextual demonstrators
    • Customer best practice
      • Channel Shift
      • Data Management and OS Data Hub
      • End User Licence vs Contractor Licence
      • 🆕 IDs vs Spatial Relationships
      • Why we should capture good quality addresses at source
      • Why we Snap and Trace
    • Network Demonstrators
      • OS Detailed Path Network
      • OS Multi Modal Routing Network
        • OS Multi Modal Routing Network
      • Water Networks overview
      • OS MasterMap Highways Network and OS NGD Speeds
      • OS MasterMap® Highways Network and OS Open Roads™
    • OS MasterMap Generation APIs
      • Using the OS Features API
      • Using the OS Features API Archive
      • Using the OS Downloads API
      • Using OS APIs in ESRI Software
    • 🆕OS NGD (National Geographic Database)
      • OS NGD Address
      • OS NGD Boundaries
      • 🆕OS NGD Buildings
        • 🆕Building and Building Access Feature Types
        • Building Part and Building Line Feature Types
      • 🆕OS NGD Geographical Names
      • OS NGD Land
      • OS NGD Land Cover enhancements
      • 🆕OS NGD Land Use
      • OS NGD Land Use enhancements
      • 🆕OS NGD Structures
        • 🆕OS NGD Structures
        • Field Boundaries
      • 🆕OS NGD Transport Features
      • 🆕OS NGD Transport Network
      • OS NGD Transport RAMI
      • OS NGD Water Features
      • OS NGD Water Network
      • OS NGD API - Features
      • Ordering OS NGD data
      • Change only updates
      • OS NGD Versioning
      • Creating a topographic map from OS NGD Data
      • Analytical styling for OS NGD data
    • OS MasterMap® demonstrators
    • 🆕Product & API Comparisons
      • 🆕Comparison of Water Network Products
  • Tutorials
    • GeoDataViz
      • Thematic Mapping Techniques
      • Downloading and using data from the OS Data Hub
      • How to download and use OS stylesheets
      • How to use the OS Maps API
      • Creating a bespoke style in Maputnik
    • GIS
      • Analysing pavement widths
      • Basic routing with OS Open Data and QGIS
      • Walktime analysis using OS Multi-modal Routing Network and QGIS
      • Creating 3D Symbols for GIS Applications
      • Constructing a Single Line Address using a Geographic Address
      • Creating a Digital Terrain Model (DTM)
      • Visualising a road gradient using a Digital Terrain Model
      • Visualising a road gradient using OSMM Highways
    • 🆕APIs
      • 🆕Using OS APIs with EPC API
      • 🆕OS APIs and ArcGIS
  • Deep Dive
    • Introduction to address matching
    • Guide to routing for the Public Sector
      • Part 1: Guide to routing
      • Part 2: Routing software and data options
      • Part 3: Building a routable network
    • Unlocking the Power of Geospatial Data
    • Using Blender for Geospatial Projects
    • A Guide to Coordinate Systems in Great Britain
      • Myths about coordinate systems
      • The shape of the Earth
      • What is position?
        • Types of coordinates
        • We need a datum
        • Position summary
      • Modern GNSS coordinate systems
        • Realising WGS84 with a TRF
        • The WGS84 broadcast TRF
        • The International Terrestrial Reference Frame (ITRF)
        • The International GNSS Service (IGS)
        • European Terrestrial Reference System 1989 (ETRS89)
      • Ordnance Survey coordinate systems
        • ETRS89 realised through OS Net
        • National Grid and the OSGB36 TRF
        • Ordnance Datum Newlyn
        • The future of British mapping coordinate systems
        • The future of British mapping coordinate systems
      • From one coordinate system to another: geodetic transformations
        • What is a geodetic transformation?
        • Helmert datum transformations
        • National Grid Transformation OSTN15 (ETRS89–OSGB36)
        • National Geoid Model OSGM15 (ETRS89-Orthometric height)
        • ETRS89 to and from ITRS
        • Approximate WGS84 to OSGB36/ODN transformation
        • Transformation between OS Net v2001 and v2009 realisations
      • Transverse Mercator map projections
        • The National Grid reference convention
      • Datum, ellipsoid and projection information
      • Converting between 3D Cartesian and ellipsoidal latitude, longitude and height coordinates
      • Converting between grid eastings and northings and ellipsoidal latitude and longitude
      • Helmert transformation worked example
      • Further information
  • Code
    • Ordnance Survey APIs
    • Mapping
    • Routing with pgRouting
      • Getting started with OS MasterMap Highways and pgRouting
      • Getting started with OS MasterMap Highways Network - Paths and pgRouting
      • Getting started with OS NGD Transport Theme and pgRouting
      • Getting started with OS NGD Transport Path features and pgRouting
  • RESOURCES
    • 🆕Data Visualisation External Resources
Powered by GitBook

Website

  • Ordnance Survey

Data

  • OS Data Hub
On this page
  • What is an ID and what IDs are in OS Data?
  • What do OS Identifiers look like?
  • Using IDs to join data​
  • IDs in Ordnance Survey Data
  • Spatial Querying to join data
  • Spatial Query Examples
  • SQL query using a spatial join
  • Indexing​
  • When To Use IDs vs When To Use Spatial Relationships​
  • IDs
  • Spatial Relationships

Was this helpful?

  1. Demonstrators
  2. Customer best practice

🆕 IDs vs Spatial Relationships

PreviousEnd User Licence vs Contractor LicenceNextWhy we should capture good quality addresses at source

Last updated 7 months ago

Was this helpful?

What is an ID and what IDs are in OS Data?

An ID uniquely identifies each row of data or geographical feature.

  • OSID (Ordnance Survey Identifier) – The OS NGD primarily uses a new identifier called the OSID to uniquely identify features. The OSID will be used persistently and will allow the unique identification of records in the OS NGD. It should be noted that the OSID will not be unique across the OS NGD, but rather only unique at a feature type level. The reason for this is, when possible, the same OSID will be used on multiple features when they represent the same geographical feature.

  • UPRN (Unique Property Reference Number) – Is a unique numeric identifier for every spatial address in Great Britain. It applies a ‘common standard’ for addressable buildings and objects. One that is machine-readable, and in a consistent reference format.

  • USRN (Unique Street Reference Number) - is a unique and persistent identifier for every street, road, track, path, cycle track or cycle way in Great Britain.​

  • TOID (Topographic Identifier) - Is a unique and persistent identifier for each and every feature found in OS MasterMap products. A TOID shows unique identifiers for a wide range of landscape and built environment features, with a generalised location, extracted from OS MasterMap products.​

What do OS Identifiers look like?

  • OSID – 9d697b8b-b351-4e9a-9c7b-d7d0d155f513​

  • UPRN – 906483712​

  • USRN – 7905946​

  • TOID – osgb4000000073338613

Using IDs to join data​

Pros:
  • IDs are unique across datasets, allowing multiple datasets with common ID fields to be joined with minimal difficulties. ​

  • Avoid data duplication as IDs are unique. Maintaining data integrity.​

  • UUIDs (Universally Unique ID)/GUIDs (Globally Unique ID) can be generated offline.​

    ​

Cons:
  • ID data types often vary between datasets. Therefore, the common IDs must be the same data types before joining. ​

  • Less flexibility – Both tables must contain the same IDs.​

  • UUIDs/GUIDs take up more database storage.​

IDs in Ordnance Survey Data

Ordnance Survey produces various datasets of unique identifiers for a wide range of landscapes and built environment features for projects that require greater data connectivity, all available for free via the Ordnance Survey website.​

  • OS Open Linked Identifiers – a dataset containing the authoritative relationships between Unique Property Reference Numbers (UPRNs), Unique Street Reference Numbers (USRNs) and Topographic Object Identifiers (TOIDs).​

  • OS Linked Identifiers API – gives direct access to identifiers for a large number of feature types such as address records, building outlines, road surface area, road names, road sections and street records as well as the relationships between them that we provide links for, without having to download, store, or manage large, complex datasets.​

  • OS Open TOID – shows unique identifiers for a wide range of landscape and built environment features, with a generalised location, extracted from OS MasterMap products.​

  • OS Open USRN - enables users to share and link data related to UPRNs, which can be spatially analysed and visualised using their accurate location.​

  • OS Open UPRN – an open dataset containing all USRNs from OS MasterMap Highways Network with a simplified line geometry.​

Spatial Querying to join data

Spatial relationships indicate how two geometries interact with one another. They are a fundamental capability for querying geometry.

Pros:
  • Increased flexibility when joining data.​

  • Allows for spatial analysis and enhancing this data by combining with other attributes.​

  • Gives the opportunity to visualise data differently with Mapping, which can make it easier to communicate patterns/findings.​

Cons:
  • Complex spatial operations, queries involving multiple spatial objects or extensive calculations can lead performance degradation and require significant processing power and time. Therefore, to optimise complex query performance advanced query optimisation and indexing techniques may be required, along with hardware enhancements.​

  • Inaccurate and inconsistent spatial data can lead to poor results and unreliable analysis.​

  • Domain knowledge is required.​

Spatial Query Examples

To make it easy to determine common spatial relationships, the OGC defines a set of named spatial relationship predicates. Examples of these in PostGIS are as follows:

Relationship
Result

ST_CONTAINS

Returns TRUE if geometry A contains geometry B

ST_WITHIN

Returns TRUE if geometry A is within geometry B.​

ST_DWITHIN

Returns TRUE if the geometries are within a given distance.​

ST_OVERLAPS​

Returns TRUE if geometry A and B "spatially overlap".​

ST_CROSSES

Compares two geometry objects and returns TRUE if their intersection "spatially crosses"; that is, the geometries have some, but not all interior points in common.​

ST_TOUCHES

Returns TRUE if A and B intersect, but their interiors do not intersect. ​

ST_INTERECTS

Returns TRUE if two geometries intersect. Geometries intersect if they have any point in common.​ This would return a set of the results that is the same as all of the relationships listed above combined

ST_DISJOINT

Returns TRUE if two geometries intersect. Geometries intersect if they have any point in common.​

ST_EQUALS

Returns TRUE if the given geometries are "topologically equal“, i.e., the geometries have the same dimension, and their point-sets occupy the same space.​

SQL query using a spatial join

Return all train stations within 10km of my location.​

SELECT a.*
FROM railway_stations AS a
LEFT JOIN my_location AS b
ON ST_DWithin(a.geom, b.geom, 10000)

Indexing​

Indexing columns that you are querying or trying to join on has huge benefits. Below are a few examples, however it will be beneficial to take a look for yourself to understand fully the benefits of indexing.​

  • Indexes allow database engines to locate specific rows based on the indexed column faster without needing to scan the entire table.​

  • Indexes make data easier to navigate and retrieve information by transforming the data into an organised structure.​

  • They can help to ensure data consistency. Unique indexes ensure no two rows in the table have the same key values, helping to prevent duplicate rows.​

When To Use IDs vs When To Use Spatial Relationships​

IDs

Spatial Relationships


Disclaimer:

Spatial querying can be accomplished in multiple Programs/Software using various programming languages. ​

For the purposes of this Lightning Talk, when referring to spatial querying, we will be using PostGIS in PostgreSQL. ​

Spatial querying can also be accomplished using any software/programs that have spatial functionality.​

This content has been developed from what was originally a Lightning Talk PowerPoint slide set. These slides are available to PSGA members to view and download from the

Advantages

  • Simple and fast.​

  • Works with non-spatial data.​

  • Easy to understand and implement.​

Disadvantages

  • Requires datasets to have at least one common field.​

  • Doesn’t consider spatial data, therefore limits analysis capabilities.​

When?

You have a common field and need a quick and straightforward join.

Advantages​

  • Utilises spatial relationships between features.​

  • Data can be analysed and visualised based on spatial criteria.

Disadvantages

  • Increased complexity and computational intensity. ​

  • Requires spatial data and GIS tools.

When?

Spatial data is crucial to your analysis or could help to give greater insight in your analysis. This could be for geographic studies or working with spatial data layers. ​

PSGA members area of the OS website
An example of different IDs for the same feature
result of the spatial query above, with the selected stations in green, unselected in red
Page cover image