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/E31000046 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/fire-authority-area/E31000046 geosparql: asWKT MULTIPOLYGON (((-0.011918663354053 51.68087781020112, -0.012259675900707 51.64622869181026, 0.02271955430692 51.64111548839475, 0.021819047946785 51.62883278161117, 0.07283224061617 51.60468737920431, 0.138184248118254 51.623545391552014, 0.200311585189964 51.62493575219259, 0.224087741654669 51.63173775697778, 0.252194325699726 51.61776940040891, 0.264561978259548 51.60832065635737, 0.254008712916052 51.601598196245156, 0.269878888119098 51.59957478804097, 0.290289746586742 51.56429938776991, 0.313035091181996 51.56581812736375, 0.33402422956516 51.540503799226904, 0.265347284687935 51.53215026048795, 0.263682936277997 51.517869787519814, 0.253834330818098 51.517885866999684, 0.24896478680252 51.52867402515079, 0.237176020728662 51.519334428936055, 0.241919331782138 51.507960122304915, 0.22659729752429 51.506563238152054, 0.229965362154619 51.49936591412003, 0.214156940258888 51.49603960530885, 0.211730547880614 51.48958785137109, 0.210965054752319 51.48989715973232, 0.187593967939394 51.48790104937403, 0.181634616084128 51.49863477538973, 0.175897608070062 51.50896313886182, 0.160486299816181 51.51228082734291, 0.12717333246592 51.51944387845136, 0.09814452188142 51.51495820744901, 0.086262303904967 51.51311965222895, 0.071589312507483 51.500630201707054, 0.070007325941829 51.49928316067813, 0.024441555271941 51.498307277894504, 0.01798512829843 51.501565147966815, 0.015709305311783 51.5027133361427, 0.005396988216263 51.507914844728134, 0.004562508594212 51.508335658465235, -0.006927750349697 51.50453418553016, -0.006285079158451 51.50198038796113, -0.003228592209508 51.489831128889676, -0.015327005263655 51.4860247908448, -0.017123714814994 51.48689702355879, -0.026110995608137 51.491259108529995, -0.029472779045773 51.50237222669351, -0.031245035031651 51.508228646566025, -0.045493408113905 51.50939493078412, -0.061009624707167 51.502898705952354, -0.061082868151109 51.502868030940796, -0.061206785246657 51.50290196562371, -0.073997993601016 51.506403807558854, -0.074662188156064 51.50546070963565, -0.075340960095463 51.50449686690607, -0.070696033963472 51.50305845942422, -0.062953938728732 51.50066037480983, -0.059919205476286 51.50167997666396, -0.059865938492857 51.50166632646692, -0.044340682087202 51.50691204322309, -0.033412423895116 51.505657209352364, -0.033037245437992 51.50108534553765, -0.032376079005795 51.49302643426659, -0.032342687982075 51.49299739753224, -0.022287990955825 51.48425174192099, -0.01837604172657 51.48084795614282, -0.017858389494392 51.48321867142656, -0.002999189599418 51.48714393235946, -0.002927957254513 51.48715560774464, 0.001987695943539 51.4884607241544, -0.002386212754447 51.501914006948354, -0.00254909762763 51.50241486377039, 0.001138062908256 51.504134725116764, 0.002742790902899 51.504883164208664, 0.008211263785081 51.501732922797615, 0.015480809923589 51.49754415507442, 0.021603275261881 51.494015432648936, 0.057805639778367 51.49405461234528, 0.076234514944035 51.495890700432746, 0.081731477492194 51.50045037221852, 0.090528933948609 51.507745632630474, 0.092050662850769 51.50900721180906, 0.093778622928589 51.50921234272034, 0.118553823220597 51.51215038094853, 0.127169104719583 51.5131707524231, 0.132314895156457 51.51188407660967, 0.163275378687997 51.50413695826597, 0.166826549585043 51.503247644978856, 0.169205697080085 51.498865182400486, 0.17777828540831 51.483066441063556, 0.217626609993264 51.48047231371688, 0.221175232114655 51.47880206108825, 0.203352900572067 51.45432847161008, 0.172854359600541 51.4432451813196, 0.164328183364185 51.42858495574797, 0.1558750520598 51.43087657770287, 0.15293244569828 51.408708476715006, 0.148902757741464 51.40848297138232, 0.162384161126943 51.39249029737674, 0.147741041792491 51.3928009971624, 0.152057751435564 51.36969370000501, 0.136958120937376 51.344174600173446, 0.118456314480145 51.34414777764578, 0.117903924763801 51.329663223087906, 0.085029310998276 51.316023199667015, 0.085693094411535 51.29308422183766, 0.042396509842699 51.292673041976705, 0.032909430389583 51.30752090674476, 0.015009389435739 51.29178606442179, 0.002294731910666 51.32913884481184, -0.037892258494831 51.33870447923714, -0.05130706755093 51.32244788992419, -0.078923856601028 51.3197692432985, -0.091167927489275 51.301472534847676, -0.12429284685417 51.28675865342421, -0.137313505245197 51.300780899804565, -0.15531768797215 51.301274389905714, -0.156543155925695 51.32150858115214, -0.197319328049839 51.3435951551575, -0.220942470597896 51.329863062928595, -0.229822670020339 51.33652279985086, -0.217264414633293 51.34338708611452, -0.222736415969413 51.357086067660916, -0.245404830145622 51.36684543510895, -0.245030242343404 51.38003396084405, -0.26114854946343 51.37959979647162, -0.28543782213904 51.364249169396054, -0.306191984387053 51.33508440703612, -0.330655540991551 51.32900963431212, -0.330510134081141 51.34841943043786, -0.307365431315062 51.378383540403924, -0.317697868575985 51.39366707467949, -0.327817837307609 51.39183713703884, -0.359139319796798 51.411903156655704, -0.38335001437848 51.40853829042601, -0.391341958252474 51.42232610568175, -0.456467546997876 51.438106675043954, -0.458640438708173 51.45631541944098, -0.509701389972888 51.46917594308233, -0.490024718859114 51.49474762977613, -0.483162277771747 51.50712771126126, -0.495487333041928 51.5385452254679, -0.476620641945679 51.559188832343644, -0.50059587434753 51.59968989502356, -0.496846256996453 51.63173303114673, -0.457130743086963 51.61229388455849, -0.440575290324786 51.62007323389717, -0.404050160106153 51.61318392606387, -0.362621245263213 51.62350481207758, -0.316672233949861 51.640535562181455, -0.304458819092916 51.63635086429082, -0.257332645526686 51.64183184339894, -0.250582578419609 51.6560573469005, -0.21213501820142 51.66135352297804, -0.203352917555039 51.67012649451102, -0.191066686792294 51.663896700832844, -0.182085364943244 51.66860405314412, -0.163493260861795 51.688115074316435, -0.105779128699168 51.69187563977254, -0.011918663354053 51.68087781020112)))
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>