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/E01020202 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01020202 geosparql: asWKT MULTIPOLYGON (((-3.648125295879788 50.59227674065932, -3.6435546167916972 50.586298405531416, -3.6438199097555697 50.58604134633246, -3.6426250869378696 50.5846395019489, -3.6419059615386082 50.58217641696378, -3.6408192090842664 50.58062885984198, -3.638123601068331 50.57947398507112, -3.6411732824065717 50.57599531570698, -3.6444137830375007 50.57330495113769, -3.6456594349862237 50.57219402861505, -3.655566797414481 50.57617645834644, -3.6567685934456358 50.57533326236805, -3.6554667556508 50.57461278146175, -3.656698822707205 50.574189093520616, -3.6576481839937895 50.57250896190553, -3.6582018552471407 50.57259103099783, -3.6592359054953074 50.5718747954086, -3.6588807135344847 50.57141217546755, -3.6605433268901257 50.571079206036515, -3.6616756435982847 50.572100713988455, -3.6634961262398518 50.5737305050124, -3.6762623599082933 50.57538770982034, -3.679163373238061 50.57545963327865, -3.679323125858144 50.577172114863515, -3.681557050017478 50.578425999316956, -3.681827552908569 50.57909380463179, -3.6829560114061293 50.5789037454818, -3.684217901297779 50.577804199806344, -3.687534615463174 50.57945582052039, -3.689876827486064 50.57933693125765, -3.690891581323874 50.58201336444909, -3.692553914279662 50.58293909004943, -3.6938212275686912 50.58481878983244, -3.6986385521424086 50.58442988283086, -3.6991497511597857 50.58648094592468, -3.697116686041157 50.58848022949984, -3.697379127861819 50.590670891437334, -3.692645617147182 50.58829346466197, -3.692402948214316 50.58585967248216, -3.6894755717893717 50.58458907811601, -3.687134869573825 50.58403813236992, -3.6866288213929614 50.584936908498754, -3.684664918620125 50.58621475774923, -3.684615005681001 50.5873270220476, -3.681928168894835 50.588507510855656, -3.680666535257267 50.58849761520087, -3.6797039966401974 50.58787822854136, -3.6791634531658355 50.588965275987825, -3.6778301034596423 50.588417880580266, -3.6772916765543138 50.587815388525755, -3.6763616018286105 50.58757421710469, -3.6766638155003033 50.587004662078876, -3.6782566402920898 50.5865287252463, -3.678080945634205 50.58582387712755, -3.6791917521125193 50.58531097162724, -3.678923809407759 50.58447525469714, -3.6795965131754356 50.582935875072494, -3.6792954359185543 50.58187331862329, -3.6784384590806134 50.581731165981815, -3.678451535277836 50.58264649143866, -3.6771848412890633 50.58270044227716, -3.6760563913717115 50.582339665284636, -3.6747630519503307 50.58301612740561, -3.675589492558529 50.58371486818511, -3.6747962808304635 50.584027252758325, -3.672109868884384 50.582078571112966, -3.6684645833358807 50.58520226430708, -3.667098711509537 50.58676933991279, -3.666095476635436 50.5869510706599, -3.666014855664025 50.587718061468074, -3.664797679681842 50.58767108752946, -3.6638590070560473 50.587089303248185, -3.6619295946078947 50.58708590520693, -3.660145625454807 50.58974089495952, -3.661392975028043 50.59029893633373, -3.6608912559965194 50.59103202859808, -3.6601235204458935 50.59138547702975, -3.6581843469876487 50.59118160278043, -3.6524410329896577 50.59299273038647, -3.648125295879788 50.59227674065932)))
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>