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/E31000005 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000005 geosparql: asWKT MULTIPOLYGON (((0.171626080190937 52.73803169704935, 0.153570713645166 52.68222317879114, 0.184716633421572 52.67789466179238, 0.183841792121232 52.6556620691652, 0.169925354556199 52.65043548920806, 0.219300102831529 52.621812417752395, 0.191597459321546 52.59896063089302, 0.218411913680483 52.57259912671784, 0.205631544270076 52.56556913154514, 0.217238473854267 52.56059399638578, 0.204708372672439 52.55465616095727, 0.205139890485467 52.547900878589736, 0.214625656765073 52.54910665671644, 0.20387175716927 52.545405052786435, 0.213145021702598 52.53817169592635, 0.205847385932635 52.53385081052031, 0.230591224805264 52.527909939267616, 0.206123354315164 52.51963511680959, 0.236319153587261 52.50729056462049, 0.24604091073621 52.49989129621915, 0.256476372671844 52.507714287086245, 0.309360668393015 52.513622268930156, 0.367062180779505 52.50117377991343, 0.380706424410714 52.47953945394966, 0.428529108202838 52.45465260983566, 0.429344111242675 52.43642666436505, 0.374777435342636 52.409728860493146, 0.40761705805849 52.36157379300807, 0.442501218710551 52.34883154648006, 0.424221647297608 52.32921635950197, 0.431376644727439 52.31582542564422, 0.457617988900954 52.31625092733786, 0.504768767220682 52.28471560597351, 0.49880294657524 52.27302138707092, 0.424206354862179 52.255871568989114, 0.382723070877934 52.293266245480766, 0.358997261958061 52.297542717038276, 0.340002525118452 52.26768786051491, 0.360892989102237 52.24942238392492, 0.342684111068708 52.242343341234594, 0.371248889183918 52.22655615523857, 0.421335044520399 52.23969131605407, 0.414517815807023 52.24786113299325, 0.426964815632343 52.25360276310634, 0.480337258107356 52.23268192187375, 0.494931507841318 52.23925801580111, 0.514484054124327 52.2267794025951, 0.512566877597926 52.21505043560914, 0.491332855190797 52.16510202729922, 0.470730341765576 52.16325884638767, 0.452191382119311 52.17320424150859, 0.435915815889954 52.15949508879995, 0.417276429997886 52.15930667922105, 0.418283019545705 52.134355628695886, 0.389589798177343 52.11747057675762, 0.38180382121313 52.10270128927502, 0.394996798234567 52.095968124559654, 0.404638275131961 52.06550237537014, 0.379612840809911 52.04956270963013, 0.389695384357276 52.03646658925456, 0.345959354831072 52.04971701499654, 0.324673997613606 52.07278328235088, 0.286011777098724 52.090407646258626, 0.276228973489826 52.09263829855216, 0.251573054386618 52.07678614121746, 0.235208015126753 52.08900004534739, 0.203459411750135 52.09267415035037, 0.183194375311396 52.07318345032597, 0.189922083436699 52.06020139125065, 0.16757028948233 52.05499980645188, 0.166396154892828 52.04819077600656, 0.151116966769271 52.05285179693177, 0.128135211193712 52.04732256659957, 0.119077527343092 52.05996258258431, 0.105736224916969 52.060261102048585, 0.092254349234459 52.02165398389318, 0.068127431741126 52.00578873403208, 0.040306397684818 52.05332728670775, 0.004082763622986 52.04979277896616, -0.01928047590246 52.06353557940505, -0.126567490629996 52.02092187089194, -0.133729853972881 52.046232847641186, -0.155121021336435 52.053061094799716, -0.147505480708306 52.06940310688426, -0.157280858481759 52.08054719535943, -0.144445022402714 52.138203752332615, -0.154352335985911 52.144407921359345, -0.171534722741528 52.1395025859768, -0.234804030866533 52.14472675328988, -0.216624311583909 52.15873553889973, -0.260694075195782 52.17640141685848, -0.24978513637842 52.18437102218585, -0.240722991474732 52.190193138774916, -0.261845175363318 52.20986691616521, -0.29628436573985 52.21048709027008, -0.285613634755858 52.23727706373837, -0.293208976769364 52.240516176126626, -0.335249400332413 52.242881802861284, -0.343468847008539 52.24187441604687, -0.34101082808857 52.230647488830414, -0.374375668353571 52.232998283529014, -0.382341185697938 52.27112565164838, -0.372175057429902 52.27349984822396, -0.375009955485427 52.280469373464285, -0.42176742668705 52.284947493601905, -0.435761099415093 52.296656875203325, -0.436088642390927 52.3144708411153, -0.465365745234521 52.32295327638489, -0.466656726301546 52.33892757156072, -0.483264179983424 52.34090329260082, -0.477682412765089 52.3489199868671, -0.498699826873909 52.36009583400581, -0.488518803051881 52.37402353710546, -0.49594625502214 52.379515525454565, -0.441509851646068 52.384996429581896, -0.417072819293212 52.411599106150334, -0.362408029592676 52.43353127326481, -0.370217023940135 52.439930266638775, -0.341590481031674 52.46694262261364, -0.359399568042757 52.489859064391005, -0.354345191807122 52.50649506761426, -0.413602627907267 52.525679608993805, -0.401283284262723 52.538684677824676, -0.419593775878401 52.55896195038251, -0.407290908178652 52.56405485014042, -0.415381391214649 52.57874263510323, -0.478814856794467 52.573645142416865, -0.4926648485053 52.58190025872977, -0.470921167972058 52.62355933342193, -0.494773440019685 52.64031406807582, -0.452694575760488 52.65427765933382, -0.405681253015967 52.64804609254818, -0.350222325958003 52.661614679970256, -0.335037013509256 52.674865967335386, -0.28924032551945 52.67027618301577, -0.260753897225616 52.65141797328819, -0.21250131988074 52.666679488425565, -0.192867800885329 52.65243850644255, -0.180020091881949 52.66056115394291, -0.14106198323183 52.651507419294276, -0.102195945115119 52.67220618988947, -0.087752491536766 52.66678608810526, -0.063713801221276 52.675233090025046, -0.031270670102446 52.66153273937681, 0.021500364138449 52.664887283881995, 0.048566413368883 52.68140165564112, 0.044149487733524 52.71438234508763, 0.063626632562149 52.72739150494566, 0.089011707169996 52.72363016146411, 0.132975322645615 52.73930447265453, 0.171626080190937 52.73803169704935)))
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>