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/E09000029 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lonb/E09000029 geosparql: asWKT MULTIPOLYGON (((-0.1343790356556913 51.39088611331312, -0.1326347232836443 51.39012814994778, -0.133260552741183 51.38954909049563, -0.1294935016421001 51.387185115956555, -0.1306635907219332 51.38626315411989, -0.1287612620495758 51.38565184646107, -0.1295349782657934 51.38528742477479, -0.1286572066216722 51.382494650259396, -0.130302305279217 51.382221452916454, -0.1280790097979168 51.38049886466057, -0.1269592591961393 51.37733711911248, -0.1258330749125922 51.37560424029328, -0.1268654362154574 51.37548230227873, -0.1266733373983649 51.374909076604645, -0.1278493667418627 51.37474978009544, -0.12474433641204 51.373661489817195, -0.1247735288302583 51.3729470603023, -0.1233060199853279 51.37109802200416, -0.1220988198010542 51.366259415512424, -0.1220942738690685 51.36580884639323, -0.1240641736199374 51.36527205022577, -0.1230644774362995 51.36505825390308, -0.1223707529252499 51.36452822482619, -0.1213021819554357 51.3647332394349, -0.1209280845686901 51.363310839560576, -0.1215813093367093 51.36212616411335, -0.1213804964811154 51.3610654302968, -0.1220533782202092 51.3609800249217, -0.1218397451074865 51.35998642294778, -0.1229284183654103 51.359918466036746, -0.1218602969379333 51.35906418185559, -0.1233384633110139 51.358917867994975, -0.1234568059238637 51.359151799889865, -0.1247151720062804 51.35886619569833, -0.1245738073929785 51.35835490938273, -0.1241963577588069 51.35743069987845, -0.1214292916321145 51.35773077109515, -0.120177617297516 51.353045240334225, -0.1191151036887012 51.35314334789221, -0.1169191637207553 51.34575463376701, -0.125924909736149 51.345239013708216, -0.1268565964446108 51.34485736003882, -0.1273473948912313 51.34718800088664, -0.1275566303117747 51.34744585782908, -0.1283720416824217 51.347451697694645, -0.1288689133317653 51.34727264090961, -0.1289930765296104 51.34658750452002, -0.1314313218906914 51.34602309644275, -0.1311263655413819 51.34547234784973, -0.1328925872327051 51.34543668526267, -0.1325137908653583 51.34429932359795, -0.1362728240447788 51.344406844286766, -0.1363505705810104 51.3447929510282, -0.1367311291356248 51.34475675131831, -0.1415569650911995 51.343414413102046, -0.1445955228968425 51.342092035079176, -0.1434641301857392 51.340562500278544, -0.1443242209360367 51.34020645489692, -0.1445266233424012 51.339494763699506, -0.1475474834045659 51.33878183296214, -0.1456171186904225 51.33243119450618, -0.1451720739512217 51.33154283935759, -0.1440675330769158 51.33067010493767, -0.1493305177538352 51.32876602070342, -0.1444548821803804 51.32648115357842, -0.1442726142875048 51.325909905965446, -0.1455855267196248 51.32350083428388, -0.1479563720482963 51.32268491412488, -0.1490373333438583 51.32278839949714, -0.1505948877506665 51.32217272617409, -0.1520893840165315 51.32226823946707, -0.1527313009062327 51.32300854987155, -0.1565688595951704 51.32151057247883, -0.158660127842927 51.323977832903246, -0.1606257493192288 51.32324347798662, -0.1642125704385644 51.32604247941789, -0.1635927662154058 51.32621535249135, -0.1643876388545347 51.32812797485416, -0.164007653215098 51.32818944512085, -0.1639961177890098 51.32858492129374, -0.1623159705736238 51.32889129558807, -0.163102146606653 51.33026608781234, -0.1700912563872956 51.32947621427576, -0.1699198188587715 51.33024776707349, -0.1728889643877874 51.33001534120544, -0.1741644147739086 51.333213338824685, -0.174691532476304 51.33317022198288, -0.1750450610475744 51.33381151357101, -0.1820212621282225 51.33785346053648, -0.1873829186647228 51.34078364190428, -0.1932544379586963 51.3426270718786, -0.1960726441656961 51.34333146230068, -0.1962922994370035 51.343040778061194, -0.1967154802866515 51.343159670952616, -0.196566367391101 51.343447845043144, -0.1973444932448908 51.34359656305624, -0.1985827262230313 51.342300809735036, -0.1995825393325068 51.34188546624914, -0.201224439091157 51.33988558199951, -0.2023233805922825 51.340090346749996, -0.213055935628746 51.335542418728494, -0.2119310923995994 51.33330946094689, -0.2141204027289466 51.330351946426426, -0.2161087051610688 51.32982827829826, -0.2209676642114777 51.32986442793901, -0.2298477295081488 51.33652398208263, -0.2268519080974456 51.337889660758655, -0.2241156273206455 51.34004241418494, -0.2232861863001882 51.33988230821383, -0.2223018303663961 51.3404617969775, -0.2227254485197162 51.34083061519625, -0.2218110067275772 51.34134643248302, -0.2172895129766784 51.34338830510415, -0.2178025597313254 51.34563257501694, -0.2202105860003946 51.35008097808433, -0.2204459245692201 51.351420837069085, -0.2212870219398496 51.351171911527125, -0.2221169020054047 51.351325743922345, -0.2219998953488124 51.353531658388704, -0.2227614143954521 51.35708718671635, -0.2240828165505609 51.359275358635976, -0.2268977963764912 51.362594962144335, -0.2332160101555986 51.36601133971406, -0.2338442410102199 51.36532480328859, -0.2368043983919492 51.366798267556455, -0.2378493314081374 51.367008264592556, -0.2389419929675823 51.36683581384017, -0.2409153849753973 51.36703815940347, -0.2411748591820891 51.36626333916481, -0.2454292703070434 51.366846845500724, -0.2445621816168343 51.37047229733295, -0.2452075450820052 51.377192200071555, -0.2450542738236606 51.38003515092193, -0.2441747217150563 51.38349220479264, -0.2429314862138141 51.382933179078016, -0.2416203058932877 51.38452496721664, -0.2387446418848089 51.38609503267797, -0.2397069381799387 51.389294649547764, -0.2346573097105608 51.390538773673256, -0.233928273914591 51.387709512047685, -0.2277423089213426 51.3839543903447, -0.2181363002859109 51.38015047737969, -0.212985650073949 51.38481112996298, -0.2133717844248612 51.38500679743894, -0.2097929956875421 51.38825331340161, -0.2050283022610673 51.3860923037607, -0.2035179892944871 51.38722563584932, -0.2005053219683426 51.3848854174531, -0.1939507854512469 51.387871752825944, -0.1936037208517694 51.387669430205285, -0.1932007561965685 51.38786648277859, -0.1904694966194799 51.38620288880607, -0.1884115140439021 51.385435521560446, -0.1792646187803134 51.38983507204357, -0.1748676076570228 51.39341851894553, -0.1728714699223599 51.392650045458126, -0.1711440398309557 51.392426123765446, -0.1676090487554752 51.390060718558615, -0.1664552640541487 51.389692865445184, -0.1652904957244479 51.38797946439184, -0.1617702999766086 51.38813205075012, -0.1609865755210943 51.387820293611, -0.1597036652899367 51.388594244999794, -0.1582824529008829 51.38883892023818, -0.1578963538836605 51.38929062572119, -0.14437842313706 51.390679809318875, -0.1431837173419076 51.390401878734814, -0.1419037786625687 51.38935554770823, -0.1343790356556913 51.39088611331312)))
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>