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/E31000020 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000020 geosparql: asWKT MULTIPOLYGON (((-0.374927434386341 54.15411315048256, -0.346397147745489 54.146872939197586, -0.323841920503248 54.15029693032587, -0.304236409769382 54.13626184831634, -0.265419785561993 54.14055850582588, -0.229746607979519 54.13244035245187, -0.212689235880885 54.15764715084124, -0.212542228305954 54.15759401675212, -0.164366219570562 54.145773391478166, -0.096516360426927 54.129081592198595, -0.079369056519928 54.11848432549762, -0.076392928343305 54.116431777858075, -0.104726319257285 54.104125010124264, -0.166454627325379 54.0984858077961, -0.16797603422445 54.098346398951854, -0.172298497541195 54.09394182100349, -0.193337385798217 54.08012283294358, -0.194396381179299 54.07847908196911, -0.198423990992467 54.07791863830106, -0.212264142667374 54.05755941070836, -0.212033418013202 54.02271133199614, -0.211931566427823 54.00734154500544, -0.173560606875488 53.93651058785591, -0.156369313847286 53.90469447684783, -0.155496520947359 53.9038518576374, -0.154805530259637 53.90256166507217, -0.122580194961037 53.872044329263964, -0.090571598854472 53.84105950616776, -0.044274362100651 53.79614775954668, -0.03250355824645 53.786462400371164, -0.02871785499347 53.78285654842111, 0.018417353829728 53.74449892792065, 0.114087192869721 53.66537518780908, 0.117198267581495 53.66079936816459, 0.119277791141742 53.65774020549414, 0.122426613612824 53.65362122651261, 0.147237042202624 53.606850151005354, 0.148220538941629 53.60473253094999, 0.146211524356476 53.600560266931666, 0.12005773704667 53.57977425134707, 0.112904665270158 53.574895145134995, 0.109488373017565 53.57256428456936, 0.109647703084448 53.5729216114956, 0.112943975506772 53.57568443651491, 0.146278686189572 53.60359771492255, 0.142233525288605 53.611686604598326, 0.11548448222901 53.62655378718124, 0.105095658580949 53.63232359071284, 0.0795772770017 53.64101259556875, 0.034483478878276 53.64921113067878, -0.054092796385189 53.62901082571369, -0.11352644169341 53.639451339481305, -0.150968149252634 53.662217767782636, -0.184563480990974 53.68261479642248, -0.227255019720462 53.708492913354576, -0.23694041489261 53.72670519581303, -0.244392961996949 53.73083180675094, -0.25168156626467 53.732850923971334, -0.286747840981483 53.742556202406156, -0.332635087939626 53.73828959190882, -0.419107722663599 53.71959763091062, -0.419207522157542 53.719576009471396, -0.447459502774962 53.71386408005004, -0.473388808621614 53.71727529342236, -0.486205083338154 53.7160377477136, -0.553164246837604 53.70954862672882, -0.583252746686932 53.726568002081905, -0.624668010247696 53.72907449644582, -0.672997752764456 53.72134038748372, -0.695979876051026 53.70436108106775, -0.725134190307583 53.70685787561739, -0.698498561956223 53.697653997484025, -0.698496747864754 53.692868465066155, -0.698493664917614 53.68461033659966, -0.685346882726092 53.67674699953846, -0.69421914437165 53.6952245634131, -0.613006505217119 53.71455920949758, -0.586254443555949 53.69333874808708, -0.523512676219688 53.67699282866724, -0.487082668877325 53.691582030523634, -0.47049297528103 53.69821868937695, -0.393535085440686 53.69687485963115, -0.387650839061955 53.70217957038266, -0.294218575374456 53.71414624630956, -0.249549854183251 53.67659264302259, -0.24880093527232 53.67566435038215, -0.246090168656889 53.67368063612519, -0.233964204100716 53.66347032759572, -0.204288761169391 53.63845719369266, -0.204092433016163 53.63836066780513, -0.186826920950658 53.62986899945417, -0.079457772139456 53.57693014946351, -0.071089213284981 53.585097143223614, -0.06808381988898 53.58434873686712, 0.001295513910938 53.53953242171676, 0.014745367624692 53.528152109518686, -0.014578806097501 53.51540535171802, -0.06504539851689 53.51873965390258, -0.075261990310222 53.48933573601064, -0.095488436742084 53.485988992639086, -0.089803721970285 53.477682411374836, -0.107820618856906 53.46986275379333, -0.082209333018789 53.451151002457216, -0.120343702269996 53.433564918511976, -0.131879258513422 53.43593939338425, -0.149227734718838 53.44669966146467, -0.153680003393742 53.465677754068935, -0.181804705728418 53.46864940834718, -0.188565215789534 53.48453805368136, -0.210604964140916 53.48628847125249, -0.204086436768562 53.51176733894425, -0.210589565682469 53.531706461130476, -0.219882515231679 53.532606486926284, -0.189340877929046 53.56592258380646, -0.195185361406784 53.57161935375637, -0.222558887819449 53.56801692352454, -0.234668661679826 53.58625041467544, -0.251395541377558 53.58465307318547, -0.248476035562676 53.59366368787328, -0.292115115661398 53.61326742742109, -0.308555234757841 53.614328754084745, -0.300743127454613 53.59528362626519, -0.335938807643433 53.55862658749664, -0.416962961082462 53.563214685183056, -0.429001032632917 53.57452471039956, -0.467018359531686 53.548960688560456, -0.490926917033637 53.54587491903454, -0.501229113513619 53.537461212740354, -0.430664736522151 53.54633715171035, -0.408145067056804 53.532108863838495, -0.405074512906814 53.51761689950978, -0.488383645947229 53.50486022064238, -0.486629991388688 53.48047016298241, -0.471749453417602 53.4748728969829, -0.551788617870756 53.45951998247522, -0.629752663227097 53.458218987665866, -0.624491091143043 53.51283921009218, -0.739591672395146 53.519935944339885, -0.752113847264725 53.50053060388587, -0.768109594384733 53.498925603585874, -0.771568231714181 53.4792015567756, -0.784388764354131 53.476669211827904, -0.784364861826877 53.463379542696714, -0.797483337847422 53.45506444301739, -0.871919269801193 53.46631079917475, -0.916249007589156 53.460295685816625, -0.920246781135393 53.46550764577759, -0.900470613932839 53.47515586339263, -0.935564612144213 53.50251652552992, -0.932094150234116 53.51067181976249, -0.950009074159217 53.51365743061861, -0.943715813695638 53.53064301484561, -0.892295368819983 53.537466960027025, -0.901265898426184 53.54790842054258, -0.890995194878671 53.56655897848517, -0.901117794685414 53.56872422280914, -0.897926437897541 53.58327743390327, -0.865338714314226 53.6377082284128, -0.946844629609817 53.65914176376069, -1.048662623138085 53.65605747536973, -1.103570409665621 53.66955674926559, -1.08104573714031 53.68461467443513, -1.074934142066406 53.70399631148193, -1.061658436860214 53.70676588244093, -1.038925921244741 53.69388229517952, -0.980327818098405 53.69694227183684, -0.980486415712388 53.705039602678866, -0.962649902270268 53.700795900884636, -0.957714748967526 53.71483548197413, -0.903739065144068 53.71835939114577, -0.910951215642263 53.73267025426196, -0.960737344801002 53.73601629138228, -0.973605981945577 53.74987690720808, -0.928253541573558 53.765598441641124, -0.934498999434778 53.80177718635231, -0.920106064126266 53.81609299029991, -0.940610973077519 53.823518462740935, -0.948227076365044 53.86160956354346, -0.923517738831214 53.88076644751687, -0.920843770306317 53.890619634934396, -0.949519680607771 53.89391480087779, -0.921600374073461 53.92141640037969, -0.921212158946514 53.96042222127013, -0.934105987615522 53.96845641889121, -0.92529497952916 53.99151837147604, -0.893902653921969 53.99953516625115, -0.878444283613686 54.01718450974294, -0.800704620480998 54.024118615046284, -0.799190997723504 54.01905483522178, -0.734257289852277 54.03025877037758, -0.730489248105211 54.012700831529216, -0.683501617116915 54.00880185031158, -0.687039060799855 54.03076765714828, -0.659484328725116 54.037169822396315, -0.644653942610735 54.05511309431874, -0.660316920382482 54.06310004950256, -0.615523431555483 54.07049370542924, -0.563137233978288 54.093999523088364, -0.524612332784598 54.085474743380466, -0.465942444362073 54.10763297352615, -0.454351117834446 54.116762508113226, -0.458539653143794 54.125973605012526, -0.427093840480658 54.13744255768459, -0.433168617725966 54.16407271211461, -0.418250103404332 54.17406341302339, -0.390747224508886 54.17652070204052, -0.374927434386341 54.15411315048256)))
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>