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/par/E04001298 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04001298 geosparql: asWKT MULTIPOLYGON (((-1.338400672322991 50.735664760853936, -1.3345400533554508 50.73079651385017, -1.3326103222250303 50.730688338858116, -1.3317110464615023 50.72826320893611, -1.3352516706916617 50.72676550255878, -1.3353675941562684 50.72538037099426, -1.3427898062838104 50.72580024312921, -1.345532802036174 50.726809415961384, -1.351470267810949 50.72211065019096, -1.3552011551199579 50.72194793806379, -1.3576531888998111 50.72030322788688, -1.3609988656884742 50.72064180086642, -1.3615651074304655 50.71868897071546, -1.359065147921661 50.7180457235484, -1.3584461328316357 50.71627971839117, -1.359631112935523 50.71299667675498, -1.355926722246588 50.71365698215755, -1.3533145216921658 50.70915148330732, -1.35672997513577 50.70919379724591, -1.357919091932587 50.70840450437982, -1.3591948228515915 50.70302667011664, -1.3577811871892418 50.69849823223082, -1.3639551852547722 50.69751774287679, -1.365680527563179 50.696621586080425, -1.3663562168477863 50.694183736246025, -1.3659349743246523 50.69119765773219, -1.3662617120930227 50.685868559545945, -1.3651684895587024 50.684433671170105, -1.3664856078566272 50.68322681972149, -1.3664725684921908 50.681359865496, -1.36852416242991 50.680888988771784, -1.3700677343458227 50.67850798694169, -1.3725988758184775 50.679103475521956, -1.3736916943733886 50.6774978625022, -1.3736217216562712 50.67446513767118, -1.3750596133076984 50.67190632649235, -1.3760139382458263 50.671866478180185, -1.3791815318127973 50.66839600950653, -1.3810028718577836 50.66461701567612, -1.3849441590302431 50.662611799969326, -1.3869755869522813 50.66209193355233, -1.3917850061861363 50.662171114254456, -1.406839876043871 50.661755077150296, -1.409090246800415 50.6600021107725, -1.4253100115743997 50.660859379637884, -1.4327827585345891 50.663574117733084, -1.4358833898582695 50.661988431323415, -1.4376268393794605 50.65899950075148, -1.445143254266458 50.66128918440786, -1.4450479508725675 50.66349112217509, -1.442916919251801 50.66410686125115, -1.4426857747009407 50.66845025756005, -1.4451922312524683 50.67081566830742, -1.4391902258455147 50.671335459587524, -1.437382220248994 50.67484293140509, -1.4308698183094573 50.67866738258931, -1.426672677895005 50.678720509713216, -1.42504444232487 50.68131769240426, -1.420403665233264 50.684272172561705, -1.4185911516021852 50.68443938245673, -1.4158358634327737 50.686662997580974, -1.41593101344719 50.68869226022319, -1.4131389540136312 50.692017241874495, -1.4096520574997724 50.69155804365771, -1.4065071203787551 50.6918289051908, -1.4022237906599166 50.693110025449364, -1.4046250262850875 50.69601534351388, -1.408084473406191 50.698905318971654, -1.4047070271819944 50.70173430983148, -1.4053897809928562 50.704406876599016, -1.4070893720127808 50.70607383305626, -1.4073751588440597 50.70812025888052, -1.407053780476182 50.70968517072722, -1.4097302660682747 50.710160119148604, -1.4119244036651033 50.71161008747888, -1.4123214501599075 50.71406713434792, -1.4108747281651992 50.71456431097603, -1.4099187124771162 50.71659094056981, -1.4068350153012223 50.71737651153264, -1.4038984317788066 50.71962318811207, -1.4028548073456482 50.71802970299767, -1.3991141496705888 50.71722086555019, -1.3957848772596353 50.71714696062535, -1.386873398457223 50.715532869990675, -1.384029538500603 50.715502554159094, -1.3835209671176583 50.71712845999704, -1.3891024175818574 50.71666150902624, -1.3947993646793968 50.718438599985376, -1.3934054839257801 50.721952922573216, -1.3940285599330517 50.72318189058276, -1.3985835358023406 50.72382244290566, -1.4001450116262815 50.726578708364755, -1.4060319062340405 50.726345435669636, -1.407269149906376 50.724066677682906, -1.410115336492011 50.72406676140667, -1.4097784860027476 50.725620807078116, -1.405742900302053 50.72668028976242, -1.4025918861054834 50.728134467670266, -1.3980126944851203 50.728795206091235, -1.3914103976477252 50.73074375601763, -1.3895995886954895 50.73161556071669, -1.3813127906613687 50.73283706300978, -1.3792470673798196 50.73410663151443, -1.3657002506954012 50.73715764731791, -1.3640536378946504 50.73788516723574, -1.3591048351969313 50.73810441004048, -1.3536747320100928 50.73889990620572, -1.3497044235436066 50.74110979234591, -1.3474359216696863 50.74321758961464, -1.3459627070967453 50.74662387801101, -1.341602403061854 50.74412176863746, -1.3399688018486344 50.7437779796218, -1.3392484229827852 50.741688460637086, -1.337679884689772 50.74075777915237, -1.3389020174935797 50.73739872578315, -1.338400672322991 50.735664760853936)))
http://opendatacommunities.org/id/geography/administration/par/E04001298 geosparql: asWKT POLYGON ((-1.407 50.708, -1.407 50.709, -1.407 50.71, -1.408 50.71, -1.394 50.718, -1.398 50.729, -1.354 50.739, -1.346 50.747, -1.338 50.736, -1.332 50.728, -1.361 50.721, -1.358 50.699, -1.366 50.696, -1.366 50.681, -1.375 50.672, -1.387 50.662, -1.425 50.661, -1.443 50.664, -1.436 50.676, -1.416 50.687, -1.407 50.708))
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>