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/E04003132 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04003132 geosparql: asWKT MULTIPOLYGON (((-4.068106983625476 50.45455455862528, -4.070827320649355 50.45368050496895, -4.073481094461186 50.45028645104662, -4.070711060023748 50.44966119222596, -4.069744713301416 50.447013348577464, -4.070755381391695 50.44583509284748, -4.068524655275527 50.44368014002589, -4.070842230534879 50.442241188902145, -4.070768526943207 50.438615944938114, -4.073348055885492 50.4366047165764, -4.076442262597239 50.437735899736865, -4.077816075558553 50.43723736320835, -4.079491809350424 50.43517736921272, -4.081540350206258 50.43385092305466, -4.084160194982143 50.43062625632375, -4.085263182568959 50.42823284084906, -4.084730843565228 50.425826455117026, -4.086843013659717 50.425799382078765, -4.089142522683502 50.42686174018815, -4.093052097149929 50.42704331816714, -4.094307245508303 50.427886902584866, -4.097931256141637 50.42864550762857, -4.099342685236819 50.429931447754015, -4.101643683812066 50.43044397191254, -4.1062024770706 50.43033189533506, -4.108764431825861 50.43379875413683, -4.107436926990742 50.43571163768437, -4.106514277503287 50.43856160111152, -4.109111453753378 50.4384695909217, -4.110216687240926 50.4421984471573, -4.1134883705535135 50.44415382842387, -4.12267632107444 50.44081778843914, -4.125121708565707 50.438183626737086, -4.124398334080428 50.43611913154536, -4.131965031579755 50.43367087631808, -4.136105196959696 50.4328564524269, -4.141622962807073 50.433271220533626, -4.146810857733687 50.431216546171754, -4.14864836194325 50.43295540965638, -4.151001081420477 50.43359908349435, -4.151121776816826 50.436635206003416, -4.155855534145723 50.43642703127681, -4.1561919067438735 50.43384925298614, -4.160305742019615 50.431227457253534, -4.165303529645298 50.42999759647585, -4.163514947344574 50.42758166625286, -4.166145806118427 50.42537308932692, -4.169327006034816 50.42402936251531, -4.1730997520215 50.42447881478341, -4.176228699010291 50.42264567420145, -4.178342056403091 50.42464248438408, -4.184233736566582 50.42576064390351, -4.188855992765168 50.42758869501776, -4.189308210634011 50.42881514302884, -4.184418977297157 50.429450348714276, -4.182943975307347 50.43075167814899, -4.176111394093015 50.43467813425094, -4.173758155581846 50.43544620338488, -4.170202331398032 50.44046861634123, -4.166638098649197 50.44239244199335, -4.165002566284251 50.443806254804166, -4.1661616469823395 50.4454072874449, -4.163428942176385 50.44676505154085, -4.162101511327591 50.45043161531519, -4.160067907265839 50.45118715844329, -4.156851135310396 50.45349726964959, -4.154593418202161 50.456549562641875, -4.154636564710472 50.45991718973823, -4.157000366032052 50.4611442953864, -4.156185555028581 50.462622797905645, -4.151913884621623 50.46391075248629, -4.147478196639025 50.46326327521115, -4.145602602346498 50.462296805466075, -4.142528838053894 50.46222214140151, -4.138249819362724 50.46351062388037, -4.136930117693334 50.46474372282275, -4.135110407116607 50.46426355565312, -4.129317563132245 50.46495616326832, -4.123630614650154 50.464493466914774, -4.116261260389131 50.463051938429295, -4.108566788456492 50.462970378259634, -4.109546712396263 50.459374656675635, -4.109158265753489 50.45789582591438, -4.110293598686773 50.45418573356815, -4.108206070541018 50.45447901921544, -4.1072677055947695 50.45038736941009, -4.104275041819741 50.455359680015015, -4.098859658612672 50.46068143239026, -4.088461743721925 50.46456696726503, -4.0780099152575575 50.46880419392958, -4.077791931251095 50.469907189233076, -4.076192838707904 50.465639141018904, -4.076282310351031 50.46427130505056, -4.072790322033356 50.46252658422892, -4.070119712351012 50.45948276004273, -4.065173451466338 50.45962729545313, -4.065278254378302 50.45802174406451, -4.068106983625476 50.45455455862528)))
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>