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/S13003094 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S13003094 geosparql: asWKT MULTIPOLYGON (((-4.476557413459417 55.19878695528856, -4.473043775626417 55.19661110832607, -4.4700672356565345 55.19599731521951, -4.466429461624922 55.192057471517806, -4.468310027171549 55.18910976125427, -4.4662188961530225 55.184611003471694, -4.467685891451478 55.1832598881437, -4.4669355194652764 55.178414887090725, -4.465041640394841 55.17379340909974, -4.461860523524254 55.17021452654625, -4.461887055547243 55.16758749971704, -4.464054095905795 55.163390895164, -4.463656791251139 55.162167456731474, -4.468406781302129 55.159383625751225, -4.471825817489327 55.15615474351902, -4.475232025706753 55.15577097949963, -4.478634301830298 55.15291974954768, -4.489407872491203 55.15225067486148, -4.500349048725439 55.152633366237886, -4.513586010086659 55.151704787711076, -4.515520120577804 55.15313000259591, -4.532134987242138 55.15831854033478, -4.536235286629019 55.15749618673619, -4.54856454424789 55.15881197209687, -4.55795622286522 55.15837242615172, -4.56058224095487 55.15748394747679, -4.565241966053882 55.157536085701736, -4.567588096864926 55.155446103060335, -4.575279078547451 55.15311289685816, -4.574626155407372 55.149679384868705, -4.578663588506206 55.149126597353565, -4.584016132144098 55.14197015760671, -4.586430564248728 55.14363138783122, -4.590353673447318 55.142658083914384, -4.590918123144736 55.140956156841305, -4.596174855935651 55.14119029753237, -4.598302457397225 55.13843466818852, -4.610430070498118 55.141883399152675, -4.614604907986861 55.14165006817231, -4.616384406918028 55.13982747287966, -4.6206689859657875 55.14115111330205, -4.626509657286507 55.13892638442975, -4.627062684915409 55.13420859673891, -4.6319235217059225 55.13296827356314, -4.634345699757128 55.13127358927383, -4.645618306448496 55.12783355271925, -4.644645240297135 55.125930994478935, -4.650322756509122 55.12117804915665, -4.6566647233497545 55.120900463113806, -4.658514839941464 55.11970951077666, -4.659690892427815 55.11593077917268, -4.662354425930052 55.111885768014275, -4.658699661750698 55.10679680550417, -4.659881757134532 55.10523829104358, -4.65984724130204 55.10070836375164, -4.65842796679354 55.099521298932025, -4.656985684681889 55.09302659206421, -4.661255888933867 55.08876667058445, -4.658144821960942 55.08723006215866, -4.655318632906291 55.087624352149426, -4.650369290178498 55.08305326462114, -4.647016322234108 55.08104525858982, -4.646980457553287 55.07825034472679, -4.643019896819299 55.07723518526446, -4.6373171328473015 55.07724207473684, -4.635135196334888 55.07825119064053, -4.630531046141075 55.07721361436703, -4.6289942896446865 55.07480629592649, -4.631351618050021 55.074202483602654, -4.630556734959876 55.07163975696973, -4.626703574085634 55.0706936491927, -4.625282832902697 55.06729946603943, -4.62922374307596 55.06397816394104, -4.627035821646681 55.060587004673714, -4.632283965036546 55.05798802195439, -4.635541259842142 55.053341984428535, -4.633766877876651 55.05135775797637, -4.64590586796848 55.04881107952223, -4.644645422563062 55.05213313654769, -4.646194802160422 55.05390174810096, -4.651022976587703 55.05504616287266, -4.65659287014012 55.052726760950804, -4.661713502875028 55.05332057307496, -4.666820726787686 55.05065116100119, -4.670114200364341 55.05096553453486, -4.677287772353257 55.04900636575664, -4.676904106053964 55.0466586291355, -4.6807682322945094 55.04427226222836, -4.687759716798143 55.0441763999351, -4.689920102525755 55.04487482969958, -4.698561418747685 55.04184275600753, -4.702411800437367 55.04159991299965, -4.710816857206846 55.03961046205823, -4.714324128981704 55.037657921168716, -4.71938599955289 55.0409788770258, -4.722146252572184 55.04428375644051, -4.725942012970319 55.045655098707435, -4.735194267118202 55.041514415294166, -4.737221280149124 55.04208460992085, -4.740355771964647 55.04717861895543, -4.743344204800663 55.046576351788204, -4.745936855239725 55.04396930327664, -4.749812332730594 55.044092951587054, -4.752771045802026 55.041580914920644, -4.7614506832643775 55.03804447533049, -4.766127906486715 55.03992938081911, -4.776012010726961 55.04183028517516, -4.782554809672667 55.03809391950779, -4.787930942251454 55.032113952139206, -4.790132482023225 55.03124985467136, -4.794137275760435 55.033360404318344, -4.791844667172182 55.03797540058525, -4.79718173866673 55.041331810600454, -4.799268020310144 55.043971796589986, -4.803959190171455 55.043220980999216, -4.808650965889859 55.043485793925306, -4.81648208693987 55.04297659054649, -4.819164722837672 55.0412737296384, -4.824258354402699 55.04124552469073, -4.827533369411895 55.03529274176732, -4.830470740074892 55.034664327686826, -4.833707620444366 55.03550592666902, -4.8349987140122215 55.03849197721981, -4.841169872822219 55.04473076544164, -4.844125878925307 55.04314237633631, -4.851516500646696 55.043598630287164, -4.859699159331513 55.04143774989203, -4.8689796316511345 55.040302211451056, -4.872050505147981 55.03858908592886, -4.876865114986368 55.0383854219447, -4.8794471130754316 55.03978962931656, -4.884539564813673 55.0396375032696, -4.8826737090506835 55.047219853509766, -4.888188600490781 55.05226731848108, -4.896233000928628 55.05361335625313, -4.8946646396573685 55.05835237796264, -4.894751302107716 55.06085403682713, -4.901059284605081 55.06425939428742, -4.905212147345235 55.06201615782102, -4.908867107899555 55.06198274653657, -4.912946019647971 55.06638014947595, -4.923068180768781 55.06620037955744, -4.9236971358102 55.06494463050859, -4.933421514758487 55.06436444000462, -4.93257989443082 55.061854017991855, -4.929900614292386 55.05927093619896, -4.931425952448901 55.057427155351085, -4.930803226956094 55.05137385989372, -4.935480889707579 55.04842468030349, -4.940030805153936 55.04641337666326, -4.943226334421604 55.043553625474736, -4.944248985446354 55.039249520748776, -4.952026687234916 55.02974719704465, -4.9577523168275945 55.027481860287686, -4.956692797743965 55.0257410157163, -4.96168588782128 55.02068482669871, -4.969060029089531 55.02188405275886, -4.9740727823749715 55.0235416485779, -4.97808236959214 55.02211297029201, -4.981083872131479 55.017858869080705, -4.973253275224428 55.0115281461064, -4.978496895958041 55.00924669318152, -4.986862437001343 55.01098783335745, -4.994698120400787 55.0086553501783, -5.015480647827304 55.005750130687055, -5.029516931043209 55.00260958839753, -5.035665322635269 54.998801628201825, -5.040199283282164 54.99764681635238, -5.041688010917866 54.999648993709776, -5.047727345455404 55.00493696858089, -5.050374888189178 55.00808854971307, -5.049927854217758 55.01012324040711, -5.055048190296246 55.01152305769269, -5.055639181338647 55.01754083789199, -5.059356648204387 55.022383142551064, -5.060930199771438 55.02772885711463, -5.059486931589993 55.03189182324868, -5.056590982106674 55.033942560578076, -5.052260713187955 55.04446679416917, -5.053641656654076 55.048743060403886, -5.051693073489971 55.05301388807929, -5.0478599690253265 55.05751171970653, -5.046041633779197 55.0578009076474, -5.043889706146826 55.06223581167035, -5.03964155479772 55.06568368132445, -5.035657518043664 55.071282676414455, -5.032322017222851 55.074699489535426, -5.030706896008689 55.07822440104036, -5.027297400502261 55.08183619638244, -5.020524593685191 55.08526854057065, -5.0149668800764555 55.087305123479105, -5.012349048876261 55.09139341355043, -5.013320268137919 55.092409295961886, -5.0100458417244615 55.10025318644324, -5.009693336170282 55.1055037257212, -5.006110976116639 55.10599321858844, -5.002587667807666 55.10942276112473, -5.000161336102009 55.114713562892135, -5.00035745269207 55.11831885183901, -4.998379046242171 55.119589367926025, -4.997801840871563 55.1230027891394, -4.9963662448799475 55.1249053992145, -4.99712533439371 55.127581085361705, -4.996415235113655 55.13183448448966, -4.996841377494838 55.138101863407115, -4.99402127109806 55.14006699846874, -4.991816388068957 55.14391558953361, -4.988773890020615 55.1454386152396, -4.985007052888936 55.14579980748023, -4.984253748114538 55.14735648646435, -4.97470917885063 55.15173147639864, -4.971655208975527 55.152357122819296, -4.9667903346897955 55.155488576982265, -4.962074819915643 55.15712986220288, -4.960008793150893 55.159272079743914, -4.955947610433043 55.15960174638273, -4.953036217717295 55.16199719294045, -4.954022377856777 55.16416236210509, -4.943230293201067 55.16406938307577, -4.937715007135552 55.16901756478765, -4.931352836972625 55.17382862112056, -4.931073160156646 55.17876986195864, -4.926237570507404 55.1842710823485, -4.9218884091480115 55.18785006489519, -4.91364598508562 55.19643951246121, -4.910497476319356 55.198951009348875, -4.907401099470449 55.20002728804365, -4.904627851861107 55.20230492441819, -4.895057067479632 55.20709049259898, -4.894791751904597 55.20917344874706, -4.890000218898157 55.211323345032355, -4.885192961660631 55.21437060156339, -4.881573639710071 55.215329121348674, -4.881642013804795 55.21714434404486, -4.8787475590991285 55.218651096656544, -4.873810228601703 55.218218311959696, -4.866552282694552 55.22167854406372, -4.865606152727201 55.22496586393211, -4.861791786145664 55.22762921938628, -4.860958637454383 55.231730109715166, -4.862788636400511 55.240403597112795, -4.864943061021725 55.245463569488905, -4.861197025905266 55.24641443796264, -4.859481025748478 55.2531775455386, -4.854180367673408 55.25576227158852, -4.851115046037639 55.260685420118776, -4.850926817536686 55.265948683772606, -4.848377531066785 55.26754726537657, -4.84827757239064 55.269862367019584, -4.846271128281636 55.27370219708795, -4.843585792906187 55.27466288184126, -4.838586845486621 55.27811264496622, -4.839652302140233 55.28088101496061, -4.837753101761718 55.28520210806014, -4.838689409128049 55.28771125152859, -4.837594293978076 55.2901108765544, -4.83791415399609 55.29613365901526, -4.839480378067762 55.29846149011499, -4.84293838695377 55.30045848038424, -4.840317440694999 55.30408657692865, -4.842694662398768 55.30731962433059, -4.840979854802551 55.30996320545238, -4.840617460801469 55.31567732718351, -4.842951199503006 55.31988855286246, -4.849238549795223 55.32288086174744, -4.840533171937708 55.32971713147427, -4.830013032237768 55.333831612466, -4.824535639325683 55.33495538418018, -4.8212272764041515 55.33815302735907, -4.817990309600925 55.336996933711355, -4.811850786312497 55.33920335485902, -4.810609930790176 55.342625986250496, -4.81095906193142 55.347478463189574, -4.804214883834246 55.35139784263383, -4.7970085872983335 55.35294557983947, -4.789637915160486 55.35566750781559, -4.782066900819482 55.36002088678009, -4.7780101546454805 55.36152805590419, -4.77467781825115 55.36382902228483, -4.774990619974484 55.366236184509596, -4.7732502458850785 55.36767816051728, -4.765514036002385 55.36793076790552, -4.762234046254652 55.36575317388337, -4.750454989731658 55.36526920358442, -4.745099660672659 55.366105189622665, -4.740831242036921 55.364017542573094, -4.741393618752101 55.35754619143059, -4.732317766218414 55.35244499594904, -4.72775678019189 55.34825096354589, -4.720978257030165 55.34981712385236, -4.712416026243998 55.34964623292891, -4.702827615955707 55.34849059853885, -4.700498516687939 55.34695374145876, -4.69684297594934 55.34664441153898, -4.698232448631883 55.34434487661439, -4.701487716111908 55.34477804600384, -4.704281363269447 55.34385332146233, -4.707214313334469 55.34106727970603, -4.711518472061931 55.33915055330818, -4.710183577835602 55.336163465753025, -4.707716775541372 55.33618215464384, -4.70607411838472 55.33166019434703, -4.709053701297119 55.32913196401743, -4.717842409585455 55.32901303093484, -4.718108511024829 55.3259454410845, -4.7159834193293815 55.3239215782962, -4.723782165989936 55.32294865027941, -4.735702986700535 55.322043872552356, -4.737356964395596 55.32055957591288, -4.73129816355373 55.31945295670428, -4.727955694137725 55.31717515401447, -4.717998475901264 55.316696114126415, -4.712773745577599 55.31379739419184, -4.716495621355705 55.310787666227384, -4.715487775089252 55.30766565323263, -4.709219417674906 55.30728272820147, -4.706008422358556 55.302435917652055, -4.703465004381684 55.30058027987532, -4.699715365298451 55.30114055865529, -4.696546186482895 55.30020564210231, -4.696564155536835 55.2980550121657, -4.692491886405683 55.29892253136238, -4.687935283330751 55.297269140477646, -4.687288129248019 55.29575971030476, -4.675817901790165 55.299300015537106, -4.673234464137564 55.30209384829035, -4.665045722048798 55.30237626709585, -4.657390414499673 55.30052956400312, -4.638007249713531 55.30418256724191, -4.635981430011102 55.302411423793885, -4.632923412714964 55.297804010547125, -4.631468133042212 55.297264575094616, -4.628797276361117 55.29337689085994, -4.626089072454406 55.292514711136114, -4.624033676439183 55.289538571502945, -4.625666257737294 55.28837987903723, -4.622322537066092 55.282703222874346, -4.618056475076501 55.27938347537684, -4.614093508971846 55.278506618690635, -4.613512906063269 55.2742502204818, -4.603448489853572 55.269008101198864, -4.600092519406166 55.263789714641625, -4.59853118074397 55.25750273111974, -4.592210512389404 55.25552126410976, -4.59348120656335 55.253889728096645, -4.582633903449312 55.24763878475374, -4.576015863163452 55.24554947924558, -4.576719584323174 55.24390313333454, -4.57463138170703 55.24238764281596, -4.575484684932906 55.23855373133839, -4.5670150461194154 55.23711429721411, -4.563185114902344 55.23458089485322, -4.560964567718116 55.23590846289373, -4.554427765492578 55.23743888882522, -4.551186218325773 55.240124282773266, -4.546832406970233 55.239864719542574, -4.543770100138508 55.24132815893397, -4.537032293573566 55.239208712700645, -4.534005471000461 55.236216295612614, -4.530860382050116 55.236180058412614, -4.530380430295707 55.23268616932982, -4.5273332809627655 55.22792048103798, -4.520775364993243 55.2282944451662, -4.518833617543003 55.22419971155618, -4.519268756684058 55.21827154516864, -4.515182524096431 55.21456261539625, -4.512859985904643 55.21101500413476, -4.504498901521137 55.210921862279285, -4.503774286152569 55.20626703295714, -4.497216974015013 55.19969589495244, -4.49317070945772 55.197189868225074, -4.48493839947242 55.19722317199196, -4.482723831571393 55.19648622518843, -4.476328902587313 55.19751070297398, -4.476557413459417 55.19878695528856)), ((-5.118623563394617 55.25825884526759, -5.114212742709064 55.256890810815435, -5.106486932266793 55.25162792434409, -5.109463676172429 55.25004353686155, -5.111216361687712 55.24778269568356, -5.1175736807783005 55.24658905479779, -5.121665973931704 55.24760011313244, -5.1245602430552655 55.24966663069535, -5.124724429292928 55.252239971016024, -5.123289730704021 55.255776698247466, -5.118623563394617 55.25825884526759)))
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>