Using SPARQL With Transport Data

The SPARQL endpoint for transport data is available at http://gov.tso.co.uk/transport/sparql.

Sample Queries

  • Select a stop on Scotland Road, Liverpool
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    SELECT ?stop WHERE {
    	?stop a naptan:StopPoint;
    	naptan:town "LIVERPOOL";
    	naptan:street "SCOTLAND ROAD" .
    }
    LIMIT 1
    Insert
  • Select stops in administrative area 104
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    SELECT DISTINCT * WHERE {
    	?stop naptan:administrativeArea <http://transport.data.gov.uk/id/administrative-area/104> ;
    	naptan:street ?street ;
    	naptan:naptanCode ?code	
    }
    ORDER BY ?street
    LIMIT 100
    Insert
  • Display the latitude and longitude of a hailandride bus stop on Boad Street
    PREFIX geo:  <http://www.w3.org/2003/01/geo/wgs84_pos#>
    PREFIX naptan:  <http://transport.data.gov.uk/def/naptan/>
    SELECT * WHERE { 
    	?stop naptan:indicator "Boad Street";
    	a naptan:HailAndRideBusStop ;
    	geo:lat ?lat;
    	geo:long ?long
    }
    LIMIT 1
    Insert
  • List of OnStreetStopPoints on Northfield Road
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    SELECT distinct * WHERE {
    	?stop a naptan:OnStreetStopPoint;
    		naptan:street "Northfield Road";
    		naptan:naptanCode ?code.
    }
    LIMIT 15
    Insert
  • List of OnStreetStopPoints in the administrative area of Norfolk
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>  
    SELECT distinct * WHERE {
     	?stop a naptan:OnStreetStopPoint;
     		naptan:naptanCode ?code;
     		naptan:administrativeArea ?administrativeArea .
     	?administrativeArea skos:prefLabel "Norfolk".
    }
    LIMIT 10
    Insert
  • List of all Active CustomBusStops on the Kingswood Road
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>  
    SELECT distinct ?stop ?naptanCode WHERE {
    	?stop a naptan:CustomBusStop;   
    		naptan:naptanCode ?naptanCode;
    		naptan:stopValidity ?stopValidity;
    		naptan:street "Kingswood Road".
        ?stopValidity naptan:stopStatus ?stopStatus.
        ?stopStatus skos:prefLabel "Active"@en.              
    }
    Insert
  • List of all FerryStopPoints in the nptgLocality of Liverpool
    PREFIX naptan: <http://transport.data.gov.uk/def/naptan/>
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>    				
    SELECT distinct * WHERE {
    	?stop a naptan:FerryStopPoint;   
    		naptan:nptgLocality ?nptgLocality.
    	?nptgLocality skos:prefLabel "Liverpool"@en.
    }
    
    Insert
  • Traffic count on a particular count point
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    select distinct ?vehicle_type ?val where {
    	?s	traffic:countPointNumber "966943"^^<http://transport.data.gov.uk/def/traffic/CountPointNumber>;
    		traffic:countPointCount ?countPointCount .
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    
    Insert
  • Traffic count for a particular road Category
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    select distinct ?vehicle_type ?val where {
    	?s	traffic:roadCategory ?roadCategory;
    		traffic:countPointCount ?countPointCount .
    	?roadCategory skos:prefLabel "Motorway"@en .
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert
  • Traffic count on a particular road
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    select distinct ?vehicle_type ?val where {
    	?s	traffic:roadName "The Street"@en;
    		traffic:countPointCount ?countPointCount .
    	?roadCategory skos:prefLabel "Motorway"@en .
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert
  • Traffic count on all roads in a district
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    select distinct ?vehicle_type ?val where {
    	?s	traffic:districtRegion ?districtRegion;
    		traffic:countPointCount ?countPointCount .
    	?districtRegion rdfs:label "East Midlands"@en .
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert
  • Traffic count on all roads in a localAuthority
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    prefix area: <http://statistics.data.gov.uk/def/administrative-geography/> 
    select distinct ?vehicle_type ?val where {
    	?s	area:localAuthority ?localAuthority;
    		traffic:countPointCount ?countPointCount .
    	?localAuthority rdfs:label "East Sussex County Council"@en .
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert
  • Traffic count based on spatialrelations(northing/easting)
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    select distinct ?vehicle_type ?val where {
    	?s	spatialrelations:northing "118410"^^<http://www.w3.org/2001/XMLSchema#integer> ;
    		spatialrelations:easting "577880"^^<http://www.w3.org/2001/XMLSchema#integer> ;
    		traffic:countPointCount ?countPointCount .	
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert
  • Traffic count based on Lat and Long
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX traffic: <http://transport.data.gov.uk/def/traffic/> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX spatialPos: <http://www.w3.org/2003/01/geo/wgs84_pos#>  
    select distinct ?vehicle_type ?val where {
    	?s	spatialPos:lat "50.937695" ;
    		spatialPos:long "0.530364" ;
    		traffic:countPointCount ?countPointCount .	
    	?countPointCount traffic:roadCount ?count .
    	?count traffic:observation ?vehicle_type .
    	?vehicle_type rdf:value ?val.        
    }
    ORDER BY ?vehicle_type
    LIMIT 13
    
    Insert