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/nmd/E07000224 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/nmd/E07000224 geosparql: asWKT MULTIPOLYGON (((-0.5531034159498118 50.90151702534637, -0.5435563846069954 50.898097893078535, -0.5429648679166973 50.89121622743673, -0.5486802359709955 50.89301676900228, -0.5610380866153967 50.887850333406476, -0.5492277021404414 50.88015630417774, -0.5471389769198575 50.88451446068583, -0.5381787937657415 50.88622281518266, -0.5328246669862293 50.88115100808013, -0.5247917750828117 50.882984194628776, -0.5192797629306009 50.88981390707112, -0.5149267736611809 50.88894294698287, -0.4999180191074734 50.89988274587577, -0.4928961994211705 50.89258793805734, -0.4752795275348476 50.8943440437064, -0.4765877253235227 50.88505588381816, -0.4649213418904555 50.88397138649346, -0.4553576251035854 50.89688097354949, -0.4515023557483955 50.89546744918643, -0.4479341558575335 50.87972417379272, -0.4399843277123131 50.87752735093097, -0.4310768295549296 50.892790973113236, -0.4273741750079563 50.89316925981196, -0.4248674430234846 50.88633119872366, -0.4117399134521769 50.8865590670182, -0.4131609551414306 50.87958800992635, -0.4086197808985898 50.87990396034494, -0.3959554958239189 50.89190747187663, -0.388718497293666 50.89234565280036, -0.3866341702457523 50.88727531502754, -0.3800641881955241 50.885593461554784, -0.3638962538391908 50.88847967729475, -0.3667070300571506 50.88222017523454, -0.3645979329531462 50.87452573808025, -0.3715080714796033 50.870668029210286, -0.3674532533772648 50.86053179623579, -0.3812669730540151 50.86322429102299, -0.4054408795668248 50.854620468584315, -0.4092803945341216 50.85226356944383, -0.4227938166752555 50.86023489937397, -0.422297576389061 50.8406780084773, -0.4460070802169787 50.83985417888948, -0.4465318283784237 50.83632589710017, -0.4436449628020041 50.821415390239245, -0.4359748155807521 50.803201353420974, -0.4528936998440543 50.80243967119258, -0.5073753641999793 50.802632782219966, -0.5380762153518874 50.802320696439814, -0.542009730249605 50.80024026540898, -0.5603792468613784 50.799756868006284, -0.5949661970482069 50.792445752466236, -0.6273696679737812 50.78847287336916, -0.6422782456368714 50.78738337456766, -0.6595774032328238 50.78396903637217, -0.6882403047326027 50.779494394454154, -0.7164942249357661 50.77448004808233, -0.7285391393097921 50.77131756619718, -0.7513289952471618 50.75807944633585, -0.7503664839499671 50.76259165733777, -0.756888742180357 50.76764260621828, -0.7553949513944306 50.77194695940096, -0.7615289268617103 50.77272184573113, -0.7560418889583874 50.78376364212096, -0.7495813524428504 50.78196698030736, -0.7550920416055561 50.790685433446676, -0.7347059735024964 50.79372311702731, -0.7393761527261388 50.79712714393308, -0.7339724046819387 50.80223366826458, -0.7347412759236236 50.80944279598461, -0.7194191068228319 50.80523957048301, -0.7009255606518973 50.813351125736055, -0.6898969087109916 50.81281506893816, -0.6866078451520692 50.82111832445976, -0.6925232967209314 50.8354172645882, -0.6939420831739255 50.84589394627889, -0.6861039255358838 50.85471635060178, -0.6811247271575303 50.863285479202645, -0.6503749948302462 50.86690091384916, -0.6540127563219966 50.87934347164349, -0.6497924912291285 50.8857805593392, -0.6582024838929375 50.887537631070465, -0.657766537619374 50.90240806895276, -0.65494452433664 50.90567875275933, -0.648576762397504 50.905388487579614, -0.6492017137159094 50.90001155955838, -0.6336529833524631 50.904843388377444, -0.6173851269795578 50.90556204818608, -0.60496002853405 50.90146905452786, -0.593697510333996 50.90280343609258, -0.5795734921716111 50.899253812228196, -0.5531034159498118 50.90151702534637)))
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>