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/E31000022 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000022 geosparql: asWKT MULTIPOLYGON (((0.547003852561244 51.48704544871834, 0.553938350646188 51.48142282472923, 0.574545918614332 51.48426566911871, 0.582488370860378 51.47964730273405, 0.585779712207702 51.48443949127158, 0.59096593055939 51.48279302026008, 0.61523622380087 51.475083243375806, 0.659983927632027 51.47767695661556, 0.671239651467981 51.47225505603048, 0.699735904283791 51.47273375553459, 0.72038460840918 51.45973702349092, 0.72325917034656 51.44352606435867, 0.713429342393362 51.43568456317954, 0.677888593451363 51.43317594501388, 0.670371369475839 51.448509347838474, 0.667222777373549 51.4438790039682, 0.656750680151965 51.449276633110564, 0.635814651859527 51.44622172564511, 0.618295773322882 51.4286832640012, 0.625214918075312 51.4236691809967, 0.610664657113971 51.41737281154879, 0.587194931023324 51.41614695455605, 0.534985475882821 51.41340323682918, 0.521181142012308 51.393046712265644, 0.53668432546629 51.410211444011736, 0.560969207654003 51.394814073207925, 0.585645330537551 51.3886840627257, 0.594636540103441 51.386448788540264, 0.616045956287433 51.37809287362662, 0.619230170128701 51.38848761120659, 0.632410475895486 51.38900167805392, 0.634639624407033 51.38908844665832, 0.639938604914345 51.395086853410234, 0.659645817855544 51.39183511954403, 0.672691579484383 51.375957108826746, 0.687362387205697 51.39186560655027, 0.703063774961223 51.39259908092435, 0.695284215603942 51.37982142073473, 0.713539475552824 51.38395018973139, 0.71865336563312 51.38937921859877, 0.701778931247084 51.395727082025466, 0.695894047062838 51.40728328129598, 0.705532945414247 51.40842102092328, 0.696260519045095 51.41969461636142, 0.727977385318634 51.423589046193065, 0.731171115075706 51.41898260391334, 0.716721726451422 51.41537344514445, 0.725927569423872 51.39987980552937, 0.763657291094081 51.38289754821612, 0.75595245119038 51.35362351165447, 0.76689190269382 51.36258108589615, 0.814325834852255 51.35829603119478, 0.865926073080287 51.35590784607221, 0.87097580083568 51.35407701273253, 0.897629976508965 51.344407388630806, 0.895647470282435 51.33703787363968, 0.904374145712054 51.34302247569938, 0.950244436407435 51.34576148375622, 0.950302380293989 51.34576716373732, 1.011521950636781 51.35175121106272, 1.033149712978038 51.3655622010868, 1.098618093432731 51.37244681413855, 1.125201243254118 51.373915294073726, 1.138523453023158 51.3734634107334, 1.165122540260564 51.37610905750067, 1.22423007883496 51.3793319157253, 1.22489487023518 51.37928032726282, 1.255730076415258 51.376883066090144, 1.288007788566937 51.38236677936848, 1.308510490579903 51.382493193461464, 1.314634574528481 51.38196947774734, 1.332960979571265 51.38503973876409, 1.398205878298627 51.39401462655804, 1.424924779568935 51.39378782349506, 1.447441801955652 51.37891246854845, 1.449585118495545 51.37749583263192, 1.446274403753257 51.36337654739954, 1.444127940723916 51.35421698915758, 1.424681810292493 51.3259922198337, 1.423194761770871 51.331372553701655, 1.413984452050132 51.323926417905525, 1.377466954290155 51.32969046726046, 1.365882822696625 51.32500502147353, 1.363153778944259 51.313570587398196, 1.363399278216437 51.31351240646286, 1.370643621227 51.31179526906971, 1.379923953929672 51.29030789483116, 1.40112241088329 51.241151271484696, 1.403910205192255 51.23337425798988, 1.402680926872322 51.20393527215376, 1.39837717744987 51.162305882946185, 1.379578565345945 51.14217798013397, 1.353811990760356 51.133449427150516, 1.342716981350983 51.13044301112445, 1.342774693747639 51.12970770525227, 1.323962682188918 51.12442369911485, 1.31741794170092 51.123108532549296, 1.317696696222105 51.12266272386706, 1.315731264717676 51.12211026610437, 1.320914268708968 51.11751624697315, 1.323048718251479 51.114101537192376, 1.313616533699731 51.114755269194205, 1.327841472478022 51.11137448647157, 1.30316476993546 51.11310185601176, 1.300771510051328 51.11264775464122, 1.299844821128209 51.112691230444995, 1.298402280406147 51.11219815491739, 1.234995019109448 51.10014429771079, 1.220856035368755 51.09947117910655, 1.217285035667839 51.09745001320179, 1.185719579454434 51.07957147104219, 1.194951340579569 51.075955240612636, 1.138887132494627 51.070088834696634, 1.075288814715418 51.06340002806888, 1.068355617414155 51.059914738202515, 1.061615711344205 51.05905658991693, 1.021373109668937 51.03627174366341, 0.994244451617672 51.02259981797116, 0.976349911834349 50.99021036746203, 0.973171280372121 50.98613226854597, 0.973297080385456 50.98467963097402, 0.964139173894204 50.968079649262506, 0.97311532165428 50.94156108016076, 0.978372869737423 50.926014882473815, 0.979199260017107 50.916452599597974, 0.975749800610504 50.913241789686275, 0.910859137141898 50.91789548808511, 0.854995576166642 50.92369703320031, 0.867891392847235 50.9332622897419, 0.855967982681082 50.95312860158269, 0.841401389026136 50.957608823737175, 0.812941759430859 50.94199957020854, 0.784327869089258 50.977229681350025, 0.777134941240379 50.97542834500679, 0.77895671604856 50.98949201927848, 0.740611388739665 51.00067670281243, 0.706770614525536 50.99360181819107, 0.676955930375848 51.003298780075056, 0.661355100182509 51.017787294531736, 0.605390836399549 51.01206996994109, 0.568381162158347 51.00381468169886, 0.541906636582485 51.01100643640808, 0.537600390884653 51.02167357188208, 0.472315371495058 51.03044158512259, 0.463267149806865 51.05478701157114, 0.41826687317312 51.062626965523926, 0.396473814042706 51.08309614602145, 0.37390355307443 51.088464717765596, 0.350820002040407 51.0840683281607, 0.358960090190952 51.10447855575473, 0.334703424301417 51.10556456466865, 0.325177409034887 51.12291711683715, 0.273935056034107 51.12007870089949, 0.275670548390623 51.11235542986929, 0.244534368873021 51.114880052008075, 0.226284335187785 51.124467906737095, 0.171628370376787 51.11541024852635, 0.151200738565452 51.123829856520565, 0.160747956682772 51.13731925961118, 0.133117097332669 51.14727851383109, 0.050016541019525 51.14265001100431, 0.052600374954082 51.18062401270012, 0.033598963925881 51.21433796703667, 0.05824284259376 51.2477783210246, 0.042396509842699 51.292673041976705, 0.085693094411535 51.29308422183766, 0.085029310998276 51.316023199667015, 0.117903924763801 51.329663223087906, 0.118456314480145 51.34414777764578, 0.136958120937376 51.344174600173446, 0.152057751435564 51.36969370000501, 0.147741041792491 51.3928009971624, 0.162384161126943 51.39249029737674, 0.148902757741464 51.40848297138232, 0.15293244569828 51.408708476715006, 0.1558750520598 51.43087657770287, 0.164328183364185 51.42858495574797, 0.172854359600541 51.4432451813196, 0.203352900572067 51.45432847161008, 0.221175232114655 51.47880206108825, 0.274292516885507 51.45377357753935, 0.301807750067424 51.46125798484382, 0.315246148590497 51.464910101386366, 0.315395584291979 51.46495070366931, 0.325163834057653 51.45033536140554, 0.38222205175809 51.44329136676841, 0.458519359872778 51.45526285980415, 0.456756509892388 51.4586924838641, 0.454309382253846 51.46345249299076, 0.467616984915798 51.46420103925919, 0.457874809519394 51.46694638343063, 0.468742151074754 51.48277067179615, 0.547003852561244 51.48704544871834)), ((0.902017957948962 51.41648964098605, 0.951023524462421 51.373478759900976, 0.897166315446385 51.35433514404516, 0.871407522203681 51.360982247466374, 0.858343045625198 51.364350710747374, 0.839629463530773 51.363553907046146, 0.804615787801519 51.370673698310405, 0.766182972669934 51.36976961375352, 0.764264898043588 51.38823202846076, 0.731031742628413 51.40137367697324, 0.721502901084382 51.41447034968832, 0.732133567591569 51.409025295941916, 0.741097267255046 51.413458233282995, 0.735425145333561 51.42359088789474, 0.743909982706578 51.447069328975836, 0.789380442698428 51.43970061136182, 0.791558200719096 51.43929186193854, 0.823863860105182 51.42584169683427, 0.875088366225767 51.41971853924106, 0.902017957948962 51.41648964098605)), ((0.690537507053292 51.412160592326686, 0.695441431632048 51.397657473116595, 0.672639136264905 51.398404616454506, 0.665584010366308 51.40745490907513, 0.690537507053292 51.412160592326686)), ((0.684311301617644 51.42295852343732, 0.688333398068209 51.41533478728333, 0.659585570891387 51.41857367689068, 0.664738302368651 51.423699237535786, 0.684311301617644 51.42295852343732)), ((0.582631462258857 51.403261549538385, 0.560246012661979 51.40322898126875, 0.5639419327256 51.40806963683428, 0.582631462258857 51.403261549538385)))
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>