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/E01017478 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01017478 geosparql: asWKT MULTIPOLYGON (((-0.5133342424972445 52.24252927459389, -0.5089894595971887 52.24139965738188, -0.5077039406159978 52.24230868195876, -0.5061316999235986 52.241682304635596, -0.5084051590477642 52.23944063414395, -0.5062781287681558 52.24003287143828, -0.5031213636705014 52.23930016298231, -0.5008640499635402 52.23805041412862, -0.4945069564334306 52.2361446163373, -0.4947497634764383 52.23510893748844, -0.492479194460167 52.23676360314485, -0.4902405908813265 52.237012476497654, -0.4880204589935739 52.23979025374595, -0.4859134686357028 52.239015255106096, -0.4843881946495576 52.24005836661627, -0.4831998876144086 52.23960618218946, -0.4821469555053167 52.23843263699082, -0.4811823827239006 52.238077733368264, -0.4809202826089103 52.23718872097312, -0.477056286732526 52.23210439391822, -0.473240721604032 52.230423635061044, -0.4720569270522205 52.231103609566226, -0.4687801092266954 52.23184665958336, -0.4668788341849338 52.23347905590014, -0.4663539526227135 52.233360000744995, -0.4595177562212268 52.231791784925484, -0.4564100759696536 52.2318600843102, -0.4551092598594349 52.2325807808542, -0.4493541241906476 52.233426787270304, -0.4448693977314833 52.23350586947139, -0.4442674356972882 52.23382583834532, -0.4433681363954107 52.2356467933855, -0.4411361745509971 52.23732047254576, -0.4391720264061031 52.236702768839436, -0.4337420957588697 52.23655862410254, -0.4336464218310193 52.233394947124104, -0.4329766663007493 52.232518115941104, -0.4331305984457357 52.230810268349906, -0.4339494078396244 52.22842453636771, -0.4364838804635496 52.22504973776378, -0.436258986516148 52.22406600400489, -0.4372082368164167 52.219113358575036, -0.4382591336792004 52.21588767164902, -0.435795551029042 52.21142461726376, -0.4379855629930032 52.20805723311401, -0.438566344019852 52.20501749878711, -0.4413368744641302 52.2008847210413, -0.441134688958485 52.199290976907264, -0.443318757655936 52.19703814237938, -0.4472140024321631 52.194031305317374, -0.4483456191309912 52.19421421536549, -0.4497257377230063 52.19381524117729, -0.4502049996599384 52.19417035222509, -0.4526471942365918 52.19332031477605, -0.453795660843766 52.19400431806299, -0.455826589850971 52.19260670627635, -0.456539630723113 52.19318157180588, -0.4597825416495191 52.1912647973747, -0.4653667575960149 52.190959009323095, -0.4691360402492973 52.18948752286584, -0.469397283080939 52.1916820797692, -0.4720500068272748 52.19239978522753, -0.4726678674528471 52.190204080991634, -0.4755891966015449 52.18901540373302, -0.4792985271726998 52.18809404482239, -0.4794117485502961 52.1903523058412, -0.4799650492863184 52.19093937068644, -0.4810215920643436 52.1912353569835, -0.4844411563106457 52.19087922348033, -0.4862204563295314 52.189143302104576, -0.4879467300799828 52.188805771730124, -0.4926484738538138 52.186431118991436, -0.4937655160884062 52.183674298349395, -0.496813014829211 52.18321594089161, -0.5084243629104084 52.183615378097926, -0.508889281692469 52.18277944869703, -0.510535484933985 52.182417963092476, -0.5115882865931138 52.18268747691685, -0.512139803865761 52.18544924885165, -0.5135022381082943 52.1881449427591, -0.5125955333128449 52.18860699339496, -0.5146072564313966 52.190639541551114, -0.5161408646692289 52.19138659996837, -0.5198438852189766 52.19230312245604, -0.5225316841014692 52.192152337910585, -0.5254429328612789 52.19091198912328, -0.5263081701183645 52.189922226966125, -0.532885578630797 52.19100207116747, -0.5375480209984113 52.19313080294755, -0.5390927620563538 52.19479664934825, -0.5396622638439753 52.19678968198075, -0.5394663069725175 52.1980094126598, -0.5387460952003205 52.198777402747304, -0.5381955939750893 52.200743224194554, -0.5326751738422404 52.20419436757147, -0.5300594321633079 52.20442705341587, -0.5287309757613108 52.20242974521917, -0.5265561694888198 52.20167964640732, -0.5177288328192661 52.20205940064697, -0.516818727452971 52.20270854524481, -0.5131889127977632 52.206416723752845, -0.5123150005036415 52.20863484311397, -0.5131799631352355 52.209087782199774, -0.5136620988598177 52.2100426513174, -0.5147719156340088 52.21085951756249, -0.5144218340448756 52.21127685598865, -0.5160357034225892 52.213482739075445, -0.5170785971619943 52.21675593397548, -0.5191626763583759 52.2188067507787, -0.5179759235989593 52.22073353876254, -0.5170919762037121 52.22048951359297, -0.5162598080043296 52.22103395097066, -0.5162600263055082 52.22200531892758, -0.5150772317416342 52.22313429449429, -0.5153000177730245 52.22343676398103, -0.5103102112514272 52.226680035177495, -0.5106118794932493 52.22751444513435, -0.5117873767610746 52.22931596344843, -0.5136396138756314 52.22805676329799, -0.515170380602671 52.230533697132685, -0.5188366073666322 52.23260995323742, -0.5159860162751245 52.23373852142019, -0.5155396900806011 52.23333127442753, -0.5139335288312181 52.233397198277025, -0.5143127594100794 52.23591011288781, -0.5172039489548653 52.23951568779, -0.5133342424972445 52.24252927459389)))
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>