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/S02002245 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02002245 geosparql: asWKT POLYGON ((-3.173502821286582 56.53109299502113, -3.1740586757466223 56.5294776161456, -3.173022587845705 56.52620171873881, -3.173488021593565 56.52621798798954, -3.1771963471716935 56.52554499503848, -3.179306036650307 56.52532462885951, -3.181551753754246 56.524774993079866, -3.184136982748765 56.52338650708021, -3.1854141937432 56.52321619638031, -3.1860459949034032 56.523771707680595, -3.190376426080973 56.523720406228044, -3.1951708124393283 56.52420716560259, -3.200855596635297 56.52590974919726, -3.204831510893372 56.52579578319241, -3.2086595959598867 56.52537944554611, -3.2097043869356865 56.525109618901915, -3.2120647434428893 56.52429506116395, -3.211922166112066 56.523698969725444, -3.210508188787166 56.521463885654356, -3.209013270222155 56.519897136645476, -3.208493021874503 56.519842001387936, -3.207256048452258 56.51907325863904, -3.2072172944870823 56.518416853766865, -3.206675814012484 56.51799983397714, -3.2037970623176824 56.516809439843584, -3.2022992207575998 56.51600813593464, -3.200758815403959 56.51534918385857, -3.1997704670014646 56.51451866504143, -3.1984485328827628 56.51429063659582, -3.1972831022766734 56.5144384428205, -3.194823472399967 56.51384487829986, -3.1924827352171015 56.51248103476856, -3.191420701304223 56.51152087995018, -3.190130282278105 56.510012143326094, -3.190131237417104 56.50879830254481, -3.1888104461880635 56.508494690374015, -3.18598018667515 56.50834744499348, -3.184646837324961 56.507795931394654, -3.1855513873516568 56.507155676955215, -3.1888859904029023 56.50701508717635, -3.1899933549363104 56.50678345875046, -3.193419694410502 56.50551310500458, -3.1938118481869973 56.505549153665356, -3.1950711759320947 56.507360936596726, -3.2019558286163403 56.50483662601108, -3.2149175376783283 56.5010284393098, -3.218090648151662 56.499778460299204, -3.2204029278199364 56.50031442099678, -3.221624556181708 56.50119118969878, -3.223847631474742 56.501804137003, -3.2242729089558804 56.502180853581734, -3.227592589925737 56.50309944294864, -3.2290595440301733 56.503246668563705, -3.2302451009514597 56.50273178417157, -3.2315326963944955 56.50185648627212, -3.2315574721820792 56.50061634438244, -3.2321925157361253 56.50016080727251, -3.2332800176843217 56.500132042763276, -3.2338719527659983 56.49885032697012, -3.235156981443931 56.49790313716118, -3.236557823258071 56.4965235115263, -3.237668475385657 56.494715492801085, -3.2386697831563485 56.49404063551374, -3.241367052397029 56.493573446528394, -3.2422362267633553 56.49333115015831, -3.2433522500357825 56.49269104577194, -3.246049659241653 56.492232737507905, -3.2474102905020064 56.492120243696725, -3.2472409469289554 56.490383711417905, -3.2475860816420674 56.489958075763454, -3.2498271024752694 56.489059080991744, -3.2466057213280255 56.4885632128158, -3.2492228948891517 56.48280577479485, -3.263479021134074 56.47469793670933, -3.2651672538642895 56.47566907460719, -3.266267333771139 56.47701456870227, -3.2681606756186907 56.47828905872013, -3.2720238430234043 56.47971406517787, -3.2746121759622495 56.480882502269935, -3.2748421627002453 56.48144618584766, -3.2761973457741043 56.48263623169115, -3.2733086493426162 56.48462458537129, -3.28535180785371 56.488768294787874, -3.2927431433327907 56.48309399332914, -3.296195743214399 56.482914237869174, -3.3006473600994886 56.48535649206661, -3.302636299253249 56.4865306287682, -3.3025715903726978 56.48712879258805, -3.3038981018303626 56.48714544477815, -3.3049756420458407 56.48741943893833, -3.307160894020569 56.486348303466116, -3.313726964313394 56.49025930647389, -3.318049514524273 56.487518030675176, -3.3173680368696803 56.48706703356219, -3.321864169883312 56.48513241907461, -3.3239552160893804 56.486421934745394, -3.3237872824583783 56.48672921198643, -3.3271305550215264 56.48899365707146, -3.3307756470900642 56.48687912934632, -3.3326085192864885 56.48588909123069, -3.335968452507578 56.48491856084237, -3.3377874704331134 56.486309607282195, -3.3381876155313237 56.48614356661007, -3.339514777761292 56.48693789860423, -3.3429840207462838 56.48552940296905, -3.343351607454101 56.485123045227795, -3.3428516386354974 56.48409995764753, -3.3543569354561167 56.48417125243419, -3.361152384313221 56.484384456995166, -3.3616668552266566 56.484533321029986, -3.364413898677876 56.48793365661148, -3.3735114107860222 56.48756380251923, -3.3776228021967167 56.487635057961874, -3.37852683135748 56.488829011198874, -3.382768927278566 56.48868765157026, -3.384752923941409 56.490772366944924, -3.3864771757591274 56.4890639480511, -3.395657279101973 56.48828722435877, -3.397581190541287 56.48804994355192, -3.4018374296930736 56.488082827252704, -3.4032100232664626 56.48830991802427, -3.4033757488711545 56.49015895775913, -3.4049223604236767 56.49025827293215, -3.40606482128249 56.49084733699286, -3.4075022784479114 56.491945193091745, -3.409584573379371 56.4929099241893, -3.411479842579399 56.49277158950423, -3.4135653841828626 56.49294553571532, -3.413083958103137 56.495287120878224, -3.4141007158262626 56.49772845666874, -3.4147331064490016 56.49900611130116, -3.4137179430232325 56.50184795156007, -3.4118535299281354 56.5037021030306, -3.409323289262812 56.50513250219117, -3.4069896457537756 56.50573400163626, -3.4057390951523727 56.506188427346615, -3.4020612219540793 56.50691286068048, -3.3991777784232027 56.507152032874146, -3.3970778832547976 56.50749014617108, -3.393349244876297 56.50861022933944, -3.3907320306499433 56.510355691664564, -3.3900067281035207 56.51140606666651, -3.3892974429117877 56.51200700980998, -3.388718599472975 56.51306472328488, -3.387717184247247 56.5136779076668, -3.3858602513317084 56.51623239649692, -3.3848290496212745 56.518705772767255, -3.3831209554612403 56.52044991202438, -3.381271415775884 56.52099161771368, -3.378554096671763 56.52205750449872, -3.374652630231106 56.52180180084371, -3.3698410634416964 56.52269953362811, -3.3681445865440125 56.52343702207, -3.3676615761655495 56.524017375017245, -3.3673435663637155 56.52511703483117, -3.367650239396074 56.525958240702465, -3.3685809269164126 56.52697226240027, -3.37011554998539 56.528051515670256, -3.3724498356786468 56.52921175933523, -3.375217861819436 56.53022340090772, -3.37797467535323 56.53136987970287, -3.3791329872121256 56.532372323388806, -3.3801067754893204 56.5336643236641, -3.381786749683955 56.53514613317471, -3.383269213810125 56.537896992816876, -3.3818692844861573 56.53919741225902, -3.3801082672408445 56.53996273151531, -3.3785927245400225 56.54121947195446, -3.377893743919153 56.541676469861144, -3.3768575402290026 56.541804759274726, -3.3735151099301923 56.54112294832219, -3.37279705716934 56.540194216597875, -3.3691818086110707 56.54055429908811, -3.3685887099609757 56.54071009880412, -3.3677282093501617 56.53984803884046, -3.365528036036667 56.54016873804784, -3.3616079947651376 56.540148860444674, -3.35961827818979 56.53999094970365, -3.357481444410627 56.54026588852495, -3.3543923397985225 56.53710098212599, -3.3456677652831037 56.53869624675753, -3.346286782606069 56.5396419367253, -3.338468665463765 56.54022056266165, -3.337295976886924 56.54017029477738, -3.33621008868146 56.53981359774317, -3.3358748911846923 56.540455125756104, -3.335659952427655 56.54312593436346, -3.3351108487413295 56.5436978799894, -3.3329403831447255 56.54505162759956, -3.3359981071556013 56.54579978125756, -3.339706654358125 56.546263007636504, -3.3418697024609245 56.546715866917545, -3.3415204683309607 56.5478786731287, -3.343274552444163 56.548722279781735, -3.3434058755695153 56.549215026651126, -3.342642257827655 56.54924124850474, -3.3429957951735414 56.5500370794433, -3.344589680076965 56.55002883003722, -3.344843755483186 56.55077182290005, -3.3453631451536534 56.551197473942906, -3.344674425211201 56.5515014273318, -3.3449594474306847 56.55265738770276, -3.344801259751448 56.55324311404898, -3.343027683458799 56.55415179084928, -3.3427926328732056 56.55486413250898, -3.3400431785129183 56.55532507875334, -3.3376367851356243 56.555827196229636, -3.335575533563723 56.5568916021763, -3.334018784571629 56.55657588215495, -3.333303321997206 56.556125333419054, -3.329244227161741 56.55682470169813, -3.3284789765481544 56.555880493317126, -3.324958429488701 56.55709508263681, -3.321765098044012 56.557901775448585, -3.322327880403276 56.5583922176295, -3.311783610746633 56.559085693876135, -3.3106361006699503 56.55742662926303, -3.3101288733729395 56.556007618799846, -3.3076867032689403 56.55540916450647, -3.304361653735292 56.55428506731635, -3.302964608973757 56.55292504981523, -3.301871685349741 56.55141807509077, -3.300130229551425 56.54949559244296, -3.2999702132469406 56.54814954905691, -3.2987992985880017 56.546257017837306, -3.2974561938472458 56.545983534645494, -3.2928968501049596 56.545833387566454, -3.2878788341671945 56.546065187999375, -3.287663307425015 56.54690300482326, -3.2889967551945776 56.54785056036882, -3.290733418987404 56.548695055328224, -3.2928294306856283 56.549580739513154, -3.2927710479904877 56.550731397399026, -3.2904507681676614 56.55186063744382, -3.2866757742602215 56.552313075400264, -3.2842870739832777 56.55239169051379, -3.2832081682679415 56.552717301057875, -3.282161899101996 56.552566373588256, -3.281621772427867 56.551987935693504, -3.28136071315327 56.55100230472242, -3.2814469186369193 56.550183794321526, -3.280908658172916 56.54965925164435, -3.279870270503564 56.54925665103065, -3.2789888543460832 56.54916689282839, -3.279550903063144 56.54846928128807, -3.277793793742348 56.5484940446772, -3.274794112903618 56.54938578710427, -3.273242802364003 56.54959821338151, -3.2733280397518025 56.55013248040926, -3.2743816977319664 56.55002284834397, -3.275460372750389 56.55017350820965, -3.2749891479440074 56.550672504384465, -3.275387633936583 56.5513961800404, -3.2771091859093833 56.55276215235755, -3.2775863237697846 56.553404150174956, -3.27750154168879 56.554267557068414, -3.2761266378867155 56.55595284321876, -3.2744506565068123 56.55691344594187, -3.273188088158199 56.55710607112882, -3.2678660774804724 56.55705265616678, -3.264700626693207 56.55677942488701, -3.259025929221572 56.55688196006733, -3.255569286813475 56.5566563695415, -3.252981507182251 56.55662857544418, -3.251459795000214 56.55685953930314, -3.250490491886112 56.557561117190424, -3.2509391200752984 56.557844113327555, -3.256744134818647 56.559214123027324, -3.261741942869232 56.55992799998728, -3.2619875024583895 56.56043076247965, -3.257881478376295 56.56240978158886, -3.2573266830804313 56.562550542512575, -3.254476653805123 56.56398039392242, -3.255302539915774 56.56472993380656, -3.2526631198734566 56.565661803528236, -3.2522027190146674 56.565582237589325, -3.2508262491329205 56.566749082942934, -3.250537305164031 56.56736294882776, -3.2487228560754358 56.56879610547944, -3.246709948559842 56.569252236223114, -3.2446842565959493 56.569020963501046, -3.2440900502099628 56.56827219849051, -3.2445373265382984 56.56801615048445, -3.2437357728425575 56.56739524494244, -3.241313693487738 56.56797650393194, -3.2395162383921274 56.568749151618256, -3.23934351780864 56.56993685020441, -3.240363036071543 56.57075327195823, -3.240784703990726 56.571701439180565, -3.239786883615413 56.57304112469621, -3.2404602857977336 56.574220392450776, -3.2392046040021873 56.57464620026223, -3.237980812094479 56.57405641987131, -3.2376393698661374 56.573071506455854, -3.235547253826753 56.57280480675772, -3.2339975403183137 56.57319754518247, -3.2331286209945507 56.57400581020865, -3.2322222820402566 56.57366439496162, -3.2318573824764263 56.57395552002475, -3.2324329219179346 56.57513579940216, -3.233765011624607 56.575553841946665, -3.2351332258761163 56.57508203946175, -3.2364974479915927 56.57498761709804, -3.2359180845177247 56.57618833729623, -3.2350321308104375 56.577472962113, -3.23471084450084 56.57910237521893, -3.233309956148888 56.581074932172896, -3.2334301299006367 56.58176555787052, -3.23420407400045 56.58303369775957, -3.2365769368935866 56.58340544682709, -3.238821630995041 56.58284402417874, -3.238092510397082 56.58394741357665, -3.2344267318769084 56.58437019949327, -3.2353997757830113 56.58525001557246, -3.236583258841747 56.586091793047316, -3.2376172159416527 56.586342061191544, -3.238065968798576 56.58711925812653, -3.234679069550535 56.58811428953386, -3.233631439230125 56.58794499425154, -3.233125263468515 56.58740195190193, -3.2322671418920392 56.58705107309698, -3.231335244932202 56.58693451954148, -3.230607951013665 56.586600294137455, -3.2292130218879898 56.58626369941806, -3.228023926506821 56.586248494366686, -3.2257823512742503 56.58641436537651, -3.2226827755058767 56.58572611125225, -3.2202026204870937 56.58556180536307, -3.2183852981396743 56.58474405552815, -3.2161161179707167 56.5850627526099, -3.2146088815655935 56.58578726907206, -3.2119933653794837 56.585462389748976, -3.2093021730422375 56.584805761088205, -3.208969900128794 56.58561760690786, -3.2103372429563106 56.58611642806933, -3.211042047098172 56.5877896877737, -3.209347301291522 56.588767533931275, -3.2084827722798694 56.5882098995724, -3.2074679960015895 56.58702481401002, -3.2061320993307603 56.5870018403447, -3.2056275482358325 56.58803097777545, -3.2043264660160204 56.5885916458893, -3.2017593629680405 56.58876921932195, -3.1988300633434226 56.58933656930061, -3.1998471430880806 56.59111469343056, -3.1979506333361702 56.59190566059139, -3.1952623238703333 56.591347521250526, -3.1931688088652392 56.59157427074509, -3.1929752910261264 56.59215114037287, -3.1937762632465843 56.5927633900427, -3.1928094881451035 56.59360823232197, -3.193279654915569 56.59457405608789, -3.1957849080919885 56.594487100706075, -3.1980295817439655 56.59491472645692, -3.199077410746639 56.5961175465988, -3.1980139245694015 56.59647819421263, -3.196813532658928 56.5956002784127, -3.195127491789055 56.59532898587868, -3.193755227611179 56.5967437590798, -3.1935585882630058 56.59825505444566, -3.1920150002239587 56.59888979356078, -3.1897790054470603 56.59926160188431, -3.188540616957156 56.60080081796012, -3.186769041243276 56.600404444936586, -3.1849138650451945 56.60045807119467, -3.1842737736998674 56.600823549890755, -3.1855313373872947 56.6019705770519, -3.1832810585368114 56.60241427963123, -3.1810877100697255 56.603117952497186, -3.1815661149105985 56.60383217258639, -3.180738894837174 56.60499004991676, -3.1814051914644166 56.60493880042301, -3.1807876961235957 56.60603179378954, -3.184871825706615 56.60691836462233, -3.183629606154422 56.60782864595042, -3.1795600861104174 56.609713976172856, -3.1806565098245994 56.61133714295691, -3.178292778620131 56.61170672639252, -3.173404497272866 56.6122201190347, -3.174454822197057 56.613512972417205, -3.173733906810357 56.61338500862523, -3.170474783341232 56.614952069253604, -3.1740860853140185 56.617733062558976, -3.1707133946724024 56.61797580906347, -3.1687957702382517 56.61777731294309, -3.1681802468063167 56.617950206109136, -3.1609121588081743 56.61921767146405, -3.1575064656202825 56.61741477016564, -3.1566301557615954 56.616201927149135, -3.155988924012772 56.61494826047322, -3.1547777653331943 56.614291960821355, -3.15354624957009 56.614195572548596, -3.15304988467245 56.61389470134453, -3.150869041747228 56.61081883845808, -3.149885912985634 56.60811640816086, -3.1541003163936088 56.608430468909745, -3.1549606504814256 56.60763454230824, -3.1556847691492824 56.60659369952446, -3.1565733696505434 56.60635184297075, -3.158064781443449 56.60637839681733, -3.1594195160258165 56.606250774724856, -3.1611309853924965 56.60548550119788, -3.1619612936593615 56.60472664151783, -3.1622257586687734 56.604161739557135, -3.16217059717137 56.60321438776121, -3.1640165971524192 56.60259246694367, -3.1659460634896384 56.60108655653946, -3.164399893022163 56.600120829005085, -3.165049480748512 56.59952895432161, -3.1660003072549046 56.59925230483048, -3.165855193088525 56.59887721320626, -3.163628230494382 56.59896814801461, -3.1618608138663067 56.59933237271395, -3.160208396886693 56.59925166376635, -3.157346983170311 56.598463427146264, -3.155949907351319 56.59890228626762, -3.1547722655419457 56.599060572168575, -3.1529839461066445 56.59900888114631, -3.1513258320482116 56.59852560083125, -3.1495209777547344 56.59841112163415, -3.1489018147286703 56.598134729054415, -3.148209873912067 56.59717708069119, -3.1460952260560067 56.596026802127504, -3.1444576824023684 56.595570195140525, -3.1436307450507885 56.59563709992668, -3.142639108464808 56.59607477587541, -3.1428158620127467 56.59675058381453, -3.144159587502746 56.59664568863288, -3.1453660071800105 56.59679360983261, -3.145508844277623 56.59710046305893, -3.1440849463315597 56.597355253149594, -3.141999738744899 56.59712285148669, -3.1404965197504486 56.59739450080644, -3.139507591969039 56.5978707597679, -3.137411769352111 56.59782705298624, -3.1361388474134912 56.59844783683956, -3.136611730971126 56.59917126050349, -3.136540232452807 56.599556450389514, -3.1355634887489248 56.60044225892778, -3.1355882164115982 56.60121200433104, -3.135179510799776 56.60148796538564, -3.1338017555907913 56.6012247085266, -3.1326315813738908 56.601256932964176, -3.132198640019268 56.60072360227054, -3.131203608899526 56.60051163767741, -3.1321446628822667 56.601532697698445, -3.130348559150311 56.60144121994026, -3.1296225507996684 56.601620317980654, -3.130240510373292 56.60207740505263, -3.1304883942652597 56.60268699575185, -3.129161541037442 56.60380234303073, -3.1281583528234322 56.604411609461536, -3.127524328128407 56.604563805508306, -3.1266197184372846 56.60421801400644, -3.1260259497379574 56.60435456416019, -3.125789832017978 56.605014365217706, -3.124909182503438 56.605638667802836, -3.1229039378962513 56.606629804894645, -3.1217192570967285 56.60760722282256, -3.120254154264193 56.60747937016866, -3.1194260907111255 56.60691271766715, -3.1188088063835773 56.60708268711664, -3.1187023717206137 56.60767032995092, -3.11727894901108 56.60867770343706, -3.1168302146211535 56.60975717302359, -3.116218951237968 56.60996750525683, -3.1145872493129456 56.610104324947734, -3.1134290423083164 56.60966727145414, -3.112927831449664 56.609853242731596, -3.1130129020810995 56.611692497595556, -3.1138517519968447 56.61201651561325, -3.1137090046317772 56.612369984213, -3.112685547973548 56.61308172682129, -3.1112922242983343 56.61235296460807, -3.110649162770252 56.61220417515986, -3.108159019970367 56.61285259865155, -3.108928766247899 56.61332101640346, -3.1102041605300137 56.61375167539999, -3.11005166710927 56.61399651469535, -3.1084405629437653 56.61339724297248, -3.10654027469226 56.61327040958614, -3.105446593332299 56.61370330029248, -3.1042607945520784 56.61371652724437, -3.102679167812304 56.614180677059814, -3.10131193139701 56.614398532154816, -3.100308782096743 56.61430588479042, -3.099904775869369 56.61503719650336, -3.1008524805369158 56.61529565141109, -3.1007672366260355 56.615893870427186, -3.099692560270008 56.61592044527672, -3.098506813698273 56.6157134980595, -3.095794403650829 56.61545441010773, -3.094600114461514 56.61562664379325, -3.0940952873118355 56.61614409521202, -3.094562733104467 56.61669971288337, -3.0920705272628677 56.61718341434396, -3.0912177107714056 56.61693753704499, -3.088152272658593 56.613188236764984, -3.097640445252715 56.60994774924091, -3.105282494014412 56.60736263920189, -3.1044295706267375 56.606773647791144, -3.1021723950071007 56.60601561566243, -3.101494599025559 56.605620014966355, -3.100149591458442 56.6036786998077, -3.100110494680515 56.601885749597294, -3.097979480883124 56.59833326100609, -3.101643829769635 56.597037642465175, -3.106159963327457 56.59575141177572, -3.11214085745171 56.593889496970746, -3.1173253024377354 56.590277084002025, -3.116388681325307 56.58954876802141, -3.1230068299773643 56.584023907152066, -3.127847320827281 56.58200619956636, -3.129260798869462 56.58125394493167, -3.132663256934058 56.57907569668755, -3.1348901151492963 56.578257564812105, -3.137737464727508 56.57750649070526, -3.1376901028226762 56.57668843339729, -3.140207720886846 56.57623680810423, -3.141545748319459 56.576398830073266, -3.1444346216962296 56.57579187082448, -3.1447943047814304 56.57562863463261, -3.1491160653133896 56.57445132188819, -3.149793934009737 56.57436868601351, -3.1530684762655925 56.574356328365404, -3.157682492945228 56.572103248016525, -3.1594961657336684 56.571535592114564, -3.1624787088989894 56.57002438677647, -3.165136427150014 56.56923042686965, -3.165605301355628 56.56955307008668, -3.167263984865157 56.568822334703526, -3.175281689465069 56.56696065734842, -3.179466628260939 56.56620674589523, -3.1794381873643527 56.565920407078764, -3.1835803199838195 56.5650005469333, -3.186655502302908 56.56306469496919, -3.190200442723407 56.56127880298973, -3.190322018646762 56.55634238623822, -3.18905713507218 56.5552808307546, -3.1855384456416087 56.55461274453971, -3.1839390977434467 56.55372234003141, -3.18168378348385 56.55109513745875, -3.1799566146430784 56.547082843005015, -3.1789064124529904 56.54594906728358, -3.177154594509799 56.54463594912353, -3.1767352882481816 56.5440693966502, -3.174613621544388 56.54293943732561, -3.171175353249899 56.542091396546205, -3.1660737626149476 56.53913401891622, -3.164043369796819 56.53815037256515, -3.1674238337359015 56.53592191839212, -3.1717925981489388 56.532486401056644, -3.173502821286582 56.53109299502113))
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>