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/S37000010 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S37000010 geosparql: asWKT MULTIPOLYGON (((-2.3632806956081254 55.946622451423146, -2.3665501624972065 55.946115954592166, -2.3665518466797293 55.943235430234196, -2.3725611645055387 55.93898459389979, -2.3799332500919 55.93606627438684, -2.381784601354823 55.93372623447028, -2.390504671408117 55.93322992251811, -2.3922664163335736 55.93080916651897, -2.398692368053562 55.925034649403415, -2.3981515425565494 55.92255297348015, -2.4002529306100344 55.92056412429454, -2.4060085353645233 55.91797912208732, -2.406942927860644 55.914922140387255, -2.409159797745861 55.913509507889984, -2.417113801093115 55.912007556845694, -2.421185842546795 55.90971595341435, -2.4250545165629815 55.90876912236557, -2.4227881779991622 55.90644448499561, -2.4339974750737 55.902719838613315, -2.435192716256758 55.9040498558625, -2.4459169375924414 55.897802959886135, -2.448561353683183 55.893453612086994, -2.4597703953265104 55.892136392607, -2.4611286752016976 55.89071613803683, -2.4663800171862813 55.88931270345425, -2.4683894621923526 55.88491142933694, -2.4754241297520445 55.887584379239385, -2.4794093823816983 55.88794186750372, -2.48519229583538 55.8907898859809, -2.487948957075828 55.89449877252837, -2.489121142962797 55.898699040670415, -2.4921720960516685 55.900946575231146, -2.494680356277654 55.905761491719545, -2.5015011816022095 55.90879319802526, -2.5053309115307494 55.91176058163618, -2.5151769209371126 55.90932974324467, -2.522012305647366 55.90910782831963, -2.533731708589631 55.911016275522414, -2.535916705888095 55.91459174127554, -2.5543991831106263 55.91152694098315, -2.553783684936034 55.9099869855679, -2.5627108439858812 55.906637299119446, -2.5584846730493584 55.90528636783825, -2.5584895935446594 55.903399501434045, -2.554571099017281 55.900038844341594, -2.558388531632742 55.89859751455477, -2.566445714292805 55.89731178566566, -2.5700159912513163 55.89214684710259, -2.5665454100407277 55.88879356215095, -2.5606111832450384 55.88583766987832, -2.5526052748529042 55.88438234532831, -2.5486523483532255 55.88237844577011, -2.54626857078913 55.87996307514033, -2.5500553485112007 55.87815816361745, -2.5451764997687847 55.87730839939187, -2.541839060365434 55.87580915027162, -2.5388603586824336 55.87249774022744, -2.5350999418653313 55.87214578079245, -2.5327101604279725 55.86976161177264, -2.5340199774063636 55.867162881992584, -2.538283752892985 55.86316660395721, -2.5348339598198457 55.86105226851317, -2.538366794240336 55.85820028904578, -2.5426808212341916 55.852516271130305, -2.5443473197257886 55.851188035369034, -2.5431137323637576 55.848053215004605, -2.5471033314671065 55.84498966426969, -2.5481134131615932 55.84300839158306, -2.554876440507973 55.839092060342125, -2.5643452370634376 55.84240492923887, -2.5685488206053915 55.8453955155088, -2.5730223776479186 55.846071169190125, -2.5808946639229844 55.8454636752947, -2.583914801737604 55.84239442431601, -2.581890767428146 55.83998251093665, -2.5839495220647883 55.834586207513325, -2.592155826634933 55.82934006620783, -2.594173146877981 55.82867443117952, -2.6048666825246594 55.828563912891035, -2.6056560892650675 55.83210920865485, -2.6099048765077026 55.833777377684385, -2.622846660727187 55.83489408085549, -2.6260577300475068 55.83302683279992, -2.6313292674502065 55.83567740367219, -2.6338216188969668 55.83578144793682, -2.6424166661167874 55.83367472818203, -2.6478830751813716 55.834054849881106, -2.6474894275777263 55.837749831978854, -2.643230988056568 55.84093044132164, -2.649252417678568 55.84389089247437, -2.660483805607876 55.842290140246874, -2.665443620870689 55.845650820736736, -2.669260045527127 55.84655109699582, -2.672510091498281 55.84562586350815, -2.68696630408309 55.839471962472295, -2.6911250211459437 55.8416679917337, -2.695980327917227 55.840378202730555, -2.6961904319361514 55.83649545816585, -2.699833818693856 55.836223178929906, -2.705228838088743 55.83701454030772, -2.723823956698567 55.83453438763785, -2.7350718045102305 55.8302985730712, -2.7412630559184152 55.82889569331265, -2.7441312063337446 55.8302890060963, -2.7484694119583915 55.8300830282712, -2.754914507734083 55.83191705552341, -2.7586670484901203 55.836467386419855, -2.758279334877133 55.838698099404255, -2.7646324846785197 55.839004691052104, -2.7740967861322074 55.837570788919884, -2.7749983178319364 55.84235420841199, -2.777192984630483 55.84430360808711, -2.7861654857126803 55.835867932714606, -2.7939613121872973 55.83490584733739, -2.8022270320707996 55.83157524311352, -2.807006922505295 55.83173539356624, -2.811857823448212 55.82985608880874, -2.8185149447548645 55.82986136974489, -2.823133673677337 55.82633079364262, -2.831193714803418 55.8229115690864, -2.832797021826902 55.82100932143445, -2.8373860042331573 55.8195405634038, -2.8404490594240297 55.81763275496476, -2.844683294962767 55.81750035110394, -2.8462391937735942 55.818964169098635, -2.846639341939467 55.82268942815585, -2.8498811939849955 55.82423500171114, -2.8525651568085046 55.82726695863513, -2.8564535846734658 55.82842152999531, -2.860157891483428 55.830550276104105, -2.855364358353103 55.83363423935859, -2.8618686528548922 55.83673278642204, -2.865173704438141 55.83995863389277, -2.8689205113093843 55.83856289694246, -2.8736029261386045 55.843928079268736, -2.8775203057032948 55.84294057182523, -2.8800905798865797 55.84487918683342, -2.8804450386211142 55.847417772670454, -2.889367386966895 55.84724301577233, -2.894005046720428 55.848133094376024, -2.899042930398944 55.850919564850166, -2.8983094130395832 55.853118236248086, -2.901619243552507 55.85546618418207, -2.9010370403163215 55.85792255427811, -2.895607908971996 55.85879686745001, -2.8957441640687613 55.85985799252189, -2.900853290553704 55.86040376021266, -2.9103992685053224 55.85869280367856, -2.914045993538351 55.85676268370251, -2.9177792914745533 55.859469148565694, -2.919026433658813 55.86201704603953, -2.923735290191492 55.86263411196724, -2.927306391019485 55.860759859602915, -2.9314353962458 55.861389983064804, -2.937187436178578 55.86352165946819, -2.9358259315018445 55.867302259385504, -2.9362500562896328 55.871978592931995, -2.9376356682212474 55.87529444054686, -2.9414862760584346 55.876433068763774, -2.940660651155704 55.87831282089624, -2.948335004169757 55.88088488065162, -2.9490993387518407 55.884563886361306, -2.947269613242817 55.888987063101666, -2.9498776804848372 55.89175053226635, -2.962200036872847 55.8953981140947, -2.9555967333308226 55.89953875279742, -2.957433471332123 55.90047692018447, -2.966994053421102 55.902659376658335, -2.96596799760955 55.9107289707863, -2.968878847937762 55.912498690771294, -2.973996070305207 55.91285903816486, -2.984238061087097 55.91241370755991, -2.9888018514945816 55.91283274770982, -3.00327571631491 55.90893375148936, -3.007490718757774 55.90652537115346, -3.0095910070188787 55.90166331272542, -3.017740824803432 55.90163843082794, -3.0301694278735543 55.9061004721305, -3.034447412364522 55.908409829725095, -3.0415103438237447 55.90997662244265, -3.053375374876515 55.910501071525026, -3.061060664026764 55.91595205377677, -3.0713079137920793 55.91976034292291, -3.0759213869316544 55.91902018109963, -3.0792113474840863 55.920407444015346, -3.0790481619221572 55.92288166257942, -3.080411479355196 55.92552574746386, -3.0827848225682075 55.926786302253, -3.084727638374523 55.93016380943512, -3.088572977281586 55.93138963270952, -3.079620605011012 55.93408682598375, -3.0839749088884147 55.93862747387281, -3.0814702531881624 55.94146819882502, -3.082390785141178 55.94473981878943, -3.07928625855397 55.9450905270492, -3.074951175849112 55.94956897503399, -3.0714293507771937 55.95071737929303, -3.066190935287902 55.950766506622664, -3.060269576972534 55.95336942866157, -3.057167982105687 55.95567652951388, -3.051756322065769 55.95745516427118, -3.0470858635467652 55.95728295141717, -3.0402895898020317 55.955299915286304, -3.035042150259474 55.954733104270474, -3.0221038215554077 55.951539972518376, -3.011937790657668 55.95257992127646, -3.006348640613216 55.95597723224097, -2.999928479340967 55.956250476828046, -2.994677916127436 55.957983156932, -2.991822346647665 55.95817864358219, -2.9820940386164256 55.96161437562496, -2.9783344758419217 55.96471904422012, -2.9770796187321045 55.96756203609787, -2.971336897793579 55.97027779388094, -2.960249459923543 55.97182031994546, -2.957307403371321 55.97342908981732, -2.9489421760913044 55.97554505267077, -2.944865333891122 55.97546858443785, -2.9401950412175677 55.97714587036224, -2.9368887643937214 55.97693390839472, -2.9319657230713 55.97505731493979, -2.9254618590413823 55.97687912758933, -2.91973091415012 55.976921130127536, -2.9156429286054135 55.97814301763578, -2.913045078790977 55.98030975187472, -2.9084374055570152 55.98119013555291, -2.9058761326086056 55.98303118693779, -2.901324588089187 55.98971801372183, -2.900705572056848 55.992806241767774, -2.9007639659540443 55.99876563292222, -2.903498582092394 56.00395252065681, -2.9017160622936897 56.01128029916806, -2.8984995368651116 56.01504966113892, -2.8915416046966107 56.02014436909065, -2.8824303567702625 56.0273575235727, -2.8660571852590664 56.03801564992778, -2.861227998236036 56.039465540776305, -2.8545366402384538 56.0393997967356, -2.8450794099480388 56.04085039747151, -2.841568789925745 56.04231562554614, -2.835363705825906 56.048352564161185, -2.8346632830176093 56.04989374266943, -2.826272804323984 56.05445973770793, -2.817667921330169 56.06271940052356, -2.8161860596481625 56.06593411540721, -2.807707509819085 56.06333669687105, -2.801512111535554 56.06561702113508, -2.795899233270756 56.06602800449217, -2.791917494993655 56.065237846325466, -2.7883516137503617 56.066797016402646, -2.781412262569539 56.06660581710283, -2.7793165950266507 56.06518953378923, -2.7739056449762884 56.06791370231793, -2.7707524449811824 56.06790918425047, -2.7684886902558663 56.06513079175939, -2.757376358876679 56.062032334987386, -2.7515988204388546 56.06108203399082, -2.7470554812041126 56.06306920461038, -2.742692978044774 56.06403805128437, -2.7347656727915073 56.063370340464346, -2.733254187585592 56.06259939986157, -2.728291320329816 56.06334575773987, -2.724990424917174 56.06237957027422, -2.7213365791396886 56.060131430952005, -2.7175141662165267 56.06304771936747, -2.711477063230734 56.05998648712495, -2.706273822649905 56.06050250153349, -2.697482923274568 56.05924972021687, -2.6948923838960916 56.061011837019606, -2.691376676917597 56.06117539364243, -2.690252573530191 56.06324545092469, -2.681224495601764 56.062018887259605, -2.6785120025512765 56.063479526158275, -2.6743040933314104 56.0606229746983, -2.6701912077426293 56.05922394162032, -2.6609678087407667 56.06066459756617, -2.652131037395066 56.05983917526971, -2.6512698656199993 56.05752199526919, -2.648609414768442 56.057635802719616, -2.6467501904718915 56.05497253876188, -2.6390211676708373 56.05530302966729, -2.636332395493768 56.05378680392987, -2.6324911516645813 56.0535522699166, -2.627277660324355 56.05423755509832, -2.619888354637946 56.05131885436732, -2.6180155559865828 56.04906230385359, -2.6127818556260514 56.04572178277785, -2.6119030652041477 56.04314213603668, -2.605725190614356 56.04183840810042, -2.604112742231898 56.039417698763664, -2.6067431913489405 56.037253811049396, -2.6031646406898026 56.03275652887134, -2.59557530401289 56.027407928133314, -2.592663093140157 56.02699063036289, -2.5881639022403067 56.0246537023504, -2.5809212290858987 56.024308804145384, -2.578614951447217 56.02189920181205, -2.5738375127161484 56.02082263990329, -2.572755855206228 56.01776202766685, -2.5661650598686196 56.01198562264839, -2.5616093995652105 56.00884290928532, -2.5531947881209924 56.0048234009573, -2.5482535848365053 56.00432522227332, -2.544972788231904 56.00717627479217, -2.5304756477127373 56.00776155552185, -2.525656274677805 56.00738958633992, -2.5220030828747486 56.005842648551, -2.518416032010382 56.005500202705996, -2.516146063957166 56.0065169055862, -2.511374268714409 56.00632112911106, -2.507611250450517 56.004665538080886, -2.509336828203186 56.00223788789124, -2.5059814485009513 56.00105581166177, -2.5009377136801842 56.000987487550006, -2.495457523082721 55.99949837579384, -2.4905150634244477 55.9997993772982, -2.4763497082649386 55.998265529100976, -2.47409031019751 55.99705948413829, -2.470407253310215 55.99728566646989, -2.4652736512880105 55.99368603460215, -2.4670646856893304 55.992385459981904, -2.4631107260631158 55.98923414523771, -2.4576756865735314 55.99226169881032, -2.456795884856118 55.98983634791992, -2.449428218275725 55.99185623224245, -2.4426070827099062 55.99043801467188, -2.440737800874783 55.98759923633766, -2.4381036161396605 55.986963525440714, -2.4372722217106166 55.982748964161104, -2.4337996189995277 55.98049708716356, -2.429412442143885 55.979530427155765, -2.42640178040154 55.97710687714576, -2.4179069803591786 55.97765623355932, -2.4142468605366574 55.97628937199723, -2.413927281683679 55.97427519289474, -2.4164611402434133 55.97209861245052, -2.410157869393999 55.97072715286869, -2.4054490356955207 55.97208414561456, -2.4024111341077625 55.97161966424215, -2.3970404994487255 55.96784910321344, -2.39347375281464 55.966993581701225, -2.3927698251830964 55.96519075811856, -2.394084882836098 55.96202930132736, -2.391477664694156 55.95780033148092, -2.3855836052385144 55.95408662023773, -2.3838019865498494 55.952060759946015, -2.3807156422322153 55.9523389978247, -2.376891279767334 55.94951784780695, -2.37391277913594 55.94866885286348, -2.3708836030744127 55.94971303718129, -2.368994927878708 55.94844646426849, -2.3632806956081254 55.946622451423146)), ((-2.784577096238167 56.073751201881194, -2.7819476996352703 56.07353246348588, -2.781428246211496 56.070648029228884, -2.7864544121297135 56.07001500397773, -2.7867387867831637 56.073090534594705, -2.784577096238167 56.073751201881194)))
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>