Using SPARQL With Geographic Data

The SPARQL endpoint for geo data is available at http://os.services.tso.co.uk/geo/sparql.

Sample Queries

  • This query returns a list and names of Westminster Constituencies, and their containing county electoral divisions.
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
    PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
    
    	SELECT ?constituency ?constituencyname ?cdivision ?name 
    	WHERE
    	{
    	?constituency rdf:type admingeo:WestminsterConstituency . 
    	?constituency foaf:name ?constituencyname .
    	?cdivision rdf:type admingeo:CountyElectoralDivision .
    	?cdivision foaf:name ?name .
    	?constituency spatialrelations:contains ?cdivision .
    	} LIMIT 10
    
    
    Insert
  • To find out the name, area code, area and types of regions that borders The City of Westmister.
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
    PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
    
    	SELECT ?regions ?name ?code ?type ?area WHERE
    	{
    	<http://data.ordnancesurvey.co.uk/id/7000000000011164> spatialrelations:borders ?regions .
    	?regions rdf:type ?type .
    	?regions foaf:name ?name .
    	?regions admingeo:hasAreaCode ?code .
    	?regions admingeo:hasArea ?area .
    	}
    
    Insert
  • List the name of all the regions and their census codes that contains the District Ward "Town Close",
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
    PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
    	
    	SELECT ?region ?regionA ?censuscode WHERE {
    	?region spatialrelations:contains <http://data.ordnancesurvey.co.uk/id/7000000000006763> .
    	?region rdfs:label ?regionA .
    	?region <http://data.ordnancesurvey.co.uk/ontology/admingeo/hasCensusCode> ?censuscode.
    	
    	}
    
    Insert
  • Select the names and spatial relations(Northing and Easting)for all Named Places.
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
    PREFIX gaz: <http://data.ordnancesurvey.co.uk/ontology/50kGazetteer/>
    PREFIX spatialrelations: <http://data.ordnancesurvey.co.uk/ontology/spatialrelations/>
    	
    	SELECT ?namedplace ?name ?northing ?easting WHERE {
    	?namedplace gaz:featureType gaz:OtherSettlement.
    	?namedplace foaf:name ?name.
    	?namedplace spatialrelations:northing ?northing.
    	?namedplace spatialrelations:easting ?easting.
    	
    	} LIMIT 10
    
    Insert