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/E04004013 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04004013 geosparql: asWKT MULTIPOLYGON (((0.2968396332125691 51.788989338339924, 0.2977281195224168 51.78852503258944, 0.2983823516064507 51.78348346778822, 0.2964316325531751 51.78070324858339, 0.3014987465701864 51.778938671903255, 0.3028298898606977 51.77740720141838, 0.302052823215205 51.775442203857914, 0.2985230651258318 51.77353376378502, 0.2995410925341723 51.77180341631233, 0.3033054583512873 51.77157502913832, 0.3077368555777527 51.770131083597114, 0.3123251390100523 51.770315183642715, 0.3129658363809409 51.768842138593186, 0.3185961670051571 51.77004415378459, 0.3195986272436183 51.77260442251824, 0.3223491006263022 51.77202492342288, 0.3216386820500036 51.769932831746445, 0.3242115544658374 51.7701598581497, 0.3272986635839431 51.76916890418995, 0.3361090172010059 51.76831154931372, 0.340547916077781 51.76731854853653, 0.3467004632200602 51.76759604309941, 0.3449676712415202 51.76621154762023, 0.3449861894009284 51.76343775909181, 0.3442564054604862 51.76037403861911, 0.3425491812075444 51.75813286344639, 0.3362275881328716 51.756688527600765, 0.3309335099347208 51.75633681182645, 0.3308766621191556 51.75548630062847, 0.3265362300124226 51.755726993383796, 0.3253671336812948 51.75370152524655, 0.3183949127370705 51.75308117729778, 0.3179049340653501 51.75412324008432, 0.3142293069087035 51.75381887668334, 0.3147923260935847 51.75720624181174, 0.3044069521065586 51.7566369530901, 0.2996948600254601 51.75575621830015, 0.2971537860282286 51.756793346703745, 0.292652880348257 51.7572184775489, 0.2913818323969143 51.756298106277924, 0.2883824114689629 51.75695818076424, 0.2887600230449003 51.75961093663789, 0.2863089891059731 51.76100487531944, 0.2853127945627566 51.75981651113646, 0.2859004568457406 51.758053265138074, 0.2847490650816008 51.753530613004735, 0.2874571392441397 51.7535597668144, 0.2871770107026515 51.75188713130294, 0.2837270633451364 51.75214218048929, 0.2819939068270478 51.74949234513774, 0.2818675282959476 51.75017556943716, 0.2779872986651467 51.752415457634385, 0.2806568107326078 51.75691411602933, 0.2762764288735679 51.7570880741903, 0.2733092159418231 51.759605971048984, 0.270973192168416 51.760759951572574, 0.2606442119463525 51.76413625181753, 0.2572620812139719 51.76446474776821, 0.2489340066634412 51.7639580360229, 0.2460661894890542 51.76994631157468, 0.2457083841579109 51.771993603072794, 0.2436213446654821 51.77299208724594, 0.2408201194504654 51.77610755114769, 0.2393551603497221 51.775739790299326, 0.2383166174584242 51.7760203609536, 0.2375279336101572 51.77982670984692, 0.2426148736174258 51.78066860623625, 0.2502258826122077 51.7808936501811, 0.253823685855504 51.78172489437385, 0.2574990055289646 51.7818701927798, 0.259610546841028 51.784289138464395, 0.2625088816721839 51.78440425134273, 0.2661002124088677 51.78558776302674, 0.2688098341326884 51.78714070218631, 0.2741352849940996 51.78765110152979, 0.2776987886069898 51.789105481970836, 0.2813857864273735 51.7894971114086, 0.2877590091011021 51.7889263084688, 0.2956167750008457 51.79026502248853, 0.2968396332125691 51.788989338339924)))
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>