Querying Urban/Rural Classification for Scottish Data Zones¶
Overview¶
This guide explains how to query the urban/rural classification for Scottish data zones using the statistics.gov.scot SPARQL endpoint.
Important Context¶
There are two related datasets on statistics.gov.scot:
- Data Zone Lookup 2022 (
http://statistics.gov.scot/data/data-zone-lookup-2022) - This is a FileDataset containing CSV data only
- Not queryable via SPARQL - only available as a CSV download
-
Contains comprehensive geography lookup information including UR2, UR3, UR6, UR8 classifications
-
Urban Rural Classification (6-Fold) (
http://statistics.gov.scot/data/urban-rural-classification) - This is a LinkedDataset (RDF Data Cube)
- Fully queryable via SPARQL
- Contains the 6-fold urban/rural classification linked to data zones
- This is the dataset to use for SPARQL queries
Dataset Structure¶
The Urban Rural Classification dataset is structured as an RDF Data Cube with the following components:
- Dataset URI:
http://statistics.gov.scot/data/urban-rural-classification - Dimensions:
- Reference Area (
sdmx:refArea): The data zone (e.g.,http://statistics.gov.scot/id/statistical-geography/S01014811) - Reference Period (
sdmx:refPeriod): The year (e.g.,http://reference.data.gov.uk/id/year/2022) - Measure:
- Rank (
http://statistics.gov.scot/def/measure-properties/rank): Integer value 1-6 representing the classification - Attributes:
- Unit Measure (
sdmx:unitMeasure): Reference to the classification concept scheme
Classification Values¶
The 6-fold urban/rural classification uses the following numeric codes:
| Code | Classification | Description |
|---|---|---|
| 1 | Large Urban Areas | Settlements of over 125,000 people |
| 2 | Other Urban Areas | Settlements of 10,000 to 125,000 people |
| 3 | Accessible Small Towns | Settlements of 3,000-10,000 people, within 30 minutes drive of a settlement of 10,000+ |
| 4 | Remote Small Towns | Settlements of 3,000-10,000 people, with drive time over 30 minutes to a settlement of 10,000+ |
| 5 | Accessible Rural | Settlements of less than 3,000 people, within 30 minutes drive of a settlement of 10,000+ |
| 6 | Remote Rural | Settlements of less than 3,000 people, with drive time over 30 minutes to a settlement of 10,000+ |
SPARQL Queries¶
Basic Query: Get Classification for a Specific Data Zone¶
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
SELECT ?classification
WHERE {
?obs qb:dataSet <http://statistics.gov.scot/data/urban-rural-classification> .
?obs sdmx:refArea <http://statistics.gov.scot/id/statistical-geography/S01014811> .
?obs <http://statistics.gov.scot/def/measure-properties/rank> ?classification .
}
Example Result: 1 (Large Urban Areas)
Detailed Query: Get Classification with Year and Label¶
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
SELECT ?dataZone ?year ?classification ?classificationLabel
WHERE {
?obs qb:dataSet <http://statistics.gov.scot/data/urban-rural-classification> .
?obs sdmx:refArea ?dataZone .
?obs sdmx:refPeriod ?yearUri .
?obs <http://statistics.gov.scot/def/measure-properties/rank> ?classification .
?yearUri rdfs:label ?year .
FILTER(?dataZone = <http://statistics.gov.scot/id/statistical-geography/S01014811>)
OPTIONAL {
?obs sdmx:unitMeasure ?classUnit .
?classUnit rdfs:label ?classificationLabel .
}
}
Query Multiple Data Zones¶
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?dataZoneCode ?classification
WHERE {
?obs qb:dataSet <http://statistics.gov.scot/data/urban-rural-classification> .
?obs sdmx:refArea ?dataZone .
?obs <http://statistics.gov.scot/def/measure-properties/rank> ?classification .
# Extract just the code from the URI
BIND(STRAFTER(STR(?dataZone), "http://statistics.gov.scot/id/statistical-geography/") AS ?dataZoneCode)
# Filter for specific data zones
FILTER(?dataZoneCode IN ("S01014811", "S01013481"))
}
Data Zone URI Format¶
Data zones are referenced using URIs in the format:
http://statistics.gov.scot/id/statistical-geography/[DATA_ZONE_CODE]
For example:
- Data zone S01014811: http://statistics.gov.scot/id/statistical-geography/S01014811
SPARQL Endpoint¶
Endpoint URL: https://statistics.gov.scot/sparql
The endpoint can be accessed via: - Web interface: https://statistics.gov.scot/sparql - HTTP GET or POST requests - Supports SPARQL 1.1 query syntax
Key Prefixes¶
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
Alternative: CSV Download¶
If you need comprehensive lookup data including multiple classification types (UR2, UR3, UR6, UR8) and other geographic hierarchies, you can download the CSV file directly:
Download URL: Available from the Data Zone Lookup 2022 dataset page
- Dataset: http://statistics.gov.scot/data/data-zone-lookup-2022
- The CSV includes columns: DZ22, IZ22, MMWard, LA, SPC, UKPC, HB, HIA, SPD, SFRLSO, SFRSDA, RRP, LRP, UR2, UR3, UR6, UR8, Country
The CSV approach is more suitable for: - Bulk lookups of many data zones - Obtaining multiple classification types simultaneously - Offline processing
Additional Resources¶
- Urban Rural Classification: https://www.gov.scot/collections/agriculture-fisheries-and-rural-statistics/#urbanruralclassification
- statistics.gov.scot Help: http://statistics.gov.scot/help
- Data Zone Geography: https://www.gov.scot/collections/small-area-statistics/
Notes¶
- The classification is based on population (from National Records of Scotland) and accessibility (drive time analysis)
- Data zones are assigned based on their population-weighted centroid
- Some data zones may straddle urban/rural boundaries
- The classification is updated periodically to incorporate the most recent Population Estimates for Settlements and Localities
- The current classification is based on 2022 data