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/lonb/E09000020 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lonb/E09000020 geosparql: asWKT MULTIPOLYGON (((-0.2160289349800449 51.52792816052723, -0.2155730163664009 51.526719914871556, -0.2126984107874138 51.526866736735535, -0.2065079169171147 51.526065471661454, -0.2038815678427015 51.52345886621927, -0.201639345728469 51.52274200224836, -0.2006340681440223 51.520710431543726, -0.2026691406197934 51.52089904433457, -0.2037667526989845 51.520622698151016, -0.2014881005438483 51.5177992182042, -0.2007475156907896 51.51797664752815, -0.1998940598734896 51.516775723447566, -0.1992078104440452 51.51455125528301, -0.1950726444551381 51.51503167242621, -0.1940649578161083 51.5117564341498, -0.1929847328089111 51.511813513238856, -0.1921438349951927 51.509868090646734, -0.1879335207817532 51.51017898558839, -0.1842592391893082 51.501793384139816, -0.1803361178652683 51.50146099477987, -0.179570859938611 51.497778360091374, -0.1735669976258804 51.49822098892399, -0.1684145442334595 51.49902101547539, -0.1676438695219739 51.498300301553115, -0.165803684964726 51.49924190774324, -0.1655057879836853 51.498696773967, -0.1625989752961155 51.50029237857755, -0.1610239360672071 51.501589571151825, -0.1584686645490922 51.50224817222206, -0.1578741344682056 51.49901774366575, -0.1560964931087545 51.49776232109412, -0.1553193952670053 51.49506408605282, -0.1560137463128587 51.49449407618415, -0.1550152734171549 51.49385608790188, -0.1560089157326751 51.49322156374646, -0.1548179428050502 51.491962757620826, -0.1558210961177922 51.49145064793902, -0.155196295133841 51.49004881698765, -0.1558739086841626 51.489606201567334, -0.1501952659869701 51.486092397333586, -0.1500542773501164 51.48547752264759, -0.163829778389574 51.48364764043277, -0.1700638843683331 51.48276940163073, -0.1739066270661102 51.481756461037605, -0.1756750315451325 51.48165093929497, -0.1778387029461821 51.48026556364893, -0.1775495570879567 51.480076720904734, -0.1793085623259345 51.47800068929874, -0.1808218983538468 51.47793336411859, -0.1821003575411905 51.47739835487113, -0.1838809198606452 51.47741873813161, -0.1944944320453179 51.48649335893687, -0.1959879127411557 51.487372362607545, -0.1964482618508203 51.487205938247584, -0.1982990042760649 51.48812196160695, -0.2023870865358221 51.49166837424159, -0.2018353197648809 51.491851399776905, -0.2030279551163059 51.49332109885607, -0.2073885719153488 51.496148538751626, -0.2080014610508394 51.49602206811824, -0.2102701603904128 51.49812771069322, -0.2141330786406404 51.5007701066639, -0.2179907818118242 51.50614601776661, -0.2159634483889269 51.506401164869885, -0.216144580306864 51.50751893184987, -0.2152029905917956 51.50764673698713, -0.215817060265073 51.509114594294225, -0.2168418206060376 51.50944401406808, -0.217209743825116 51.51039201323553, -0.218053369215972 51.51023042963888, -0.2178886507882089 51.50975937583645, -0.2192864944159827 51.50957473941914, -0.2226040400961625 51.515642770341884, -0.2283015983364134 51.52109742436441, -0.2267294493194637 51.52197651582806, -0.2266199279297952 51.524795776568, -0.2271951934588011 51.524792785389934, -0.2274121465642956 51.52789215681738, -0.2287277102116775 51.52987774157967, -0.2285031522491169 51.53035269792453, -0.2275880978079944 51.530156382806744, -0.2276852113137808 51.52991773266349, -0.2254466250809875 51.530168957349225, -0.2238038673297896 51.529963310801506, -0.2179790429438847 51.52864039878623, -0.2160289349800449 51.52792816052723)))
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>