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/E31000014 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000014 geosparql: asWKT MULTIPOLYGON (((0.151200738565452 51.123829856520565, 0.171628370376787 51.11541024852635, 0.226284335187785 51.124467906737095, 0.244534368873021 51.114880052008075, 0.275670548390623 51.11235542986929, 0.273935056034107 51.12007870089949, 0.325177409034887 51.12291711683715, 0.334703424301417 51.10556456466865, 0.358960090190952 51.10447855575473, 0.350820002040407 51.0840683281607, 0.37390355307443 51.088464717765596, 0.396473814042706 51.08309614602145, 0.41826687317312 51.062626965523926, 0.463267149806865 51.05478701157114, 0.472315371495058 51.03044158512259, 0.537600390884653 51.02167357188208, 0.541906636582485 51.01100643640808, 0.568381162158347 51.00381468169886, 0.605390836399549 51.01206996994109, 0.661355100182509 51.017787294531736, 0.676955930375848 51.003298780075056, 0.706770614525536 50.99360181819107, 0.740611388739665 51.00067670281243, 0.77895671604856 50.98949201927848, 0.777134941240379 50.97542834500679, 0.784327869089258 50.977229681350025, 0.812941759430859 50.94199957020854, 0.841401389026136 50.957608823737175, 0.855967982681082 50.95312860158269, 0.867891392847235 50.9332622897419, 0.854995576166642 50.92369703320031, 0.854736670285275 50.92372385536896, 0.844450875914465 50.92466454208133, 0.772015170902651 50.93126203307704, 0.774606898465139 50.92759823389593, 0.731886928240778 50.91455623790416, 0.687292871068532 50.88552522366735, 0.660542664831476 50.8704724732958, 0.658238301426148 50.869885995331174, 0.652391371210817 50.868397632924406, 0.560948622516946 50.851716380860594, 0.555812931863598 50.851429235640154, 0.503460804787371 50.84318607621381, 0.503103964858875 50.84312979410807, 0.378213258741164 50.82042592378925, 0.377512340122081 50.820298061952265, 0.339217550105541 50.7991870903028, 0.339108280368265 50.79903817149286, 0.337410679578794 50.796724440223734, 0.315215664347751 50.779553973635984, 0.307651816185782 50.776730806097625, 0.305990948506083 50.77611078078971, 0.266432145870353 50.7436707161572, 0.260056290608856 50.73843661859348, 0.21701271493433 50.7372851563092, 0.209988766934769 50.739537288582, 0.150070664251144 50.758723438550724, 0.148942717023948 50.75908416825913, 0.122143925137434 50.75840488452998, 0.071255390923874 50.78116923985244, 0.070705623337446 50.78141493139765, 0.056245555350176 50.7837648346463, 0.056910181204036 50.78142318636819, 0.057055752763772 50.78077395376878, 0.053707592439273 50.780508141625745, 0.05814540683196 50.775913739796714, 0.034061840835477 50.78182395916288, -0.014941702104848 50.79382984752205, -0.037784140284839 50.79941715441245, -0.038109130648172 50.7994966068198, -0.038544338827157 50.799193729649524, -0.092531879763769 50.81174360421834, -0.1063878148238 50.80826567013776, -0.110356523154925 50.80973858185014, -0.109993956522327 50.81334077245824, -0.125369208630302 50.815308219387354, -0.135775175863231 50.81916687705332, -0.216052272069857 50.82752821603755, -0.216695599257347 50.82748575112771, -0.244970855062882 50.863808898419265, -0.239238275684962 50.867885590847514, -0.226719319332873 50.87818063273033, -0.187734446489411 50.86857046402576, -0.182422843743901 50.888324770693096, -0.168612069801149 50.892368316822086, -0.168126147908153 50.88074823793895, -0.135010034605917 50.88663451006218, -0.119726368665445 50.94234120522393, -0.104170545645053 50.94647658164194, -0.115214878645701 50.976077131286374, -0.073619405547038 50.99167525754629, -0.061591830332896 50.97842041029823, -0.024604248233845 50.98002516835964, -0.01640976848822 51.002513828157454, -0.021913671039622 51.02651243811021, -0.001565480099292 51.035754981944, -0.003001715442351 51.047564317711284, 0.013725567363142 51.05701259795808, -0.008548146540854 51.056457983112566, -0.013256597991779 51.07396709711599, -0.026852086924925 51.07511286638146, -0.036213361793164 51.093429607515894, 0.01047320335532 51.1021824768213, 0.009505057118517 51.11039195163252, 0.018618578773843 51.10357550780294, 0.044560935760424 51.11064407808257, 0.028152565827307 51.11771965628199, 0.027361235652853 51.139850501349, 0.050016541019525 51.14265001100431, 0.133117097332669 51.14727851383109, 0.160747956682772 51.13731925961118, 0.151200738565452 51.123829856520565)))
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>