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/S13003097 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S13003097 geosparql: asWKT POLYGON ((-3.47163919992554 55.77097192034,-3.46718951806502 55.7671404719546,-3.4643716038962 55.7674436811199,-3.45605984304902 55.7636199795582,-3.45731084387388 55.7576770126224,-3.45399920219363 55.7542898416576,-3.45313916589256 55.7487287020383,-3.44953108519209 55.7463809901035,-3.44615889276374 55.746524046058,-3.44465821397738 55.7434190290319,-3.44842942683375 55.7415037087888,-3.44629584589715 55.7381699046633,-3.44078185001571 55.7333758731935,-3.43587573582901 55.7317879930957,-3.43928580559911 55.7295967909613,-3.43695289083588 55.7269084745961,-3.43952419836496 55.7240450422881,-3.42135592009619 55.7150243825432,-3.41924954532435 55.7105808755502,-3.40956952639044 55.7102403330074,-3.3983872657461 55.7165371686925,-3.39643955019961 55.7162888405674,-3.39698584733398 55.710455208625,-3.40119888816959 55.702228878384,-3.40573998101889 55.7027035804686,-3.40941502843788 55.7008659966296,-3.42654463941221 55.688151430283,-3.45562578181726 55.6707478422664,-3.45568452950396 55.6657355274287,-3.45844409396809 55.6629484608511,-3.47323385325661 55.6597470620627,-3.47947766772495 55.652791138922,-3.48573992173154 55.6490229749737,-3.48444326953688 55.6432299776547,-3.48941397566712 55.6378040098822,-3.4890600246899 55.6350072675918,-3.48714230344164 55.6327353678942,-3.48132566643615 55.633548081583,-3.47782051855694 55.6326827382295,-3.48420276153694 55.6201928301007,-3.48170732373035 55.6164307847498,-3.49567095880268 55.6158892447482,-3.51525380687214 55.613175759669,-3.52489544623435 55.6137337938191,-3.52651700222943 55.6117015991459,-3.53002346154765 55.6113972737715,-3.531886122826 55.6053423543209,-3.52656795991434 55.6001039976074,-3.5268878276119 55.5970194522516,-3.51298381136522 55.5887823414151,-3.50849024419561 55.5810510699526,-3.50818795603686 55.5758561066527,-3.50350447474259 55.5749161764696,-3.50013088099888 55.5692242069947,-3.4884798391134 55.5626668522992,-3.4951080863861 55.5601642893734,-3.49594706697736 55.5557462090278,-3.50186064345859 55.5528386438595,-3.50342209488364 55.5474411144,-3.49840219865653 55.5329850143482,-3.494726008447 55.5290129625534,-3.49483636867859 55.5241948984546,-3.48897722152133 55.5219477987361,-3.48660663624789 55.5170519849455,-3.49784909754678 55.5153109103298,-3.50443205612841 55.5124668443234,-3.51161208674279 55.5027089036174,-3.51191302647067 55.493831008138,-3.52218306617999 55.4902618837124,-3.52349162057207 55.4862330834056,-3.51600035953956 55.4813520160178,-3.5189516451727 55.4778600897726,-3.5184781138441 55.4737770761217,-3.52465833005711 55.4676837312863,-3.52493247268908 55.4631060973989,-3.53167803485844 55.4612605279438,-3.53011574360168 55.4548186575064,-3.53545185906557 55.4519434828926,-3.53660486638887 55.4464202459146,-3.53956916348163 55.4431702724228,-3.53903846862027 55.437456873556,-3.53659238638289 55.4347108225515,-3.52519775618675 55.4328987654591,-3.52326722080637 55.4270905398919,-3.52010189334208 55.4265547608132,-3.51727276849294 55.421184440993,-3.51342148471421 55.4208772000928,-3.50977128159643 55.4175523010895,-3.51041204390981 55.4144709369505,-3.50738166011972 55.4122625788347,-3.52108210600838 55.4062237069973,-3.52108726714581 55.4024537321297,-3.5302789362331 55.3993959277891,-3.53140403794675 55.3964341473977,-3.53856214229597 55.3961601014912,-3.54983625999227 55.398983282916,-3.55427301949622 55.3969543972865,-3.55817265513821 55.3881112253262,-3.57849920880991 55.3849612107861,-3.58003703800092 55.3811668910737,-3.57392981240339 55.375835564431,-3.57598153649453 55.3754406828518,-3.57802800430293 55.3719408838374,-3.57127309568692 55.3681366639989,-3.5776760611004 55.3601233295095,-3.57714910327372 55.3581799198611,-3.57225105344635 55.3569893782934,-3.57269680703961 55.3551009019145,-3.57770280847481 55.3491365825509,-3.5804774253475 55.3479584616884,-3.58432610795139 55.3483282716578,-3.58827413154125 55.3461723537661,-3.58391603092681 55.3430727519982,-3.58442869289344 55.3411842561112,-3.57397020019558 55.3283576445064,-3.5866799179288 55.32294942385,-3.59993368028164 55.3268250470262,-3.60703370526733 55.3258242406869,-3.61483009997017 55.3188958150637,-3.62155787210776 55.3165383886846,-3.61784401032626 55.3118325716762,-3.61657268589113 55.3055630358152,-3.61862261451339 55.303095988741,-3.61868053054767 55.296201311881,-3.6260264644405 55.294197568042,-3.63413861302584 55.2948324509321,-3.64253576506337 55.2908868261199,-3.64829309508687 55.292624629203,-3.65297929275602 55.2913165642435,-3.66361982591071 55.2917471288472,-3.66699952735259 55.2953498062814,-3.67013265061075 55.296070847555,-3.66895639170687 55.2984415849761,-3.67240886830547 55.3005692181234,-3.67343065365729 55.3053812312142,-3.67837043869333 55.3089442430374,-3.69374101465778 55.3108079750803,-3.6987722033805 55.3136086387923,-3.69947909092776 55.3180141490348,-3.71116407131374 55.3231560733634,-3.71231264752984 55.3284063383662,-3.71033259685001 55.3357963399731,-3.71433067741365 55.3400945441565,-3.71046860594376 55.3441460589113,-3.72018697815792 55.3502421524785,-3.7110507571067 55.3632389867689,-3.72063450338467 55.3652469466375,-3.73466791164807 55.3648886238432,-3.74457176204965 55.3708722866503,-3.74816134372153 55.371468955793,-3.75040695718512 55.3747207425251,-3.75366767167467 55.3749390414897,-3.7529059779032 55.3777000379606,-3.75866304262019 55.3802775612151,-3.762756042844 55.3887248732925,-3.76184016540083 55.3919149996736,-3.76526071999788 55.393734970515,-3.76345913364456 55.3967131911323,-3.76460209442305 55.4011003627204,-3.77717840157653 55.4042443583145,-3.7788035070696 55.4087402967738,-3.78671685761049 55.4085575341721,-3.78903240352643 55.4106850847165,-3.79230369917328 55.4105428401356,-3.79234393165901 55.4154401679304,-3.79607933896004 55.4190745873865,-3.80762018797526 55.4232004108619,-3.81035684751061 55.4275815852222,-3.81641103987569 55.4272671145488,-3.81801728919786 55.4331612847202,-3.82548506963243 55.4393140898737,-3.82550719821578 55.4444139306823,-3.86093488238325 55.452135705978,-3.8683452498619 55.4547809481561,-3.86945341761333 55.4569793555982,-3.8890903426398 55.4563586850224,-3.89544503731811 55.4597564203792,-3.90016056473997 55.4596383537825,-3.90612639837807 55.4575683887584,-3.91954468715017 55.4577001087353,-3.92435690979333 55.4563258625103,-3.92728628201282 55.4598027487591,-3.93530954133397 55.4579505842291,-3.94099535333621 55.4584320320983,-3.94823441650076 55.4599383611615,-3.95099097984227 55.4625905826508,-3.96526960770629 55.4551766640962,-3.96979952123018 55.4543623863075,-3.97609692914432 55.4609069839001,-3.98623580107144 55.4640502117588,-3.99434906265061 55.4647989308418,-4.00044757003973 55.4637107726926,-4.00142467022713 55.4669167598534,-4.00803345119079 55.4713516747257,-4.01683334077563 55.4729595403892,-4.01154325847387 55.4826361493986,-4.01392344020873 55.4844942462245,-4.00656416389594 55.4860252936764,-4.00568026343683 55.4896526710772,-3.9925490219202 55.4907299546954,-3.98080252000031 55.4883412641975,-3.97263075332345 55.4821119347932,-3.96386329407236 55.4814135800097,-3.9578757050425 55.4823551586568,-3.95548612271946 55.4812726962203,-3.94880643896866 55.4840331506506,-3.93471847614389 55.4805953068905,-3.922470616623 55.4871090325249,-3.91610652771333 55.489461011915,-3.91222007273016 55.4894166699047,-3.90306450745341 55.4872774457121,-3.89472213458747 55.4779891892553,-3.88835323725863 55.4754463285286,-3.87060341591528 55.4834335420849,-3.86268946410952 55.489180102765,-3.85052053374382 55.4920473746746,-3.84799832337216 55.491595642681,-3.84611422612804 55.4874585767645,-3.83406433979739 55.4911626425294,-3.82045243833845 55.5038803054315,-3.81866767173823 55.5070657658658,-3.81985956854232 55.5118606664423,-3.80916634304096 55.5158655480435,-3.78741509627545 55.5209013421827,-3.78095041208912 55.5302583193292,-3.77035530221331 55.5310724591817,-3.75579889896709 55.537051638122,-3.74479512707855 55.5390691663798,-3.74013226115789 55.5418584514509,-3.73793691645334 55.5484950270988,-3.73999453378454 55.55405555306,-3.74944708930513 55.5542786016379,-3.75155559896709 55.5556657438245,-3.74857380874619 55.5597119941093,-3.7596916042915 55.5630648651426,-3.75371749546289 55.5738699937664,-3.76760433857841 55.5762963979709,-3.76850198176526 55.5791503281748,-3.7754559754514 55.584401446666,-3.76998764345956 55.5876978034307,-3.77079216219862 55.5894241875368,-3.7774835708395 55.5925392993017,-3.77489217935845 55.5945826756924,-3.77498362364749 55.5986793406842,-3.77234916669342 55.5986159355421,-3.76951502300208 55.6015200668167,-3.76416059022612 55.6114826693931,-3.76531089676188 55.6153161185698,-3.76161390207718 55.6249356671646,-3.76279723913205 55.6288620951808,-3.76717251297617 55.6285259170502,-3.76533820345711 55.6307945211917,-3.75711152626985 55.633425358356,-3.7558599016037 55.6366614140198,-3.75273358961917 55.6370242588821,-3.75052938283377 55.6424603371501,-3.74092258064227 55.6483692768479,-3.74008632181265 55.6533075860784,-3.72977156140883 55.6524909905606,-3.72345494390904 55.65721792796,-3.71103696455552 55.6562990105948,-3.70653061806236 55.6574688818122,-3.70304774673232 55.6607236840021,-3.71005416391203 55.6686082028981,-3.70958573949226 55.6740542984087,-3.71620771601175 55.6744238266473,-3.71874715777835 55.6761594919481,-3.72019903976898 55.6715910596196,-3.73400369219312 55.6705969104233,-3.73782495200862 55.6807158027206,-3.75924065492017 55.6787507753009,-3.7516920961627 55.6856437263934,-3.73905407944024 55.6902008476641,-3.72326700819562 55.6923960456684,-3.72149100313391 55.69093725349,-3.72059907182506 55.6920012511005,-3.72436909595822 55.6938660792023,-3.71856555027267 55.6939528604247,-3.71641707297652 55.6979343647238,-3.71398599718177 55.6985577739562,-3.71550968659007 55.7004668853018,-3.70185287610336 55.7007944276686,-3.69137572492207 55.7061370816429,-3.68764981644996 55.7105269781236,-3.68043735056323 55.71392849151,-3.67804561034575 55.7175863082964,-3.66829518592972 55.7208851891758,-3.66447246693736 55.7198748089695,-3.66053659543325 55.7205823032266,-3.65771674777648 55.7227196688453,-3.64398768420656 55.726899627596,-3.62802035820064 55.7373648611339,-3.62656420261059 55.7415314410935,-3.61547342275533 55.7424029779148,-3.61193646256561 55.737523093473,-3.60426649936802 55.7359179426784,-3.60408920887881 55.7371469034245,-3.59875666044232 55.7365253086746,-3.59030902478254 55.7417006472891,-3.58510467330434 55.742640419065,-3.56910752199382 55.7398156907914,-3.5639312040725 55.7458414086202,-3.56739688234877 55.7481219515995,-3.56716285587787 55.7544422768798,-3.55069148875298 55.7660962010415,-3.53363919302528 55.7717297689955,-3.52919366852915 55.7833863297313,-3.4827964778445 55.7720212902857,-3.47163919992554 55.77097192034))
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 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://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>