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://statistics.gov.scot/id/statistical-geography/S01007281 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01007281 geosparql: asWKT POLYGON ((-2.832312548999645 56.74613714959663, -2.828102360938824 56.74295037831913, -2.8374624492588083 56.74023611979049, -2.8399928875070226 56.740812034248464, -2.842668273563301 56.73909600172728, -2.8397684194200172 56.73734572933197, -2.8387604109627946 56.73465732126348, -2.8388286491807144 56.73331824754084, -2.841203394602118 56.73297086613363, -2.844429182874771 56.73014500972951, -2.843941433647919 56.728800713749656, -2.8444911933262578 56.727808749034836, -2.8431909217249496 56.72666760167608, -2.8426359183185497 56.727426012168266, -2.840706000373838 56.72735819145036, -2.839086275102453 56.72654258056251, -2.8373066227504875 56.72588075151553, -2.8348433714654457 56.72607695884473, -2.8346566407027742 56.72723714524768, -2.8324987248809035 56.7279433478717, -2.8292928780825846 56.72782098002944, -2.826128189455388 56.72733889746486, -2.8232883720397846 56.72751041977163, -2.8201581226923516 56.72785448479606, -2.8187053415737204 56.72718125553033, -2.8175880981656043 56.72540077861517, -2.815547258356337 56.725486024304416, -2.8137436983978814 56.72596498228976, -2.811583990232531 56.72584430767139, -2.810528217068586 56.72538401277594, -2.8100780620299575 56.725728331142776, -2.8069749340692627 56.725811353768165, -2.8056433672469083 56.72620628077395, -2.8047942629752374 56.727002356985075, -2.8035105011843657 56.72734303934856, -2.8019557084273994 56.72723627261189, -2.800961350245429 56.728123096565966, -2.799743068534474 56.72847231185073, -2.7986018534421526 56.72783278546577, -2.7980310548672485 56.727117725248185, -2.7964114962576705 56.727038247099834, -2.795091622936665 56.72567212960205, -2.792785768425534 56.724815377158805, -2.7902918714246336 56.72433711043229, -2.788849886890988 56.72336698711641, -2.787218325188357 56.721921904176995, -2.786553767909857 56.71983283790787, -2.7823005301025336 56.71722731448969, -2.7822246650005833 56.7159340999454, -2.7813102226008413 56.714681831166345, -2.784724877642586 56.712852921159275, -2.784675050373381 56.712001680193836, -2.788771770040142 56.71133236824279, -2.7929383411719746 56.711531694603146, -2.7956861110832723 56.71049440312384, -2.798146945344468 56.707909240705376, -2.7974272683022656 56.707420287156836, -2.798407578183134 56.70556274855863, -2.798842576398387 56.70525475548601, -2.7985769081953955 56.70288510612944, -2.8002933990050076 56.702548024674776, -2.8023694183013057 56.70139566861304, -2.8050865238436287 56.70168360180778, -2.8063323224376355 56.70113649418865, -2.8047071393967364 56.69988145394101, -2.8036516962622584 56.6987281362767, -2.8055689541230824 56.698275534688406, -2.8039536754182954 56.695276327287544, -2.802524046702625 56.6956179555764, -2.800218793825213 56.69548005962598, -2.799570174975317 56.69258245242242, -2.801995432458151 56.69072507246473, -2.80332807240256 56.691049772831796, -2.8046611844659055 56.690941012934125, -2.806366642093296 56.69121377861609, -2.8073184781059384 56.691725127788544, -2.810337833445416 56.6944257911529, -2.8124949590799666 56.69391174101507, -2.8135277677583472 56.69341337537638, -2.8129556790155736 56.69302933344789, -2.813606200393535 56.69238246720628, -2.8126383727452233 56.69138608775943, -2.813570786551147 56.69086437101536, -2.8108250010415423 56.690543525900495, -2.8092921101349253 56.689330464973494, -2.8084654351797873 56.68927489556333, -2.8078768795633997 56.68858623514656, -2.8087024984489477 56.68730736368378, -2.8081743795817893 56.6853612575614, -2.810869724605762 56.68507055885211, -2.817746307479816 56.68300418356413, -2.8267488359573734 56.68115691393284, -2.830879446518958 56.68046460091225, -2.835495140418428 56.67957124706975, -2.8419350996622925 56.67852165475255, -2.844626487021135 56.67844952348537, -2.8459612138879895 56.678287733482826, -2.852716854620598 56.67678623223113, -2.8600775533466414 56.67536104096901, -2.8610714321465847 56.67671975384614, -2.8627481108884387 56.679385406936305, -2.8655550238540664 56.6786561843054, -2.8665060689881248 56.67813747648305, -2.871794706340943 56.67816345026267, -2.8733528946706546 56.68131493394876, -2.87373771200878 56.682426262363464, -2.875724425984582 56.686418512190286, -2.885580035235742 56.68525916338185, -2.888804721258606 56.684829668443385, -2.8934098764973317 56.683437356696906, -2.896630294816403 56.68206588367529, -2.8943712915566024 56.67972828992213, -2.8961288253042627 56.679509019458244, -2.899250992724416 56.67833654360664, -2.903159031140847 56.67448404689575, -2.9038230994718783 56.672975849832795, -2.9044396213002046 56.67214483219023, -2.9088533011837585 56.67246307429302, -2.908970579299481 56.67394460165404, -2.910981356859159 56.67476543150208, -2.918952569600874 56.6723799611873, -2.92009478244943 56.67304533729922, -2.923620098241581 56.67372898478745, -2.9246063107877065 56.67468296997631, -2.9255758408953274 56.67428944797835, -2.9288863317224494 56.674192921943416, -2.9356640030721484 56.68097912290605, -2.9483838534042612 56.6876569601297, -2.949701207496063 56.6913483953367, -2.9461224551850624 56.69122291143274, -2.939122652606515 56.68943413009707, -2.929637574537304 56.69143688200498, -2.92994614317483 56.69188599534803, -2.9244476636020003 56.69348908980847, -2.922355765657854 56.691223843230496, -2.9170284730012823 56.69252153447866, -2.9167218940502346 56.692736490507144, -2.9214921320254406 56.69685195369697, -2.9102141470138494 56.7011394423389, -2.9064790162623715 56.69929798662619, -2.9043590300342106 56.69942120587115, -2.8997413698023538 56.69889763240622, -2.8975151541395054 56.6979883405227, -2.896278576839794 56.69817691761237, -2.895211753563395 56.69932556933684, -2.8974860465231003 56.700881419521295, -2.896377887932336 56.70235380559337, -2.895012543714203 56.703315936349796, -2.892714635868005 56.70421286567619, -2.885744770305905 56.7056972595858, -2.8835479791279863 56.705659162287915, -2.881442548207739 56.70518616179416, -2.8806580515162845 56.70397901351903, -2.878564475625348 56.704351659231136, -2.875304443948961 56.703264043636594, -2.873508375092977 56.70424121638383, -2.8742336804329036 56.705233359358836, -2.8742331800181486 56.7068306392919, -2.8737128552953366 56.70786336887231, -2.871139534163316 56.70845336024072, -2.867476595450876 56.70886118298484, -2.8671928576254326 56.70983610418168, -2.867088245809365 56.711275663727, -2.869624101911482 56.71334565680137, -2.87364106541012 56.713675477806774, -2.8799575964159447 56.71444449458483, -2.88655911648596 56.71514557190135, -2.8901458852023767 56.71628905774472, -2.9000967582040986 56.713781696463016, -2.9030636617060837 56.71283486618131, -2.9051893694009334 56.71291826469381, -2.915840885501791 56.712930260830085, -2.9157085675004857 56.71824083005298, -2.9165312095857154 56.722226346714386, -2.9121067256209545 56.72266046381566, -2.91409603134971 56.72517939552548, -2.9147217319265133 56.72495259190467, -2.916851665541721 56.728285608464724, -2.9191104873669333 56.732446562071104, -2.9226127577756498 56.73196249552457, -2.924374007909034 56.734464984453254, -2.9270156914643684 56.7360517598789, -2.9323656151480066 56.74100874831571, -2.9342821965525734 56.741820931173855, -2.9348214450751815 56.74180838899426, -2.9397236833301372 56.74096679462064, -2.9428442241086796 56.74082826788293, -2.9418001015920408 56.73946140883531, -2.943587838519518 56.738224497524975, -2.9439214806416905 56.73746541225225, -2.945256914310474 56.7369583721437, -2.9472846358974665 56.73879323192678, -2.948457994373941 56.739260959225824, -2.950548953738962 56.739218329211916, -2.9536521041178356 56.738457928423195, -2.9571926269321653 56.73813276710192, -2.9584211885458593 56.73771668731959, -2.9570120652376186 56.736389917525045, -2.9562060906462206 56.736585156228045, -2.9539561842156865 56.735196440161715, -2.9539769382472056 56.73466467409867, -2.9573211235493884 56.73461550145717, -2.9601797881170135 56.733529441213, -2.965066972933683 56.732889756382946, -2.967584755621165 56.73291515436197, -2.970000612138699 56.73152180371731, -2.970339659222783 56.733262083813074, -2.970966883055058 56.73476653075345, -2.972143206541323 56.73537726482448, -2.9721286120106387 56.7360781399109, -2.970466902360088 56.737564485177586, -2.9701196503730647 56.73994797830981, -2.971458992416145 56.741168369569884, -2.970518010539079 56.742083095074555, -2.9707267711752903 56.743204482813056, -2.9727890829402117 56.74392510139644, -2.972165722361637 56.74447799531695, -2.9700273067331664 56.74461144860652, -2.970850776845826 56.745476495575986, -2.971611913901261 56.74772557475685, -2.9716519191458897 56.7486416411772, -2.9730860009962643 56.749717530795984, -2.9731592082390312 56.75065130563284, -2.9716528605114503 56.751211085874914, -2.971587699078989 56.75248733528041, -2.9739670112430745 56.7534300670491, -2.9746545450180717 56.75471840336007, -2.972857912884111 56.7554421799449, -2.9722793718726783 56.75647087060816, -2.9702930045384335 56.75681876636392, -2.9688709223378016 56.75748566433547, -2.969258583822343 56.75793185529132, -2.969249566775207 56.759486171770966, -2.9664828932053604 56.76002872627399, -2.966174540522409 56.76139669593132, -2.96365873724833 56.7627997134105, -2.9610560961314283 56.7595316319565, -2.959482194361149 56.76002889424454, -2.959716563882499 56.76088057707478, -2.962492589124865 56.765171531090246, -2.9607651334128855 56.7647895550379, -2.9597217313569613 56.76557022012186, -2.9573594895109223 56.765956726537034, -2.9561036656131394 56.76739482774268, -2.9556758100251757 56.76858400309173, -2.9512738969903585 56.771780047697945, -2.951532473117549 56.77294600074738, -2.9460476711037202 56.7793124921346, -2.9467814170841193 56.781804483932234, -2.943768434628565 56.78369599696865, -2.9454721327140625 56.78505765777851, -2.947494251619455 56.788007030662584, -2.945815439079033 56.792844187721755, -2.9415957129425085 56.79561623311155, -2.9490231157965954 56.80252255225111, -2.94715309591431 56.80953529412298, -2.9496493609028684 56.811097501860914, -2.9507688679321857 56.81649733593051, -2.9484613996053346 56.817884898768426, -2.9362189289576874 56.81636478091387, -2.9222678817649292 56.81126696099802, -2.9137619179584537 56.81105104053264, -2.9063346960561134 56.81345002993809, -2.9024832564758305 56.813361145607686, -2.8977655533897124 56.814033037542075, -2.8935067298712704 56.81197035097206, -2.8910772988277293 56.808987091588534, -2.8793146549892015 56.8053511993912, -2.8855900327440045 56.797850144670626, -2.88510169397391 56.793801851067144, -2.8879530947033847 56.790457523338574, -2.887763695087716 56.78452047405209, -2.8889812752104813 56.77994794547782, -2.8854790509440336 56.77994590895063, -2.8817101483272265 56.77345923398414, -2.8800465256297185 56.77089258516116, -2.8762117657773825 56.76922161922696, -2.8764708220708597 56.76770150665223, -2.8720656166818763 56.76539656065211, -2.867589343582824 56.764241903607484, -2.8657413619623986 56.763553999022065, -2.86773650989574 56.762821411505186, -2.8670976158319514 56.762071202438634, -2.865933317182578 56.76194453467319, -2.872747833267684 56.76025295053067, -2.8623906421277905 56.743695664586426, -2.8609435748878607 56.74404706007837, -2.8594315812699325 56.74298839914471, -2.8558201953408386 56.74378587132186, -2.8541262630527684 56.74334829107845, -2.8486224745076933 56.74421340860865, -2.8455300376600863 56.74554127934047, -2.84485208375129 56.74522419598773, -2.8428929328362784 56.74624272178929, -2.842028670357099 56.74686514226009, -2.8409548792938986 56.747282994794546, -2.8393704709349974 56.747356561785125, -2.8389168038367263 56.74827597182718, -2.8363717329541087 56.7485356504719, -2.8331781780263685 56.74609210656591, -2.832312548999645 56.74613714959663))
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://statistics.gov.scot/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://statistics.gov.scot/sparql HTTP/1.1
Host: statistics.gov.scot
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://statistics.gov.scot/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://statistics.gov.scot/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://statistics.gov.scot/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://statistics.gov.scot/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://statistics.gov.scot/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>