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/fire-authority-area/E31000002 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000002 geosparql: asWKT MULTIPOLYGON (((-0.382341185697938 52.27112565164838, -0.374375668353571 52.232998283529014, -0.34101082808857 52.230647488830414, -0.343468847008539 52.24187441604687, -0.335249400332413 52.242881802861284, -0.293208976769364 52.240516176126626, -0.285613634755858 52.23727706373837, -0.29628436573985 52.21048709027008, -0.261845175363318 52.20986691616521, -0.240722991474732 52.190193138774916, -0.24978513637842 52.18437102218585, -0.260694075195782 52.17640141685848, -0.216624311583909 52.15873553889973, -0.234804030866533 52.14472675328988, -0.171534722741528 52.1395025859768, -0.154352335985911 52.144407921359345, -0.144445022402714 52.138203752332615, -0.157280858481759 52.08054719535943, -0.17261940186068 52.060209932680195, -0.194982606547798 52.06241507627381, -0.219493421719825 52.03674125404612, -0.201255994797197 52.009824683451626, -0.244078657945671 51.99902328417223, -0.247983014148297 51.98507998052951, -0.270625707594963 51.97962203835343, -0.282415822556106 52.00156401201204, -0.296089139106161 52.002192434344565, -0.31155544050291 51.982109909815335, -0.367157506519246 51.98376096652639, -0.349264212582278 51.97116968931163, -0.350225328991146 51.95757809880246, -0.374104640701829 51.94776932146515, -0.382989171169512 51.95181756525623, -0.379630050793909 51.97795751893329, -0.391303382193442 51.97702063937194, -0.405607096928768 51.93245434716436, -0.385615543134399 51.91568039078409, -0.377489871160045 51.89843309128976, -0.349898894608467 51.87870821412184, -0.354833877528721 51.87401452409355, -0.339485883518071 51.84960554584597, -0.363307654573655 51.84210473618838, -0.373362793969493 51.82922916312178, -0.404858794091122 51.84060745982013, -0.421500797563722 51.85020522080382, -0.447524493330487 51.84760161928413, -0.470419984213218 51.8557101645571, -0.478298456568694 51.853136497367004, -0.471195664299083 51.845467864468105, -0.501818257924659 51.83679481732698, -0.511192904519501 51.825893605101506, -0.502282745805324 51.81545868881856, -0.519728835410532 51.805095356748794, -0.553628602093621 51.826712669137976, -0.543650542622043 51.82451781913902, -0.537628491358587 51.83141084498487, -0.583563566023975 51.870323835445355, -0.620089145316851 51.88548551258028, -0.651979960418011 51.88679050863085, -0.672969105469311 51.901752710317574, -0.692702676008113 51.90015066936581, -0.702156741425682 51.909119108270005, -0.652978320056627 51.96922895989817, -0.645680793607104 51.97222830616508, -0.661689654324399 51.999736380235184, -0.64347687768972 52.010854698605485, -0.651023968049189 52.01848607168604, -0.640200276262236 52.02406577754141, -0.64304737334124 52.03724943337894, -0.668975964645554 52.048716835688026, -0.591810318519528 52.11069188306015, -0.607249368804315 52.13386874676304, -0.635451642179665 52.13925361587081, -0.640781500199599 52.152772269440575, -0.630670840375619 52.15492396982633, -0.627446640164576 52.181545463337734, -0.668135626510287 52.19503410682096, -0.637331610386329 52.227317626790644, -0.653655458350616 52.26828930135969, -0.610617027880452 52.279497942385184, -0.586335326297426 52.27283132924135, -0.565693043905503 52.25346822153572, -0.541971896331942 52.25607274363254, -0.531190172211852 52.270402425456886, -0.541969401561205 52.28994244201191, -0.514051184472571 52.31469707130909, -0.519829867421592 52.317692563215125, -0.465365745234521 52.32295327638489, -0.436088642390927 52.3144708411153, -0.435761099415093 52.296656875203325, -0.42176742668705 52.284947493601905, -0.375009955485427 52.280469373464285, -0.372175057429902 52.27349984822396, -0.382341185697938 52.27112565164838)))
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>