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/E31000040 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000040 geosparql: asWKT MULTIPOLYGON (((-2.134127259823476 53.685734025440254, -2.118084995183621 53.671245219613965, -2.092906462975322 53.670161120280824, -2.051242160614617 53.68369175500445, -2.026815728002123 53.62416714240834, -2.023035945064746 53.61583947230529, -2.009470774561354 53.616779506535394, -1.942725838681934 53.56164128945457, -1.912884630202868 53.55164361028742, -1.909620819361319 53.538390981866804, -1.92678064303258 53.52094874589353, -1.921972833200946 53.50995468018667, -1.951332662204349 53.50419883418156, -1.963385976710869 53.50982725596576, -1.987819562966447 53.48111039555362, -1.985792365648841 53.4552267683079, -2.008234840244295 53.44154929475235, -2.004216039482904 53.435921781986984, -2.014227492920115 53.43976274989592, -2.026255405064098 53.429865157555014, -2.013697169553762 53.41589010591543, -1.992329458069614 53.415193129149046, -2.004642854773065 53.38632727268837, -2.033775420197972 53.37554156585617, -2.031058450797742 53.37026238218233, -2.040563612453884 53.37408776247312, -2.068077795327012 53.3573936329965, -2.095179310922318 53.36608069528581, -2.123195710610306 53.3619466282943, -2.139025297828614 53.36731700767664, -2.151190584656578 53.348133130516906, -2.144099297708197 53.342871003527684, -2.160647534921056 53.327314692546196, -2.194162852685615 53.33865043711038, -2.180977265112509 53.34404379629561, -2.185440871428487 53.352659764772774, -2.240790071814372 53.35957426306446, -2.256447273553654 53.36067683735128, -2.301358998784904 53.34012061641723, -2.296930217371354 53.348583807210616, -2.313998148879243 53.35742463822241, -2.339874882090525 53.36737798812767, -2.375783612215103 53.36535117949829, -2.426589911388087 53.38746151214939, -2.478454385554697 53.39621856364466, -2.449378176101223 53.41589144041395, -2.489713809554706 53.46028229361464, -2.496334446683295 53.48092941814623, -2.552638530437996 53.467813403114086, -2.549075672481768 53.46148584902484, -2.570389935418627 53.458475592128345, -2.576742821026685 53.446057203656935, -2.615359138181341 53.463601416547235, -2.612138254736393 53.481138085842815, -2.645540001671886 53.48025231697614, -2.666295819882208 53.49975747520188, -2.698892998849714 53.502031556422644, -2.730520911617254 53.520600142133326, -2.717925541372682 53.52721115993184, -2.704819135696724 53.559192181583576, -2.719222610226238 53.57611417763334, -2.69335211016332 53.589428660023756, -2.689312575452456 53.604302838263045, -2.634592146738262 53.608282757925515, -2.625906761015946 53.59368326680578, -2.595925743338651 53.61081497603198, -2.569278269036208 53.595596943673236, -2.511322915572243 53.62699496215569, -2.479195327748007 53.61703588543341, -2.459700031517579 53.62004268962132, -2.438724370522257 53.646045444108104, -2.421696422695865 53.62383557019712, -2.379132103180365 53.6308703597745, -2.370327876693581 53.6315343263739, -2.362746502153803 53.65540147058859, -2.371236182074357 53.66708064995449, -2.316757278191183 53.65498721959143, -2.298985070758091 53.66670478463802, -2.295272764357941 53.64039523167134, -2.271787056387675 53.61451422956845, -2.25676900346231 53.620397951059054, -2.269866079585416 53.64613660673061, -2.245877491114286 53.66352172603444, -2.217728887157323 53.66898073427148, -2.205228487718943 53.65434883077581, -2.182407171095697 53.648257611533474, -2.185395826654737 53.63822408911096, -2.161352819803316 53.64137417156206, -2.146328063383273 53.68223152581118, -2.142257538589567 53.67800580532211, -2.134127259823476 53.685734025440254)))
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>