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/S02001356 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02001356 geosparql: asWKT POLYGON ((-2.5313614516890572 56.70608848334395, -2.530957463571262 56.70537548191231, -2.5283262825125057 56.70514051446666, -2.5254020454426467 56.70414939381767, -2.52453866531832 56.703604122744196, -2.5229000412552893 56.70156270650406, -2.522473645596711 56.70072630722441, -2.521962170340071 56.700348437002916, -2.5209415031630593 56.70011014778933, -2.519043011928887 56.69933109333186, -2.5164106399061206 56.698615246773684, -2.51526864749942 56.69857415951327, -2.514767297482011 56.698810710019885, -2.512614126875662 56.69862194767678, -2.510243266810407 56.69863527735771, -2.5082857144024353 56.69878253109607, -2.5042857841097206 56.69896499225843, -2.501969584853235 56.698792876943436, -2.4996023423296125 56.698956917256744, -2.4983460854218955 56.69879485205806, -2.492730083563118 56.69914870020564, -2.49094781445269 56.69947106993284, -2.4886795750624766 56.7008545102009, -2.4882048454006167 56.70101808018742, -2.486876802397988 56.70098914073969, -2.4853295566550404 56.69978955624, -2.4838487086186536 56.69942967839787, -2.479844640323019 56.69981440404307, -2.479975505757944 56.70047330924836, -2.481132277481804 56.701031230283604, -2.4817497889862725 56.70181492385452, -2.4816164221940253 56.702368840443654, -2.4804695371747236 56.703999333844955, -2.4796871180067 56.70437427807981, -2.4778108019789236 56.70452073907289, -2.475887542525478 56.70496022211953, -2.474692271670063 56.70433142759828, -2.473113445552375 56.70436887836203, -2.468906153532091 56.70238500249404, -2.4650659800706562 56.70179569257779, -2.464636010009506 56.70122772640544, -2.4627126423778534 56.70165712462508, -2.4615797077924246 56.70155801546919, -2.456315282090477 56.701741818956116, -2.455143483564902 56.70193925797558, -2.449972322374059 56.70214491181705, -2.4468363181466044 56.7021058941652, -2.446272366460392 56.70219865232708, -2.4446016316471386 56.70205370096819, -2.4418687738722684 56.70227274904119, -2.4402959080034283 56.702116612181285, -2.43916788508863 56.70173429361799, -2.4378459095764717 56.701804529938876, -2.436966522503596 56.702158883517455, -2.4361975472805297 56.7011895368334, -2.435663867199777 56.70093536790596, -2.4365855043945905 56.70000052448102, -2.440574409612017 56.69897849809013, -2.4410146105805794 56.69836065375841, -2.4415876731252335 56.69821308597658, -2.442487501384161 56.69724683221469, -2.4427394133649085 56.69589477824215, -2.441517404187046 56.69528103379899, -2.4413734998305174 56.69484403441728, -2.442311795783133 56.69396209233794, -2.443478896799348 56.693519533132864, -2.443476096289782 56.693003874575616, -2.44296737036012 56.69264453771012, -2.4418284076600725 56.692282046384804, -2.4419155795590366 56.691779544109394, -2.4403999703664296 56.69173550312273, -2.4394451028057555 56.691895194370254, -2.438894150765335 56.69155036397118, -2.43910835421345 56.6907374756538, -2.439749462086179 56.690274345453005, -2.4387798146586284 56.68916108297758, -2.4404976699915446 56.68947753494271, -2.440919263187581 56.68937183090793, -2.4399365714863106 56.68854071406192, -2.440808351034857 56.687425438913984, -2.440548639492911 56.686993339947904, -2.441192307617973 56.686616437117735, -2.4419223383168336 56.68664529132694, -2.4432199315908734 56.68621305087984, -2.4442852331311435 56.68615714809333, -2.446523864949941 56.68496777196749, -2.447390117458527 56.68396027483528, -2.447772733058606 56.68401549720957, -2.4491463542137897 56.683401448529494, -2.448975077332895 56.68299959253292, -2.448204356830564 56.682563062205226, -2.4474059675461355 56.681581310455414, -2.4463179414993608 56.680809016173754, -2.4469844121349635 56.68002862866429, -2.447665869331494 56.680100745592135, -2.448020095269234 56.68079212178611, -2.4475500999781885 56.68121066019933, -2.448437081506188 56.68154436066114, -2.4495529556389317 56.68122410683214, -2.45011727771955 56.68146283346649, -2.4506449302828477 56.680954238707834, -2.4503017556521147 56.680372432213055, -2.449685832926021 56.6801851004264, -2.4496940740078705 56.67964424622419, -2.451413700757433 56.67850067413219, -2.4529391853675535 56.67818698905475, -2.455187986859359 56.67817249829841, -2.4579529140929646 56.67765297652916, -2.4590847307523247 56.67758592129816, -2.459279822688349 56.6768539201308, -2.460505859628089 56.67608486911624, -2.461761892804078 56.675637314862115, -2.4626099357289277 56.67585696477072, -2.463551685421991 56.675733078589516, -2.4642437549599725 56.67534509428655, -2.4650936363925773 56.675977975633245, -2.4659708267618154 56.67591270708534, -2.466535427465678 56.6748522997214, -2.4662973000009507 56.67446688806105, -2.466889277654309 56.67403883659958, -2.46785716570292 56.67392200671732, -2.469126364695386 56.673102398331466, -2.4694151642745092 56.67231253070302, -2.4689066334600445 56.671572384111776, -2.4680402609874137 56.67118574698854, -2.468157204596485 56.67087895908813, -2.4694138342578165 56.67089399110736, -2.4704929379376157 56.67172092026905, -2.4707310168588625 56.6722311993619, -2.471410198847276 56.672520603231774, -2.4753884413501748 56.6725108647399, -2.476188047010507 56.67225356652657, -2.477568742068224 56.67213957309955, -2.4808873835731258 56.67236127505456, -2.4810677187973456 56.67165894180236, -2.481996129819967 56.671781124014345, -2.4833612782861096 56.671730013248286, -2.483910115924698 56.67139188593426, -2.483536102419458 56.670856106591614, -2.483662545537158 56.670027306670136, -2.4842400133821063 56.668616397489224, -2.4857291172427196 56.668063480525724, -2.4861889229718352 56.66816589787921, -2.487662082072245 56.66789780739446, -2.487827819124529 56.667465934063266, -2.4891630621720124 56.66751190189453, -2.4909577610873583 56.66675468610336, -2.4914263127636547 56.66677709351246, -2.492625369323166 56.666015914913615, -2.4926536507545753 56.66543275196164, -2.4936038507819025 56.6649842875451, -2.4940046475287274 56.66444366716667, -2.4948685739722443 56.66413747999404, -2.4955628968607497 56.66421018185618, -2.4979523101835475 56.663046222065525, -2.4996299196779095 56.66283915959174, -2.502695570435558 56.657100509648366, -2.504844003051345 56.652480398488265, -2.505276775322422 56.651913557155545, -2.506298143124009 56.65121405497914, -2.5077324098860783 56.650781477974384, -2.508741868705192 56.65077735540123, -2.509711788631104 56.65146873792148, -2.510929420563121 56.651781773757655, -2.5112662052339534 56.651119177969335, -2.50955729494607 56.6504137661644, -2.5083832205862047 56.650303574451776, -2.5068891037729024 56.64955592269273, -2.5062543845208443 56.64867988408996, -2.5064995136679737 56.647501999669814, -2.506756866770037 56.64492707238565, -2.506933845428704 56.64146845719753, -2.50658255914527 56.638738787895974, -2.5059066716850773 56.635991570656884, -2.5045673624290923 56.633117673046456, -2.5039851587818402 56.63224320510563, -2.5023293919622533 56.63043335856828, -2.5008233323458975 56.629576976811315, -2.499555133426133 56.62957039666331, -2.496075954829333 56.629755012601244, -2.495606692480628 56.630016517345204, -2.49216016012446 56.63008410307655, -2.4908576248125645 56.629693958102706, -2.490190910140597 56.62981517423107, -2.4874056631557484 56.629591638205966, -2.486732562776864 56.62909117588132, -2.484206768141376 56.62863027683058, -2.483157266618584 56.62877091237598, -2.4820483087937166 56.62808435363443, -2.481354886415384 56.627900173848595, -2.481125564447957 56.62742671179734, -2.4817600981770305 56.62721133797188, -2.48187652025419 56.62649936317298, -2.481090692152159 56.62558335295244, -2.4801177908132273 56.62494835724078, -2.4801561008079434 56.62398693315062, -2.4817554272089946 56.624159528965386, -2.48271017687905 56.62311728977349, -2.482735024835895 56.62263835182037, -2.4818525525925454 56.621678699908685, -2.480735893942284 56.62164978012702, -2.481111067032779 56.621165894453746, -2.4820887727366183 56.62090606800567, -2.4824897204830445 56.6211668431823, -2.4835641939469397 56.62121118382838, -2.483657080694911 56.62082900708418, -2.48526940107755 56.62037263418368, -2.4859477439768205 56.620026800993365, -2.485710189160327 56.61929374421984, -2.4865166908394216 56.619158528979796, -2.4871647682231934 56.618742732957315, -2.487454681987762 56.61772102579422, -2.4867023343835504 56.61699717415472, -2.4875077758897004 56.616783796502524, -2.4878836967654054 56.61611571673538, -2.4872333629421215 56.61559360587248, -2.487648015572104 56.61477085172864, -2.4883842836040726 56.61412561338562, -2.4895136814272987 56.61377080100318, -2.4900456826036175 56.61333388475023, -2.4913533652947915 56.61328650114045, -2.491596528040996 56.61244015408737, -2.4920258284218177 56.612001838290695, -2.493681289388999 56.61089295170985, -2.49403778598505 56.610122512785075, -2.494977582100203 56.609359634894645, -2.4948626414545045 56.60854345396489, -2.495320709845896 56.60782022154999, -2.4965186160754964 56.60711919073994, -2.49610124391404 56.60634734053064, -2.498507646299074 56.60563786990625, -2.499892127979961 56.605136399644465, -2.5007399963791013 56.60507638983651, -2.501595383296195 56.604355126684105, -2.5024075360899345 56.60393768905335, -2.502315499829022 56.60301720781821, -2.5030136026606606 56.602354965298126, -2.5042003785483025 56.60194228854699, -2.504625235288657 56.601556951180314, -2.505213207968025 56.6004585235014, -2.5048068377149826 56.60003074158068, -2.50485214303585 56.59939808836639, -2.5044439324467285 56.5990754247871, -2.504556707518522 56.59849460472724, -2.507302162257803 56.59761378887799, -2.5086265544753097 56.59763982249657, -2.5099929989999734 56.597160771853964, -2.510828098408592 56.59653116295378, -2.5123979680229285 56.59604675781239, -2.5133567798257714 56.595898161500294, -2.5135845603716 56.5955225902163, -2.5130293653028835 56.5949310430449, -2.514845750298552 56.59473846614111, -2.516142039929444 56.59414374477686, -2.517769894318773 56.5929106670979, -2.518583854653969 56.59170522153595, -2.519143396044545 56.59130489720051, -2.519582032479597 56.59051966371746, -2.519537308979952 56.58998979693302, -2.518936408748575 56.589153204394556, -2.5184276357053133 56.588978342807245, -2.5191676262083162 56.588441607707395, -2.5188177206660924 56.5873838590088, -2.5178761864243815 56.58687390164408, -2.5183705606216846 56.58599949836863, -2.5197925289087495 56.58569080178425, -2.5200708461104067 56.58497361562537, -2.520793968345926 56.584638181743536, -2.522568737258276 56.58441781451213, -2.5231537040899648 56.58398322535005, -2.5232858707854255 56.58329809044575, -2.5230527717235938 56.58268726280618, -2.522267764567275 56.58195477563232, -2.5211719972272997 56.58205999462191, -2.5209227412126576 56.58121834256463, -2.522669292574488 56.58097024130731, -2.5226638397446344 56.58045727920178, -2.5235364929047774 56.58023080463431, -2.523412340092642 56.579845914786944, -2.524277292969741 56.57941732785651, -2.5256437548126485 56.579235471547, -2.5278167021193663 56.57934036121919, -2.52919897338631 56.5792428481053, -2.5311721342961695 56.57891370470464, -2.532590203643222 56.57856742749626, -2.5353071475271927 56.58003789531856, -2.544065668535834 56.5837730845444, -2.5526415229202395 56.589611926761144, -2.5554105082352865 56.590701743476565, -2.5567131171382784 56.59044300100191, -2.560521569537937 56.59070409785831, -2.5578181928961787 56.59565185536209, -2.5546257703115285 56.60005930553791, -2.5520528875620623 56.603439721895356, -2.5506920556657366 56.60618587125384, -2.552707637127035 56.60588944347368, -2.5548078054362486 56.609141268351195, -2.5556238083491776 56.609211707335135, -2.5576667379196705 56.610987271463, -2.560372749054165 56.6100180934075, -2.5632144114686843 56.61186755120281, -2.5673188226997183 56.6103228558654, -2.5717873305641064 56.609432710001435, -2.5741361393547293 56.608550445110836, -2.5751609782959473 56.6095249623655, -2.5771046348018265 56.61412473227631, -2.5718788769968373 56.61548747766408, -2.564577684542068 56.61756019652717, -2.5579191060705098 56.62016862219865, -2.557942575678074 56.62065365864259, -2.5607822623035497 56.62093735069025, -2.567332075140594 56.62628903200506, -2.569227353485204 56.627681868712024, -2.5657658490436313 56.62944952518155, -2.5683813632515298 56.631036743527034, -2.567283398851344 56.6317335171535, -2.566427459999345 56.63335452373871, -2.5678545220395415 56.63502801290152, -2.5721579469836993 56.633930235873486, -2.575443934635825 56.63347486021027, -2.5739799867808855 56.63475734925321, -2.575871144074566 56.635835657196644, -2.5772402346559313 56.63794952009422, -2.5736770779318254 56.63950224959691, -2.5748008586990885 56.64049427879813, -2.5828120008472317 56.647203939812144, -2.582792556563564 56.6480575028436, -2.5820162560100126 56.64953449759347, -2.5801123030564614 56.64980392051443, -2.5811147947756425 56.65242254511009, -2.582367533170319 56.65327914469393, -2.5812454078228106 56.653491020103054, -2.5818031397214845 56.65581524549992, -2.5871205394342507 56.65476611053511, -2.5899017786604226 56.65739422859648, -2.5909269518343914 56.65723664824582, -2.5925955930986158 56.6617026905224, -2.596256791537146 56.660077087762964, -2.5985330695732762 56.664746768207834, -2.5920956420164663 56.66519082232905, -2.592915697042221 56.66754069956893, -2.5940744971173455 56.66963740582563, -2.592104653275386 56.669925290957295, -2.5947873696556862 56.671385860542586, -2.5935945649149654 56.6712837469356, -2.590579108724672 56.670453602885175, -2.5883512157671453 56.67094029779569, -2.582889662283451 56.671253473392035, -2.580252874477994 56.67168803350783, -2.5793748467429487 56.670829670384485, -2.5771473354519827 56.67135209813968, -2.5762993096088485 56.67245205961808, -2.574664986124232 56.67228892070707, -2.5744949361695446 56.67290960185571, -2.575042030923973 56.673473051116844, -2.5739230904746355 56.67393639188796, -2.574011183965621 56.67543629222704, -2.570565816018502 56.67638645166651, -2.5686404689139892 56.67641322796216, -2.5677391874597704 56.67725284050771, -2.5652938841873647 56.67743465154582, -2.5649232825885577 56.67993385565858, -2.5634946069055435 56.68044342567711, -2.5639605810048214 56.681043234297334, -2.5638454728277167 56.6820768989371, -2.5620007508957605 56.68205828741982, -2.560748391606452 56.683456430761545, -2.5615209972976887 56.68491732544732, -2.5603104624044146 56.68474309262193, -2.5604519881698002 56.685479140194566, -2.5609570361625456 56.68650999936967, -2.561912213729017 56.68707167500115, -2.564065900543862 56.688086096210384, -2.5639079651321746 56.68953321049836, -2.563501919187054 56.690765834990756, -2.564744459532451 56.69197302478897, -2.565757420518667 56.69419641913116, -2.569735558673638 56.70029627547809, -2.56777047732525 56.70017300717051, -2.5647122548495416 56.70399353786228, -2.566986950158596 56.70913435612783, -2.564940395451075 56.71049677903685, -2.5583672223261207 56.71005028378409, -2.5516562948799875 56.7102239260244, -2.5516843109091654 56.71213735240929, -2.5427656490625266 56.71216754822661, -2.5420243209922204 56.71059860234202, -2.5409317248703105 56.709588191400385, -2.540067460336931 56.70854982068154, -2.5390536701807402 56.708473348948715, -2.5385479117604683 56.707370538026765, -2.5365299421375482 56.706741387817246, -2.535093728145359 56.70681943648181, -2.5339689477857483 56.70611368070772, -2.5323070088673316 56.705823439550024, -2.5313614516890572 56.70608848334395))
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>