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/administration/lonb/E09000022 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lonb/E09000022 geosparql: asWKT MULTIPOLYGON (((-0.0783066702400979 51.42060916539008, -0.0785486219003916 51.419847802791324, -0.0823459890866025 51.4197715516629, -0.0864257134312634 51.41930584141203, -0.0881904154118278 51.41992727067581, -0.0923078440349057 51.42235409081299, -0.0939189398459911 51.42279843426972, -0.1060549041514303 51.422577049264994, -0.1093737329588073 51.423157543342874, -0.1126855934642575 51.42324418562221, -0.1157151370453974 51.42057900334445, -0.1198466324954353 51.41880724223866, -0.1224810092779124 51.41502940726948, -0.1240743852145367 51.41460973439823, -0.1244675238224234 51.41336514565468, -0.1257860045062917 51.41263179065962, -0.1262599075329429 51.41293073811792, -0.1277517832415123 51.41231700473115, -0.1278881793912005 51.41200533985505, -0.1327145112619729 51.41234853625259, -0.1335724347798656 51.41257616689601, -0.13357801234717 51.41293415073794, -0.1340999748483554 51.410991075413314, -0.138102071590847 51.4118020729797, -0.1425822104288265 51.41334250277761, -0.1448699521651234 51.412388663897154, -0.1480904293100032 51.41287031208557, -0.1470833526220267 51.41380491370711, -0.144347472974366 51.415348012555526, -0.145009434473254 51.41579999365428, -0.1404054516283284 51.419249428561066, -0.1378519297405642 51.42110632706218, -0.1389221372628069 51.42457290217655, -0.13839852042909 51.430555468585965, -0.1352641316811377 51.43033483366367, -0.1364556536492933 51.43382852745987, -0.1378576387463008 51.433776191866514, -0.139110219781636 51.43481402747853, -0.1396481014650928 51.43531530976384, -0.1399729784520802 51.436881586023674, -0.1376836730641279 51.43858175292298, -0.1374772414214646 51.440191735026644, -0.1370113612154941 51.4402526556461, -0.1359040304920356 51.44200572976298, -0.1378851750180461 51.4416955071625, -0.1436207048022803 51.44183862104613, -0.145696449982244 51.44586960822148, -0.1447951666906554 51.4485422852168, -0.1433601930867311 51.44950514238138, -0.1423226832956914 51.45099138766034, -0.1477299709672781 51.45233950662541, -0.147378014608567 51.45296342588734, -0.1483408363148297 51.45730588586116, -0.1493905016229136 51.45936193131215, -0.1497026764278435 51.46132461019268, -0.1507317725668026 51.462859615904954, -0.1512314936445718 51.46588453757029, -0.1504703891421113 51.46597771683591, -0.1506186911572806 51.46761497454023, -0.1431004325992346 51.470519387742705, -0.1426768253535947 51.47006398788763, -0.1403426845215491 51.47159259585578, -0.1398668856406647 51.47132335030362, -0.1393162607056123 51.47151607834464, -0.1395020685597859 51.47179591876313, -0.1383491815638865 51.471962004504626, -0.1369179777185578 51.47309034967212, -0.1357871416998701 51.47271448379551, -0.1345577431114351 51.47344847176265, -0.1344618408230277 51.473965848577286, -0.1352305375829136 51.47428742264914, -0.1349529117977666 51.47470472682623, -0.1341116511224366 51.47527677105112, -0.1299475313747308 51.481182394127764, -0.1274965329091839 51.48202277009607, -0.1263636552392399 51.48446586376556, -0.1281717869818627 51.48473576226745, -0.128511786103984 51.48503385292497, -0.1284556192945552 51.48504873932729, -0.125550194853488 51.486918637029575, -0.1247333899197498 51.48783363579968, -0.1242063929817179 51.48782880303811, -0.1213476441418553 51.49437007359076, -0.119375797379688 51.503847185474925, -0.1183503357377348 51.50572552994914, -0.1170133404569481 51.506838874678586, -0.1154081340915627 51.50753431066072, -0.1114574961953147 51.508354727091856, -0.1108136525758489 51.50810335661994, -0.108931508409689 51.508439549323086, -0.1087996607886085 51.50770487129143, -0.1085064576857824 51.50775866735398, -0.1081755889134911 51.50690890218121, -0.1073636194228881 51.50706391388395, -0.1064656852137984 51.50498208345103, -0.1063955976976118 51.50337129554658, -0.1074580687271514 51.50301248402604, -0.1067516296758348 51.50222236926649, -0.1061368624832254 51.50252268831122, -0.1059476712370651 51.502045680001295, -0.108353683056774 51.500348097620666, -0.1102951678287885 51.49677782925605, -0.1114426363231403 51.49644741238121, -0.1108136235597528 51.49542293940377, -0.1048962439797804 51.49352712583721, -0.1039431062467433 51.491951503055624, -0.1031562235093011 51.49147390423831, -0.1084525574431909 51.485848286278554, -0.1063575938275584 51.48489003028113, -0.107222602406984 51.483654025152326, -0.1056357919955556 51.48295037344339, -0.1060437426018237 51.48269706232345, -0.1040469741531861 51.48090760388366, -0.1082459686261456 51.48029470020539, -0.0999976872230916 51.476872782873826, -0.100619648277804 51.47427673914963, -0.098917155810552 51.47193358338834, -0.0959975468133455 51.469880888953035, -0.0941056855075286 51.47074124368794, -0.0930803277571469 51.47212746761101, -0.0927177052497534 51.46977444867619, -0.0900797464477798 51.46615786890242, -0.0906671019994476 51.463294303662934, -0.0922118124388799 51.46112075096227, -0.0947296238998097 51.45901244367142, -0.0958371665369533 51.45740818125398, -0.1009383948111428 51.45415193002123, -0.1014254145154201 51.45195572463006, -0.1007609695821911 51.45031191658269, -0.0998087193638217 51.450196695308705, -0.0992533642049097 51.44908245304405, -0.0961081007377868 51.44674640431505, -0.0951406057616913 51.44554543443304, -0.0945073899482166 51.44340116801747, -0.0930027431563506 51.44142081557148, -0.0906653861297639 51.436669710466575, -0.0883196446999868 51.4294454159068, -0.0858904539466103 51.42850109448935, -0.0860740390670489 51.42782605835182, -0.0852507947762226 51.42735492462355, -0.0836831545116099 51.425008234965944, -0.083476664142914 51.42299862326633, -0.0817265366985654 51.42336744391381, -0.080896908622128 51.421848465060634, -0.0798563489952449 51.422140772178736, -0.0789309167970845 51.421570825941004, -0.0792228749657622 51.42084983798796, -0.0783066702400979 51.42060916539008)))
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>