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/fire-authority-area/E31000024 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000024 geosparql: asWKT MULTIPOLYGON (((-0.778437323540755 52.959313816067606, -0.75495007580103 52.94955618888562, -0.776859432203878 52.90480889982359, -0.758468258456332 52.90049004541209, -0.766592043345101 52.886798359050886, -0.742722529419467 52.883157173960385, -0.682248159975162 52.81216467335199, -0.664101440623677 52.75671045642549, -0.610288457290914 52.759821375145854, -0.605443829640691 52.75049293990032, -0.572636457415741 52.75310903360462, -0.539974263112861 52.73840175024219, -0.542433629710268 52.7232814449149, -0.494530895619109 52.70965327524145, -0.430443216210657 52.70542194292151, -0.434054523257773 52.68370506627237, -0.456191189284966 52.67039342882467, -0.506674308286943 52.65952591669844, -0.523585988701244 52.66523371565747, -0.495025790703755 52.640236379755386, -0.517397137688665 52.64237952147393, -0.540260640479169 52.625965764537206, -0.552938841546362 52.60134894604728, -0.544173519687944 52.59288827636857, -0.558117801411006 52.594483963016934, -0.571903713438616 52.58580336515993, -0.581546976489992 52.59586822276293, -0.586972388363159 52.587428866458424, -0.603019129058929 52.58859112767653, -0.674864332877134 52.55863837799075, -0.713658325198867 52.52496396365628, -0.756156296778988 52.51099470822832, -0.774866772163763 52.5182763314597, -0.79616062209775 52.51636512987978, -0.868809892555173 52.526953611330164, -0.883443178001951 52.51397015340121, -0.882125548422666 52.493165800332505, -0.89804782206813 52.486918445988316, -0.882395502135741 52.47128283970069, -0.901280593790273 52.45975585535469, -0.942191906175676 52.467772516887656, -0.951908249889588 52.4774239260676, -1.000692639505022 52.470940413022376, -1.044510518711052 52.44574808960904, -1.034273668192961 52.436285267379326, -1.049984918673334 52.422208533962745, -1.084381780209585 52.4362981432044, -1.129269512829384 52.416103447382774, -1.149352938995101 52.397040622067834, -1.183992075919418 52.39217107235354, -1.201613269875416 52.39673179021593, -1.305947528763158 52.49339527584502, -1.325088108918804 52.501042319832514, -1.417344239461088 52.53445530238273, -1.459994011305008 52.55158992265519, -1.522867764100474 52.57060059479718, -1.527155217045741 52.58273782614714, -1.560756756080808 52.59615623824214, -1.55445997435285 52.61473603579074, -1.571354167418836 52.63527162534101, -1.544516974272672 52.64460787184693, -1.551771403376678 52.66745510189901, -1.589645172820562 52.68726080363432, -1.597541032739515 52.70042176241762, -1.550041240746089 52.72031701566687, -1.544640234598874 52.7316944931258, -1.562492609449191 52.75058683248897, -1.552787032031152 52.76333294759459, -1.504980440616568 52.7676086582307, -1.493983710571125 52.759047366284626, -1.468445292008828 52.766877347287924, -1.455882031660309 52.77709465809274, -1.462778623791037 52.78686345453899, -1.442391043883322 52.792983271665975, -1.443561539800112 52.80274416427965, -1.417704446260124 52.80161549674417, -1.387936171328965 52.83309765111612, -1.394322829736422 52.83677286819804, -1.36121065469848 52.85518566661886, -1.351172728400559 52.8532894499618, -1.34486270852243 52.867532880292735, -1.325332481388368 52.86598173851084, -1.319306862539281 52.87286942262017, -1.267889066732532 52.87336864616689, -1.274363462380013 52.83612951386823, -1.261926745159716 52.81045332500876, -1.225886036053568 52.7916775592031, -1.197729349516526 52.78941154266695, -1.163275757746801 52.8065222242526, -1.130893059944295 52.805826907174826, -1.116941895194981 52.81957720278317, -1.074435288294018 52.82472671896165, -1.071738199796644 52.81401120728259, -1.036289279170267 52.81587727979766, -1.021933144212865 52.82205188392121, -0.982709006540495 52.820674860864194, -0.977074569269431 52.840737658874474, -0.959503884098984 52.84378172675993, -0.928121469649354 52.866083305135255, -0.940573903732927 52.87685612609735, -0.916924909001601 52.87893157871747, -0.857633561028614 52.905642315700035, -0.862893412374775 52.91311384088194, -0.824360719539844 52.94178960549947, -0.833908616949145 52.94588049893724, -0.820021872186797 52.96046442507876, -0.812850925422186 52.95746420745987, -0.796150022950588 52.976731498469015, -0.778278634287164 52.97692337518854, -0.778437323540755 52.959313816067606)))
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>