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/md/E08000034 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/md/E08000034 geosparql: asWKT MULTIPOLYGON (((-1.6816208675879984 53.756468876094615, -1.6584440307408748 53.74545776625565, -1.638644549913022 53.74615557828026, -1.6322537383612905 53.73081380381395, -1.623371638496213 53.718546957269126, -1.6054553939030225 53.72118326412382, -1.5820931723632439 53.71388346409094, -1.571122240617289 53.70640461551653, -1.5983760636273936 53.6997807550396, -1.602499446688037 53.69217161239856, -1.5923029107600946 53.6915641390878, -1.5919201253036244 53.68933469500037, -1.6050495365186679 53.67939262782612, -1.615216888244577 53.67758112784591, -1.6140936116040125 53.6737665864651, -1.5908819703445625 53.66049280381075, -1.6240970380984634 53.65410072218783, -1.6191998169815414 53.646321413513796, -1.6231652269695065 53.63810791613032, -1.6171915863967585 53.637716092846404, -1.612139065852313 53.63270791520063, -1.615692594149958 53.63023766562982, -1.614572008412266 53.62592605597629, -1.607513856913224 53.61957288570951, -1.5919111360475673 53.614669123592066, -1.58645333313437 53.60717404960951, -1.5911513416875582 53.60678115948207, -1.5851914003811176 53.6005318768201, -1.5879783575422683 53.59348657974677, -1.6017521848421556 53.58775895385463, -1.6002656449034964 53.57733933081803, -1.6096584025941159 53.57202946626743, -1.6156318807422114 53.56302832448876, -1.6565602763904952 53.5605580950061, -1.6639303919044282 53.55750137182755, -1.6619106222410795 53.553692816615666, -1.6694658635030186 53.55322754436116, -1.6990366551133071 53.55381049901589, -1.7041268543880845 53.560249802503535, -1.7231775008949741 53.55992676033133, -1.7300828103330848 53.54679170525569, -1.7558190223958017 53.53668105467657, -1.7974313173805359 53.53388754726757, -1.8042830517959623 53.53701334914583, -1.8222288665765536 53.52109091549025, -1.8271510343664086 53.52350788133693, -1.841820848794515 53.519908787322095, -1.873492655324618 53.54042967855032, -1.8941095099116885 53.53361173689009, -1.8993219949063291 53.5381121148377, -1.9096208164687283 53.53839096028187, -1.912884651441849 53.55164360669453, -1.9256660017319935 53.55318928409961, -1.9427258841208943 53.561641266077324, -1.9481094851270997 53.57284823564036, -1.9816462520716076 53.58933783153461, -2.0094707898902917 53.616779533429344, -2.0045419031823744 53.62240990687891, -1.9795081367702525 53.62305958209554, -1.972743750806937 53.62577346602322, -1.9632154082202418 53.63273130440296, -1.9413270802178582 53.64077695767751, -1.9341522727235885 53.6483395959751, -1.897797637819275 53.644651539220064, -1.875023781971774 53.65806928411839, -1.8435663586713655 53.666121886694356, -1.85362985110544 53.6725477121417, -1.8355341741647446 53.66897481050893, -1.8187762850178293 53.67291184068656, -1.8121529407984047 53.67760162360531, -1.7953433402651278 53.68136453793944, -1.7800300514594034 53.683590827618026, -1.7598508358870715 53.692677069209935, -1.746295472900195 53.694468410335986, -1.731405567263813 53.68036236615695, -1.7332388113933552 53.69480504384602, -1.7395391753752592 53.69945496915168, -1.736824671704591 53.71413206132009, -1.7444810825243668 53.71583385283985, -1.7554092991185999 53.720736216064914, -1.7536367876824064 53.72586029882164, -1.770086312769783 53.726252305725254, -1.760908992462729 53.73464544984215, -1.7459010083702589 53.73448983879483, -1.7473517207246407 53.746691358655184, -1.7362688931335686 53.74716918279825, -1.7295370102536327 53.75132826489695, -1.722217552726853 53.758833609165734, -1.7048796562651412 53.764848351559635, -1.6816208675879984 53.756468876094615)))
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>