add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank
http://opendatacommunities.org/id/geography/administration/lsoa/E01031466 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01031466 geosparql: asWKT MULTIPOLYGON (((-0.602804840877102 50.831755882790695, -0.6063475256359573 50.831121968479195, -0.6087405907976158 50.831065953467665, -0.6104599677873813 50.83365987869357, -0.6136007180998496 50.83329841094532, -0.6143972136183268 50.83517758133557, -0.6163726227595783 50.83484495291822, -0.6173910749199145 50.83185589962877, -0.6226928495242684 50.832987048347576, -0.62454487300067 50.83337491541831, -0.6241523976008968 50.83416627493836, -0.6255355709686037 50.83415552929896, -0.625132006756645 50.83518865765464, -0.6283799141532327 50.83552910764023, -0.6282921127583079 50.83610540635242, -0.6311523415370546 50.83648974669725, -0.6319876535899709 50.83604715124321, -0.6357775406497564 50.83646372356457, -0.6368245695753332 50.83644908022103, -0.6380554524959311 50.83650392498107, -0.643170595408242 50.83772105867172, -0.645049955870409 50.83895690899085, -0.6448801043995614 50.83919980594249, -0.6434312385577766 50.84281781173014, -0.643215252787556 50.84612541631843, -0.6430230775559032 50.84738615582651, -0.6440921616885984 50.84946513139204, -0.6447484964742403 50.84985588609901, -0.6504899294247779 50.85120751441919, -0.6505808928029467 50.85258771205004, -0.6480469382698025 50.85265793917907, -0.6446380276680761 50.853443487446455, -0.642204868217071 50.85367039249062, -0.6412350298200289 50.854001083976435, -0.6408398071588836 50.85348577496978, -0.639820332882074 50.85332389985619, -0.6386723753232555 50.85354269838951, -0.6379965890119204 50.85290824125835, -0.6342628126554569 50.85150180567392, -0.632510941095945 50.8503806645984, -0.6299752477140735 50.85158025442967, -0.6291062404075682 50.85148175910429, -0.6279175308596724 50.84921467284996, -0.6247014479149378 50.848214789238114, -0.6228095531758071 50.84802041420954, -0.6195253452857686 50.848407298737605, -0.6186761139987507 50.847957055988864, -0.6160662308946786 50.84841997609883, -0.6149085939686595 50.847921383106645, -0.6135400314304857 50.84819636223893, -0.6111796567947642 50.84773590170228, -0.6106748647094463 50.847072090430444, -0.6076247690112044 50.84727415761807, -0.6074804585863084 50.846658996269824, -0.6052928385164412 50.84522989637133, -0.6019813734999764 50.8439173966118, -0.6044907996150033 50.84189211246966, -0.6041872610332472 50.840786156012406, -0.6045198914533704 50.83750214538083, -0.6035943201395746 50.836685149016056, -0.6035867329004079 50.834813469527624, -0.602804840877102 50.831755882790695)))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:http://opendatacommunities.org/sparql, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

POST http://opendatacommunities.org/sparql HTTP/1.1
Host: opendatacommunities.org
Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded

query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):

GET http://opendatacommunities.org/sparql.json?query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
text/plain
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,
application/json

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

http://opendatacommunities.org/sparql.json?callback=myCallbackFunction&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

This help topic on the jQuery website has more details.

Examples

Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010" http://opendatacommunities.org/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://opendatacommunities.org/sparql?query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
<html lang='en'>
<head>
	<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = 'http://opendatacommunities.org/sparql.json';
	$.ajax({
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');
			console.log(data);
		}
	});
</script>
</body>
</html>