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/E01012107 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01012107 geosparql: asWKT MULTIPOLYGON (((-1.0846205198605807 54.62039756200223, -1.0847908580592094 54.618403006179726, -1.0848612631984194 54.61788766627866, -1.0893610311229625 54.61770477028537, -1.089581395771437 54.61713141288219, -1.092613710053993 54.61716918275805, -1.0893414574280629 54.616153837081725, -1.0849665828185997 54.61541736041107, -1.0844234444978436 54.61317694579501, -1.0916834149498222 54.61181093938384, -1.0899415275119426 54.61122191630904, -1.0881069787712832 54.60905468381559, -1.0877456422615248 54.607661688811, -1.0872622995965289 54.6070617697776, -1.0893808698441865 54.60630488311116, -1.0908833929571427 54.60626407357046, -1.0930178365024148 54.606177949304055, -1.0946079048389836 54.605866705828774, -1.0969520518084352 54.60651509161426, -1.0980997203799205 54.60732781245897, -1.0991133122889059 54.607096656204554, -1.0998776064631928 54.60751424127053, -1.1017440345327962 54.607185662845836, -1.1022394756073939 54.60809700643697, -1.1059631658528957 54.6072689215617, -1.108317950475909 54.60864146659372, -1.108986383777887 54.60797701062455, -1.1114856500715595 54.60767184415944, -1.1122692023357919 54.607237235056346, -1.1108286235694225 54.606561643153064, -1.1110888112715434 54.605988405023666, -1.1184913360146427 54.60085710082056, -1.1322194574843878 54.587844421993324, -1.1339972912226817 54.58792604325447, -1.1346381919370556 54.58689114515132, -1.1379312128255399 54.58703146369892, -1.1373349857682529 54.591817237749474, -1.1396497856596266 54.59213027075423, -1.1412792533863834 54.59191716572862, -1.1417180145684334 54.589448879814434, -1.1413025462575386 54.587864239531996, -1.141650705377497 54.58455053971738, -1.142383112573973 54.583567169457396, -1.140315734640112 54.5832828974114, -1.1404212209696356 54.58268151045475, -1.1480578423256353 54.582969921084015, -1.1487070013815348 54.58427305141581, -1.1475901089336198 54.58973693065446, -1.1495822293355065 54.58942600701752, -1.1579411399972626 54.586869810488786, -1.1629124936125206 54.58581601129757, -1.1700749164015836 54.58478130572038, -1.1877130668789582 54.5823342523146, -1.1904771255496613 54.58163773456493, -1.194328380404154 54.57989496613256, -1.1970617085615387 54.5817932054181, -1.1934324528774343 54.58436549143229, -1.1917614872866145 54.58537347343301, -1.190494599079596 54.58566518352999, -1.1840314719346547 54.589913031490106, -1.1834227685458707 54.589938603191975, -1.1814301807241758 54.59106736283257, -1.169407240394483 54.598898375161, -1.1638001233838022 54.60211123264451, -1.1634906939460892 54.60210458452437, -1.160295939513172 54.60419707926218, -1.1602532795813736 54.60454008804164, -1.1518979286269753 54.599564281655354, -1.1479110271289252 54.598652894935164, -1.1468739992015704 54.59946699780464, -1.1496446923908428 54.6006565557743, -1.157591957985209 54.605449934180456, -1.1568625502960543 54.60561111455111, -1.1560180819393628 54.60684541087035, -1.1548687372041322 54.60747456048601, -1.1550421972906606 54.60791883759444, -1.152896597672021 54.60954930585095, -1.1512634822284573 54.61325841409601, -1.1510201739124803 54.61416167866664, -1.1496618501732434 54.61410364070328, -1.1493942443963856 54.61468408782016, -1.150681364886696 54.61504089849526, -1.1507228338743003 54.6203379988672, -1.151520352578568 54.62145976281598, -1.1527800446892502 54.622624278275524, -1.1533130980277564 54.62611846679984, -1.1519864647856968 54.6278696779413, -1.1532720097130014 54.62847270351266, -1.1531651579043098 54.62936522309725, -1.1521258793697382 54.63032853390327, -1.1512659577579643 54.62892419044957, -1.149406260322055 54.62822274442364, -1.1460585055758294 54.62772470264072, -1.1436978456000764 54.627653212893954, -1.1405679464679264 54.62799592327197, -1.1354464419842836 54.629631924727875, -1.135687299064307 54.631058954752795, -1.137437660563498 54.63223518850515, -1.1384773492323135 54.6336202663828, -1.1400973051239642 54.63437678589943, -1.1398113657795357 54.63500560927662, -1.141072810538491 54.63520958869437, -1.1401437860811636 54.63606662755327, -1.141044127066531 54.6367928709802, -1.140175675544014 54.63830095388871, -1.141909108640082 54.63816948054526, -1.1405050850387646 54.63957852999362, -1.1407992716393087 54.64039840225706, -1.140314151662821 54.64077421164307, -1.1400252375130238 54.64433273204842, -1.1391776670845921 54.644845258802, -1.1374758497086868 54.64758306088732, -1.137180700486117 54.64694568624849, -1.1387462546514862 54.64069297229835, -1.1277270178405334 54.63574423964969, -1.1234289272683982 54.63302526729706, -1.118973087207873 54.629390142921174, -1.1188125521438474 54.628861432380425, -1.1167812385829474 54.62845842924705, -1.1075583162561178 54.625355081374224, -1.1004931541069471 54.6234901997022, -1.088132964566435 54.62075207201135, -1.0846205198605807 54.62039756200223)), ((-1.1503006756598575 54.6322074790688, -1.1512978908832754 54.63222705867738, -1.150569870988579 54.63348817363203, -1.1512768359738366 54.63450592636982, -1.1509164862565648 54.63521966426778, -1.1494083239641515 54.63473638302674, -1.1503006756598575 54.6322074790688)))
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>
<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>