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/par/E04001569 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04001569 geosparql: asWKT MULTIPOLYGON (((-0.603176195620513 51.72787909810589, -0.5977418038997372 51.7273755956356, -0.594566304042845 51.72523624030642, -0.5943804016616389 51.72441484313921, -0.5911444496495856 51.72213619093615, -0.5883236060836642 51.72299346352897, -0.587612625567549 51.72178988125281, -0.5822643930374735 51.72189275696419, -0.5827298740480429 51.720340946754604, -0.5859236653730804 51.71768988518525, -0.584482958538566 51.71654224510347, -0.5797638491344358 51.71123126309005, -0.578101343256659 51.70862954159265, -0.5787068703025747 51.70722690749758, -0.5818483005338545 51.70608868648117, -0.5827734535321356 51.70482656705749, -0.579404206540427 51.70219977370181, -0.5781684786316906 51.69993501257772, -0.5818464795159782 51.69832670331967, -0.5813225574948836 51.688753692982075, -0.5845081264761536 51.68713126799194, -0.5756300222056273 51.68400173151911, -0.5801716175382187 51.6825846868219, -0.583986994881435 51.68227464082851, -0.5902046941526367 51.68457854771786, -0.591633832780749 51.68718990196033, -0.5945473272152756 51.68961847265426, -0.6092643939744027 51.69344972581698, -0.6109998796482636 51.69479567916307, -0.6141027607451595 51.69566947022904, -0.6164206304022541 51.69723621701329, -0.6181878322087375 51.69617616539996, -0.6225245458529702 51.69702557764115, -0.6247113679727828 51.69896559355419, -0.6292822927440253 51.69777720673837, -0.6335601978460874 51.69814085254465, -0.6340611258226748 51.70009973727461, -0.6370312967218927 51.70185349683781, -0.6349051207037081 51.70335385467764, -0.6408338732819753 51.706548196312504, -0.6391490717774212 51.709637222670004, -0.6432034236487051 51.71054643572472, -0.638555522791487 51.716094682935456, -0.6400655113257421 51.71710128263065, -0.6369572200639183 51.718602905862454, -0.6338282949046627 51.71828602957377, -0.6317228050551996 51.720273953837314, -0.6317712655270552 51.72231300522138, -0.626094119250692 51.723620775638594, -0.6227504108882036 51.72555180179149, -0.6181566881569603 51.727061608342076, -0.6167834219028882 51.72803188261212, -0.6175370303921075 51.72967009704303, -0.6151117320852001 51.73033124089096, -0.614277293504311 51.73077010996767, -0.6093335328448921 51.729032930715945, -0.603176195620513 51.72787909810589)))
http://opendatacommunities.org/id/geography/administration/par/E04001569 geosparql: asWKT POLYGON ((-0.603 51.728, -0.583 51.72, -0.581 51.689, -0.576 51.684, -0.584 51.682, -0.595 51.69, -0.618 51.696, -0.634 51.698, -0.643 51.711, -0.633 51.722, -0.615 51.73, -0.603 51.728))
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>