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/S13002734 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S13002734 geosparql: asWKT MULTIPOLYGON (((-3.4116356158949763 58.915074833096085, -3.4067412567663453 58.91778404026287, -3.4053095894685597 58.92046005019861, -3.3944365396960134 58.923795890312995, -3.38773786321978 58.92177966785805, -3.3824325942121454 58.92331850007532, -3.379178990366255 58.922958069466496, -3.376016189036137 58.9264973026334, -3.372012103546924 58.926622451368836, -3.369925013575226 58.92874990828483, -3.360388477875831 58.930836388215404, -3.3571552432258867 58.9324259816841, -3.3525175059564516 58.93284997691382, -3.3487340905206664 58.93068449553653, -3.3444056987434507 58.929991301694564, -3.3453611684760154 58.93271360480162, -3.3419711438318895 58.93305779213769, -3.3382851846269443 58.930925118472956, -3.329762463568847 58.92948703749899, -3.3255306091456176 58.92826407671268, -3.3230701473218995 58.92638248380266, -3.322001635117869 58.92374289104729, -3.319455776478093 58.92311503945362, -3.3211223820154414 58.919913160632056, -3.3201487169647086 58.91801990774416, -3.315564704753229 58.91831094638211, -3.3108243269951703 58.91521104344455, -3.3137585893386525 58.91012373173113, -3.3128586492039145 58.908967035821796, -3.2999312363601963 58.90642290562142, -3.2935419073119974 58.905752332768685, -3.28578019336439 58.90570136306201, -3.2823149464283192 58.903777734045654, -3.2757943224048964 58.90135884325372, -3.2684968828023533 58.899975706658886, -3.2640779474032646 58.89684403166522, -3.2562450677763426 58.895492293520235, -3.2445696285126613 58.89029715894405, -3.238922398130577 58.88692496325002, -3.236354530202781 58.88838214586034, -3.2319588929740934 58.88749004456324, -3.2264951529933796 58.883370133986, -3.2220632757212 58.882159203517055, -3.2123481029387713 58.87818210073736, -3.2099029444818674 58.875717142405634, -3.213025025843174 58.87373881433483, -3.2198700502126663 58.87382260962987, -3.225317377091271 58.872392435811086, -3.2234951378667405 58.86965685176217, -3.217309763000354 58.86932011897601, -3.214612340153947 58.868061071047194, -3.211627423776302 58.86451898818651, -3.2162016185981406 58.86195669231657, -3.2153592894562997 58.85968782906842, -3.211145019364014 58.85741461856523, -3.201729929652723 58.856357477528135, -3.198944230756018 58.85455382031438, -3.1967198343968812 58.85157638652221, -3.199589242345674 58.85044778138756, -3.197829125887557 58.84826365227825, -3.1987567705345197 58.84632403424907, -3.2018493956049716 58.845701600709006, -3.205300210165581 58.84272164896824, -3.2101419294867575 58.83994783707798, -3.2058627281249645 58.83801636243396, -3.201181368611876 58.83916835967721, -3.194556635011527 58.8388427375503, -3.1904132419560343 58.83357023117047, -3.200305836269111 58.82958868312769, -3.19859649386455 58.82673587623539, -3.1894153476256837 58.82770459545495, -3.183876065611233 58.82617566898215, -3.1790147124627746 58.826131270464835, -3.171443700785025 58.823907159144554, -3.1677294001417464 58.81918692207568, -3.1736581870435443 58.819178042148756, -3.1799544119730054 58.816478311608265, -3.1843409319964966 58.812995511529174, -3.1864470347370197 58.813626423545, -3.195435358019972 58.812345325083236, -3.2014976349446864 58.80942392204719, -3.201815746306593 58.805008323410654, -3.2032074122576897 58.80405767660044, -3.2093465276440987 58.80524064612018, -3.209905242259182 58.806375204234364, -3.217746511032391 58.80513740471598, -3.224591336233673 58.80176825290656, -3.233121680368615 58.802190017904714, -3.243428747056208 58.80074388381385, -3.2481391626392155 58.79884637917396, -3.2512533087742037 58.79463887661987, -3.250717061301556 58.79036248655605, -3.2560997052992837 58.78739117079742, -3.2524580767936753 58.78600384198631, -3.2499629473296405 58.786806801764364, -3.245749713550009 58.7862610454427, -3.238449610428375 58.78384790512589, -3.23179891473728 58.78571961512551, -3.2277994168005346 58.7859229605692, -3.224695639086241 58.78758800170797, -3.2193316476197236 58.7926927607462, -3.2150601710967686 58.79563328992892, -3.2132467191318326 58.79915585761276, -3.2088892426612756 58.80065441157189, -3.1960622372552283 58.7991276548497, -3.1908435101125416 58.801274047082785, -3.1848099229391713 58.80166908696684, -3.1823033073625058 58.80313095930745, -3.1718696389271144 58.80291807068461, -3.166345217069777 58.80174124238154, -3.161904928609697 58.802543794028324, -3.161049139805921 58.804282278138224, -3.1573585223843983 58.806087424784444, -3.1498352248915085 58.80690648695358, -3.1385632744962706 58.80311650243452, -3.1381818418360266 58.79781090785907, -3.146143208724946 58.79248452410664, -3.1470530189723775 58.78990496123363, -3.150789644854617 58.788637615859706, -3.151725276979601 58.78695424354975, -3.1460687245611427 58.78697140198701, -3.142993173355297 58.78914258946802, -3.129591753177317 58.79042107023661, -3.1317157907011524 58.78647031711146, -3.1387903834538973 58.78400637010913, -3.1433570728840827 58.783846551655614, -3.1530748042066725 58.781530842222416, -3.1608420793436376 58.781398317671524, -3.1721607964590013 58.78014538422964, -3.17947089791007 58.777510031071344, -3.184338374336089 58.77777888258626, -3.187128454947347 58.776723070089936, -3.19362315807958 58.778094739758345, -3.201602189280316 58.77735961264401, -3.207924313953627 58.780315718144536, -3.21666710965445 58.78132925702618, -3.222998332868251 58.78354979157778, -3.232299864008122 58.7843836828424, -3.2336766277613007 58.78140302780869, -3.2249343610878904 58.778893374097585, -3.220224433617819 58.776426756666396, -3.2210301680686766 58.77469371263221, -3.2311352023349005 58.7713247667014, -3.2376327309960207 58.77246155114427, -3.242221130647231 58.77465574544088, -3.2416413577838465 58.77614593294035, -3.250003275812987 58.781243139949986, -3.2553907217148264 58.78127072917756, -3.2595901346989065 58.78006124506822, -3.267720610699746 58.77918495737529, -3.2703068614439874 58.77981337204275, -3.2737530354159463 58.77794171278231, -3.2780590472237554 58.77928854796305, -3.283018578549401 58.77845883876819, -3.290109063593945 58.77540163426852, -3.295772847530546 58.7763239428651, -3.301146082373533 58.78079661449562, -3.3002120304491704 58.78357243029155, -3.306821369772863 58.78567474042621, -3.310538336107238 58.789737198641284, -3.3140876837880953 58.79209018606574, -3.3181203372186805 58.79321310867753, -3.3197701759682325 58.7956967686918, -3.322434633252383 58.79613658265476, -3.3248018562273893 58.8017168452819, -3.3231733891782618 58.8053128412537, -3.3287181019588488 58.80785875594235, -3.3275873775382667 58.809117064493684, -3.334756563163682 58.812374485576555, -3.335370144682103 58.81369741871925, -3.3292807113012493 58.81654464035288, -3.3326775167024314 58.81887625506197, -3.3409353365682906 58.821063182680916, -3.3434034722454644 58.8224161851265, -3.3436284618602574 58.82442572252336, -3.35233723117139 58.82746493224509, -3.355874669642966 58.83089030019491, -3.363598140193853 58.83369667010136, -3.3660671309093346 58.83568245429401, -3.369264860738582 58.83615608594607, -3.3709390969959494 58.840817844517865, -3.37351288670617 58.84236679558412, -3.375951739040721 58.84552935407089, -3.3744041360686907 58.849467242189284, -3.3765843438229175 58.850772496074335, -3.3761606816906906 58.85276195836758, -3.379210639502509 58.85666339962065, -3.3786901893216745 58.86079616326149, -3.3802005410179343 58.865419053424695, -3.3847981158079645 58.8683024606414, -3.392754880997358 58.87017044434678, -3.404704878361718 58.868913807102224, -3.410128915723291 58.86966760734223, -3.4191765588969854 58.87187683367641, -3.4229736255918204 58.87205963963554, -3.4328134698772184 58.87073921962606, -3.435710041891584 58.871877424186216, -3.4366304961207303 58.876632954879575, -3.434609688604712 58.88061195296293, -3.4295041067540404 58.883425894071614, -3.429910795104187 58.8867626714823, -3.425531439349407 58.88975706020643, -3.4237749538408204 58.89535864439706, -3.4240056332280018 58.90075415520794, -3.4197950157547545 58.90537673786858, -3.4188078154554487 58.9083965143152, -3.412729530562321 58.91481676498827, -3.4116356158949763 58.915074833096085)), ((-3.251829368199873 58.98239401984452, -3.250188512925186 58.98046811245407, -3.256584003007452 58.97512689613218, -3.2608804668682256 58.973078699006585, -3.264676666806343 58.96745339116036, -3.2621859707130065 58.964448232191266, -3.264515537790606 58.961868483672575, -3.2686745881858967 58.96356654023417, -3.274320321546242 58.96383898119101, -3.277786872453455 58.96245392370217, -3.2782099138694942 58.96068314555252, -3.284274827778069 58.959940431241485, -3.286280984559336 58.954937649645025, -3.293458035516935 58.951754002750974, -3.294445553855407 58.95008697172411, -3.30478635433988 58.9492610120864, -3.3138755457253115 58.95036718492448, -3.316180404900546 58.952142788714575, -3.3271161195803214 58.95223041733868, -3.3339476814157227 58.956191114792425, -3.3334263551690198 58.95804400852323, -3.3359495963428523 58.95980714060358, -3.3426400886543663 58.961324938030295, -3.34557855007238 58.963375395870834, -3.3506244045134705 58.96202949365441, -3.3540447734454255 58.9622973319396, -3.3586406762816794 58.965705286312016, -3.3565329863575033 58.96619179135452, -3.3531986200886514 58.971544705540325, -3.3535362272355314 58.97376500957819, -3.358700933868938 58.97620509360033, -3.361110608705319 58.979432879967106, -3.3592427130429567 58.98505792865586, -3.3634912144373494 58.9917314460035, -3.3625359012353293 58.99279330387263, -3.364503566740438 58.99554700800879, -3.367453398256257 58.99698431886405, -3.367374519001653 58.99991320774796, -3.364834626382254 59.000346839318034, -3.365066165254341 59.00302984008417, -3.36161803540798 59.007672809943834, -3.3497476694988504 59.005601967531845, -3.340296422251995 59.00750363119452, -3.338390321210848 59.01141589540477, -3.3324236791859363 59.01098796754093, -3.326935706883655 59.012043927549094, -3.3256563505333356 59.015586730072755, -3.320084896257051 59.01571366170053, -3.3163299101214396 59.0142942369894, -3.312103883476787 59.01503944193539, -3.30356106649861 59.01474489576824, -3.2999617240110393 59.0152148359721, -3.2906753848026375 59.01152112745795, -3.2899022440021986 59.009802643132176, -3.277495166897701 59.00597464333438, -3.26811150833141 59.005322333570334, -3.266080314100588 59.00358271348369, -3.265279575706719 58.99965035679523, -3.261345053023509 58.996162659974644, -3.2622700176137482 58.9942316371551, -3.2675432554253443 58.993893610633656, -3.2743329391886977 58.995502873647936, -3.280234016281642 58.9959009731868, -3.282891224592249 58.9949028914784, -3.2756860624173894 58.990867770385215, -3.267598972929325 58.9897293021543, -3.265063007673125 58.98639412808875, -3.2571091047913105 58.98304518479717, -3.251829368199873 58.98239401984452)), ((-3.0896886821495917 58.81514337069127, -3.0922719704673427 58.817067782881686, -3.102307695755648 58.81990327730666, -3.103939594711732 58.81861846591804, -3.1044011072277433 58.81467523108939, -3.109328997927399 58.8138722794781, -3.1164228148202184 58.81491128968231, -3.1187437615554066 58.8158521996696, -3.1217622032211074 58.81410071012777, -3.1280059975791135 58.812676561801396, -3.1395006923544333 58.816338814920755, -3.1424388179534573 58.82091586953528, -3.148961881761976 58.82807457487409, -3.1483088365694982 58.830065257577594, -3.143108071769225 58.83387912805326, -3.131220145960118 58.835878912987866, -3.1291880532816205 58.83758526357872, -3.1298663128056403 58.84032317586864, -3.121527547519134 58.8432905585511, -3.1152929664443167 58.84329158251933, -3.1044510882167313 58.845042704481735, -3.094565743845523 58.84561630722444, -3.0838265433283283 58.847992703675985, -3.07543210125609 58.849454948383524, -3.068054456649987 58.84963298799829, -3.064123181247977 58.84509481218005, -3.0671697615880666 58.84335338261723, -3.080753149519438 58.84335264441113, -3.0828360597256754 58.84124251152815, -3.0903304073550126 58.839881652671245, -3.0962223019639232 58.83689489019494, -3.0994177513010777 58.83440231864534, -3.1027119043116196 58.83421251722662, -3.1078596796964764 58.83565489055273, -3.110947073074613 58.83339020975831, -3.1092893859242583 58.83106215772605, -3.10105217792921 58.82912976811536, -3.0920745273711825 58.83022718605737, -3.08799465151261 58.83175256382363, -3.0792039200545576 58.833264299301206, -3.0760328780420507 58.83111458110545, -3.077188744785137 58.82845090324208, -3.0817717569590575 58.82639271092558, -3.0822970105487615 58.8231325955244, -3.0782384328952133 58.81624094491031, -3.082023613857964 58.81463483198871, -3.0896886821495917 58.81514337069127)), ((-3.315420053502681 58.939891593372955, -3.3122984999083314 58.94078905281017, -3.303736878637187 58.94079660787292, -3.3009410317851877 58.93955836082098, -3.290543351294633 58.93743150950729, -3.288711380878565 58.934855931334454, -3.2825826522716457 58.9326345784276, -3.2783423188623737 58.93419893790998, -3.2785992075618275 58.93790218857166, -3.273015603360982 58.9372692932148, -3.2706400546817704 58.933907503396554, -3.264946596728325 58.9299180326247, -3.2659924188857237 58.9271666215627, -3.2656911687701937 58.923968578985644, -3.2697333007755147 58.923222131553736, -3.278673977745498 58.91995997384906, -3.285013555406618 58.91946416394447, -3.2977578673822623 58.921840951353936, -3.301322896994368 58.92353232462823, -3.3077958765123703 58.924808848253186, -3.310002958245054 58.928597380999584, -3.310604451874646 58.931542685578854, -3.315420053502681 58.939891593372955)), ((-3.17146653457543 58.856963327248316, -3.1694268619634136 58.85713894102568, -3.159082833378297 58.854694933981456, -3.1628485321117887 58.850430866863675, -3.1568878557614566 58.84813570664146, -3.157894042228685 58.84608794570134, -3.1522092497062877 58.84450419018816, -3.148485638990846 58.83985353499154, -3.149619180037707 58.83693788359957, -3.157031611490709 58.83348124159834, -3.166250945282555 58.83254951384571, -3.1725718621838372 58.834288580538875, -3.175358049927891 58.8390593339169, -3.17564361179019 58.84109548547888, -3.181143102036327 58.84383854774024, -3.182101320039349 58.84678473971019, -3.179154709926408 58.85059287540024, -3.1753892235068406 58.85199684210407, -3.175892479093662 58.85456992136419, -3.1715094368123133 58.85566961963302, -3.17146653457543 58.856963327248316)), ((-3.1796732554195826 58.887692276550126, -3.1737672069069194 58.88661615499255, -3.1744639154247483 58.884445294314695, -3.1568879854886145 58.87816511836968, -3.157980380680527 58.87514562712247, -3.167591328787093 58.871507906047036, -3.1697118459465954 58.871749201472525, -3.1738042312265264 58.87532078033919, -3.173897544897787 58.87674532598718, -3.177346536221089 58.8788075465147, -3.1766298518239293 58.88472288085408, -3.1796732554195826 58.887692276550126)), ((-3.1091008901530244 58.79496197243583, -3.111867363224398 58.79851821789518, -3.101826351878835 58.8030411692259, -3.096522835829461 58.80445598007757, -3.0926392177268833 58.8042509845697, -3.0939832312739637 58.80213791922523, -3.098671778007376 58.79988865607346, -3.0989366470627786 58.79732221845544, -3.1091008901530244 58.79496197243583)), ((-3.2014233731276382 58.868521288746116, -3.198258829662281 58.86701932669259, -3.198616247712377 58.86356712092554, -3.1891975658030804 58.86117976704643, -3.1893764212503983 58.85855996097348, -3.1940801749450936 58.85696276071726, -3.20056607725045 58.85878874938383, -3.2028936676637096 58.862916614471516, -3.201414308351458 58.86450663050094, -3.2028117664718354 58.86630332678488, -3.2014233731276382 58.868521288746116)), ((-3.0820177490992395 58.85167219467124, -3.080531910763165 58.853215961810896, -3.070165617436622 58.85542188454475, -3.0655643336390934 58.85483213527333, -3.068757743082269 58.85277062775621, -3.078632699464302 58.851224546849124, -3.0820177490992395 58.85167219467124)))
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>