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/E04004900 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04004900 geosparql: asWKT MULTIPOLYGON (((1.2281675522469964 51.14877591988747, 1.23295791494015 51.14737618568515, 1.2424406252028681 51.14808599886765, 1.2453555332264719 51.1461341711869, 1.2536811765355418 51.14850957886072, 1.2584972064877549 51.14935234276223, 1.2596911901702996 51.14888280577076, 1.2604702317400727 51.14563185797363, 1.262892533615462 51.14244659939013, 1.2603677321905145 51.14107421501116, 1.2542356044257956 51.136511833770996, 1.2521397211715184 51.13330044128896, 1.244068365807609 51.13320623516145, 1.2408287137247291 51.135552929365396, 1.2345237839473686 51.13355161270072, 1.2327506568568523 51.13233954601226, 1.2356234487623035 51.12977295628555, 1.2320489520370552 51.12820863735611, 1.2235620400322824 51.123571225921424, 1.2265191772953443 51.121804887197484, 1.2251538307006802 51.12046631885928, 1.2193271494375295 51.11901320019653, 1.2170221107178603 51.12113560692058, 1.2134332500991158 51.11916005280277, 1.2064471125001166 51.12229501224937, 1.205942035581063 51.12018244713533, 1.2029984398026403 51.120770439748235, 1.1973675248163003 51.11814870492563, 1.1937031295692666 51.118999917129784, 1.189574815861534 51.11926010502706, 1.185800498521216 51.1214039430792, 1.180866695690221 51.119202253577406, 1.179150604876229 51.120873406111826, 1.1780087272311524 51.12370636797035, 1.174870915441843 51.12226425121455, 1.1730518994396686 51.12252230088162, 1.1714976129718169 51.12464139078797, 1.1741546377855556 51.12699254360868, 1.1737206134204898 51.127646560492, 1.1769390269712667 51.13123631032933, 1.1773234739713747 51.132441981994994, 1.1790066265568557 51.13450825607125, 1.182169133463094 51.13336444907238, 1.184505607528405 51.134782320099895, 1.1880765195403256 51.13462926455063, 1.1892115549963447 51.13651424366576, 1.1891444710644425 51.13875581596955, 1.1968325344490438 51.14315943700449, 1.199286178802216 51.14493450881031, 1.2024047163901344 51.145755843738534, 1.2030942588422942 51.14720493703902, 1.207989940305127 51.150263056554714, 1.2110647294398222 51.151476644390264, 1.2109183658160259 51.149430709799084, 1.2134645607431727 51.149088224589406, 1.2149995558926177 51.147058144691464, 1.2216929301671602 51.14788766873398, 1.2245332431226355 51.14725349288568, 1.2281675522469964 51.14877591988747)))
http://opendatacommunities.org/id/geography/administration/par/E04004900 geosparql: asWKT POLYGON ((1.228 51.149, 1.26 51.146, 1.252 51.133, 1.241 51.136, 1.226 51.122, 1.206 51.122, 1.197 51.118, 1.181 51.119, 1.171 51.125, 1.177 51.132, 1.211 51.151, 1.228 51.149))
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>