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/E04005519 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04005519 geosparql: asWKT MULTIPOLYGON (((-0.9608517871316224 52.84335664343487, -0.9608449692458509 52.839718382444794, -0.9614782019745367 52.83781537354505, -0.9599950173639927 52.83520611042799, -0.9552097021334833 52.834871914622866, -0.9524878099142602 52.83256089645264, -0.9561063601022749 52.82959824369297, -0.9549191536307788 52.82748326145195, -0.9550187577609452 52.82363466436931, -0.9521430872638675 52.82380169301667, -0.9460604880933938 52.821871640831525, -0.9415718429839293 52.81989436785187, -0.9402633640000326 52.81755789686156, -0.9373602790105147 52.81728021919914, -0.9324772419900821 52.81581149341002, -0.9264906941311462 52.81452048125349, -0.9275888577745187 52.81312438430689, -0.9352000546792837 52.81015431937667, -0.9361806150518398 52.81058474083824, -0.9396795306172494 52.80946354368484, -0.9413994239572906 52.80981332295456, -0.9489058418146227 52.80817464726681, -0.9535766087640904 52.808150294486694, -0.9602603460988295 52.805085009390474, -0.9628256499931019 52.80506610066302, -0.9662554695214667 52.80405947485985, -0.97222192867959 52.80335703345081, -0.979915247304839 52.80181150390717, -0.982509326509612 52.799533232701855, -0.9877028262296779 52.79765109231201, -0.991802476356888 52.7957837085811, -1.0216540906152127 52.78780143358835, -1.0330366751713762 52.784775202614696, -1.0466233952009065 52.780954734067336, -1.0442114620398155 52.79306101238221, -1.042421470165511 52.801169023181366, -1.0403313620586863 52.80420962746859, -1.0369972626824049 52.810364118096096, -1.0362308765125139 52.81268449801855, -1.036289381401696 52.815877305405635, -1.0348190733645908 52.81687672750666, -1.0307761104785502 52.81772389642068, -1.027990105056581 52.819624953285974, -1.0251446719332054 52.820057405184194, -1.0220885986747505 52.82200644579231, -1.0155489789147192 52.8215298588097, -1.0101812458861246 52.82173333418013, -1.0016782412003626 52.8204242089128, -0.9956681137693746 52.82126889125286, -0.9915345243443964 52.819758599289344, -0.9893553675453708 52.818253135648746, -0.9869363963326585 52.81973472038423, -0.9827090455908521 52.82067485903838, -0.9796871425144966 52.82412709982273, -0.9777875688612566 52.825012437355106, -0.9775628991990751 52.827063789324924, -0.9751554738508543 52.82909001870182, -0.9748658823378342 52.83295046508239, -0.9741237144684696 52.83408576580224, -0.9773636907115654 52.83663987718002, -0.9771422193697102 52.840576425874744, -0.9704184577438502 52.84497007619887, -0.9608517871316224 52.84335664343487)))
http://opendatacommunities.org/id/geography/administration/par/E04005519 geosparql: asWKT POLYGON ((-0.961 52.843, -0.952 52.824, -0.926 52.815, -0.936 52.81, -0.966 52.804, -1.022 52.788, -1.047 52.781, -1.044 52.793, -1.036 52.816, -1.022 52.822, -0.989 52.818, -0.978 52.825, -0.977 52.841, -0.961 52.843))
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>