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/S02002229 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02002229 geosparql: asWKT MULTIPOLYGON (((-3.2454657726823952 56.35835940682182, -3.245097741132775 56.35789319097647, -3.2458096125055764 56.35719059971772, -3.2471779292511425 56.35656855361524, -3.2483137928127728 56.356312725542196, -3.253151441815275 56.355628661465026, -3.257794209522821 56.35522402198391, -3.2594126764543687 56.355177933510916, -3.263082411038069 56.354813529440584, -3.26660258357645 56.354577233653586, -3.268783265926469 56.35464926791373, -3.2686290427488864 56.355024623188456, -3.264472108783581 56.355386077445935, -3.2610138787523786 56.35593256275025, -3.257257988403419 56.356731753931214, -3.25199772541255 56.358152524137985, -3.2454657726823952 56.35835940682182)), ((-3.27714946450999 56.350418535101866, -3.276789526842043 56.34928384170064, -3.2737303385388996 56.3477510338494, -3.271645291870102 56.34772123539879, -3.2695094313439044 56.34806120677338, -3.266659312961782 56.347893603384584, -3.264350737922605 56.34824783000889, -3.262862715960438 56.34831511782391, -3.2615162988863595 56.34860377430592, -3.2574537307984124 56.346749233211206, -3.2554151490245777 56.34616162038091, -3.2553405818045666 56.3452216461107, -3.25703363644891 56.34435719498338, -3.2577923294899853 56.343518382094416, -3.257907314366277 56.34273551891372, -3.2584013842998716 56.34211592698605, -3.2560599297168484 56.3401324354355, -3.2623355429289704 56.33862745545242, -3.2650775751147907 56.339118820638944, -3.2662677701831293 56.339203699900025, -3.2676042114405646 56.3390642428231, -3.267769673899898 56.33571293033014, -3.2686656561544245 56.33478279204418, -3.2692791641402037 56.33460219800278, -3.2729250695411594 56.333972674916005, -3.2731484592284423 56.33256961101805, -3.267674610982701 56.33240741016886, -3.268003921852374 56.33019372013539, -3.2665949397102585 56.328182906547234, -3.2668461253670675 56.32810119135771, -3.2681661020023913 56.327671755379875, -3.2708647195982574 56.326343062829125, -3.2744107518259793 56.32633178852925, -3.2760189890970564 56.326210106630555, -3.279646092151189 56.32499744279512, -3.2808090403685566 56.324812011228126, -3.2827858346806997 56.324206626724, -3.2852237110087197 56.32274374333192, -3.286138796492336 56.322547355159436, -3.2878065351591883 56.321941503923505, -3.288955533781857 56.32115413961193, -3.2898607751666105 56.32081136915036, -3.2917797690021926 56.319318714004346, -3.292200010638398 56.31854880066303, -3.2952774125649142 56.31684722432409, -3.297166288658133 56.31481209729835, -3.299016557312965 56.31416913756036, -3.300684906221289 56.31397821442466, -3.301015535495914 56.31309959195586, -3.299207746638453 56.31218232194208, -3.2977964446861563 56.312228567531626, -3.29535795634215 56.3118731291608, -3.2944837242528373 56.31126139979012, -3.297029873366464 56.31055009395795, -3.2997516653609917 56.30996807443314, -3.299034748039742 56.30808692622553, -3.2984410864084235 56.30697809977397, -3.296276928927223 56.30397548535843, -3.2955581111180337 56.303414250400124, -3.2948271796827724 56.302016623745054, -3.2947372265607675 56.30145958861926, -3.2939496328898774 56.300343783414796, -3.2937829508734064 56.29885489405598, -3.2943870179154677 56.29841549783459, -3.2955687664414386 56.297999706156745, -3.296223426732083 56.297528323382906, -3.2956997247140145 56.29633069674112, -3.2928293134046265 56.29368133842322, -3.29233534019845 56.29278528754768, -3.2926499015321298 56.29205241137658, -3.2933249085250056 56.291419996866566, -3.2948232075788413 56.28923891886294, -3.2956761626845674 56.28976191488169, -3.297074769610645 56.29003299681315, -3.299134929595182 56.28994490529201, -3.299696266350913 56.2901088326669, -3.300885388934686 56.28987171478837, -3.302093210937343 56.28852202788233, -3.3039794348124203 56.28816792708971, -3.3049730082289632 56.287789066568656, -3.3063654770688875 56.28754885316097, -3.3084480779827885 56.28779102261722, -3.310432842017666 56.28734503127435, -3.3112981991155936 56.28676261495761, -3.3118157139801956 56.28588287594094, -3.3125341118218192 56.285256183419165, -3.316401008185026 56.284350750307176, -3.3171013646282357 56.284000965673215, -3.319219187477166 56.28367471553134, -3.320834077817328 56.28328640741219, -3.3214157012296486 56.28366386723282, -3.3248637931982774 56.28280307064462, -3.326087320911472 56.283430613326004, -3.326723567410597 56.28440407964694, -3.328194700610325 56.286113459741145, -3.3296578343763525 56.28721640866, -3.3305924827037483 56.28677687444885, -3.3330944133901492 56.28769160548393, -3.3336410789168136 56.287987619938264, -3.3354861444184856 56.28942692474375, -3.3378749444920897 56.288806312844635, -3.3375022723599255 56.28840510744661, -3.3411836959080885 56.28631665324488, -3.34266882393356 56.28748300729679, -3.3458744873954087 56.28653080816363, -3.3474927831216728 56.285690851158904, -3.3487988433140443 56.287961772994066, -3.3490325029536714 56.28909136348611, -3.34936657554964 56.28940220500925, -3.3506698157439487 56.29193397048434, -3.3511072508313164 56.29237525011253, -3.3562742105390844 56.290788023926766, -3.359593101023213 56.289343357434525, -3.3603376748787515 56.289921050726086, -3.3614342036885327 56.28973108060612, -3.36202166617487 56.29016998960914, -3.3637069837703204 56.292349933226525, -3.365819269511052 56.294505000032665, -3.371043575242987 56.29370352214351, -3.373091146802527 56.29300035135024, -3.3733942448690617 56.292399830417196, -3.3747672064946297 56.292384592246904, -3.375806131866155 56.29322644272897, -3.3776205798952663 56.292909753178655, -3.378595112039433 56.292602392314734, -3.377827589931181 56.291478795373756, -3.376470619425007 56.291484904654844, -3.3768824623046454 56.29035716916612, -3.375276848083742 56.289737063509236, -3.376785572479416 56.28856118799743, -3.3774877483134627 56.28876903194672, -3.380634572452972 56.288221818054645, -3.3835973308568743 56.28839540174227, -3.384236890495042 56.28865781000399, -3.385715172236067 56.28709580651531, -3.386341050122963 56.28683411173096, -3.388236639711162 56.287130453359296, -3.3874657466298594 56.2877984436106, -3.388512396520061 56.28805284334765, -3.3894062947475296 56.28864482709073, -3.3900845445166237 56.28952674570202, -3.391576328285201 56.28834190995486, -3.3938994459445495 56.287363335287225, -3.3945108900414587 56.28818309456098, -3.395621027670716 56.28894331827802, -3.3974814816649173 56.28901218353964, -3.3995429566469437 56.28927642471055, -3.401890145482699 56.290283175282426, -3.4046580290993793 56.29086280100108, -3.4067044911694424 56.291154049989565, -3.4092993371577913 56.29054049463914, -3.411953793181506 56.29198383773455, -3.4134661676155993 56.29268540403905, -3.414376478639881 56.29239646347371, -3.4166831847603576 56.29272950157667, -3.417483393842588 56.292522665600075, -3.4181170814661566 56.29305452692799, -3.4202299978913127 56.292518144116265, -3.422602497038114 56.29244597850957, -3.424490119625071 56.29367323253309, -3.425028895640332 56.29338848757613, -3.4262108408725176 56.293887040498255, -3.4264322050023166 56.292455815929834, -3.4266961425136517 56.29173395814595, -3.4294476762686252 56.2922952503224, -3.4329607594896205 56.29204797555854, -3.43519055432662 56.29334299026589, -3.4355405849672644 56.29621423710892, -3.4359699934430568 56.29689214232685, -3.4378783822206245 56.29736418718433, -3.435746638942585 56.299123092944946, -3.4332068336699693 56.2999162700373, -3.4321147406207473 56.300530922513666, -3.431731301558114 56.30237734608057, -3.43088506095759 56.30395057199539, -3.429728413693449 56.30543752263726, -3.429367132561019 56.30658282704602, -3.42892709936558 56.30735165620009, -3.430810665204913 56.308012789823856, -3.433666424886698 56.30959711528123, -3.4347671686217347 56.3092069839254, -3.4396240648448466 56.30811730443356, -3.4430660082121207 56.30723262163051, -3.4459058604018407 56.30710065606132, -3.447446330026179 56.30765772019633, -3.450858308905878 56.31110409957148, -3.4522487419523897 56.31068346175514, -3.453087171327118 56.309775093170664, -3.4553631226646453 56.309263157812254, -3.457735730462229 56.31001697561253, -3.4601810434997784 56.31013193178042, -3.464375887660226 56.31076528464232, -3.4663193120790097 56.31043678621285, -3.470509295119087 56.31430471826984, -3.4715802372688493 56.313986495131864, -3.472357706371532 56.31612474551499, -3.4747760945940778 56.315529901933125, -3.4760820654495177 56.31585578694906, -3.478486957138828 56.3161685441571, -3.4799644858986856 56.31716624282355, -3.4817306620116426 56.31684859848854, -3.482416730108825 56.31702909008482, -3.4837616217249767 56.31793846906453, -3.485173086245795 56.31847864418296, -3.4871672538200285 56.31986542736595, -3.488066108651103 56.32094186127759, -3.4896574896981623 56.322360391122935, -3.486661185993335 56.321821328503916, -3.48389877286076 56.32189039678276, -3.4835872298942543 56.322612958080065, -3.484371035971823 56.324059187031146, -3.486225412985627 56.32444174054566, -3.488432474810708 56.32455458307946, -3.489970617849201 56.32496405394417, -3.489315941967602 56.32672023760837, -3.486954085129609 56.32690649520077, -3.486704854684284 56.32672724573213, -3.484911105026241 56.327023103468385, -3.4838470564866184 56.3270533672728, -3.481822625332056 56.326760581081714, -3.473497700509983 56.32486429399572, -3.4733766102002197 56.3253675479861, -3.473528726656458 56.32721671912809, -3.4733818142714634 56.328440473088776, -3.4715855124946167 56.33093279387404, -3.4689719962832757 56.33068526911687, -3.4667863065825864 56.33399979810822, -3.4672512462314224 56.33642032885963, -3.467385607422874 56.338656081695525, -3.467799635955503 56.34016969549683, -3.4678162351725605 56.34102310374193, -3.4686822641068633 56.341246458542045, -3.4685220850123235 56.34255122784045, -3.4687974519302105 56.3434015683422, -3.4711602688083736 56.34341846090998, -3.473184761792492 56.34305296300296, -3.474770158668843 56.34262976202084, -3.4763732896449935 56.341828945465714, -3.477165473075784 56.34223282789359, -3.477888625548758 56.342943029941715, -3.4776081930154756 56.34432962078291, -3.4760688079495385 56.3448651651993, -3.47735758712956 56.34552815152573, -3.4763435656327415 56.34566603291571, -3.4758258219229763 56.34608552580512, -3.471868548814443 56.345845069160596, -3.4716247423111293 56.3466566433867, -3.4671216858237477 56.34653033989335, -3.466015407598607 56.34721733219931, -3.465968287971418 56.3476761311571, -3.466732588456029 56.34777491857891, -3.4668153430562887 56.349930411408614, -3.4665600564935684 56.350867904369515, -3.457904609980668 56.3513474276205, -3.455704426318935 56.35136430971678, -3.4543192664207965 56.35111101649566, -3.451383700814652 56.35093877481013, -3.4510393879822434 56.35039470555864, -3.449137557769387 56.35059666787612, -3.447108717404637 56.35000938052819, -3.4472017037401512 56.354599766014374, -3.447353216026302 56.35603563855051, -3.447130789321568 56.3569996592082, -3.445927363990005 56.35745442922621, -3.4452186446171713 56.357152260438205, -3.443261905272092 56.35706724220111, -3.440436843233099 56.357775803187664, -3.4384196355598644 56.357589877927424, -3.4354673602705392 56.35745788413635, -3.4325059583710917 56.35794500850459, -3.4293920409520355 56.35833767887679, -3.4277885543423943 56.35787455552451, -3.4270278922194 56.35713934023176, -3.4267363665286967 56.356267535567895, -3.427932593306343 56.354843974068196, -3.427922306664788 56.35417918522581, -3.427355289710255 56.353687037301434, -3.425616132473951 56.353441993733384, -3.4242668082824395 56.35349524806248, -3.422561649460907 56.353727785158206, -3.421188643845124 56.35423233605257, -3.420873579050566 56.35502934439349, -3.4214790182032684 56.35585982365871, -3.4227206656942752 56.35647633727259, -3.4232364762281895 56.35694123999773, -3.4236102802517503 56.357764485465076, -3.4234340632396716 56.35924637586277, -3.423077074514337 56.35991717916328, -3.421934764467937 56.36036337879955, -3.4207217971658603 56.3601292983839, -3.41945110656663 56.359517589805364, -3.415596188798701 56.35625782177945, -3.4139214021044135 56.35499834659193, -3.413968947795598 56.35361587813926, -3.413676905532677 56.35320229624448, -3.4126029603396497 56.35278145635044, -3.409922386795634 56.35320194365407, -3.406966260836032 56.352381949117806, -3.405885348536371 56.35198898480934, -3.4055187019285245 56.35161217146578, -3.405481735104926 56.350871311296494, -3.4044734361480753 56.350207056603935, -3.4029939506192153 56.34966583610752, -3.401470064925655 56.34928054437163, -3.3992433673348272 56.34918890203484, -3.3978364593698003 56.349389876800565, -3.3955292526778087 56.349441940532174, -3.3907462362481895 56.35020464859608, -3.3890795049798905 56.35051626152309, -3.3874716383537393 56.3509790422697, -3.385972552656784 56.351274359424174, -3.384799235123187 56.35118235106702, -3.383528666410306 56.35005812247702, -3.382250450552736 56.34939131181603, -3.381518373146494 56.34919371582545, -3.379758828928009 56.349176482259274, -3.3781986463390132 56.349527195358576, -3.377043078205379 56.350015358288644, -3.3761386222052847 56.35082688308171, -3.3752298951191837 56.35138596531383, -3.373033456526484 56.35195751896325, -3.3716594989177113 56.3518658122865, -3.370741542342622 56.35113289796344, -3.3696549890571617 56.35070643741698, -3.368681236582154 56.350943622847566, -3.3681966946951483 56.35133084290867, -3.3678101545357184 56.35224081346051, -3.367092720509761 56.352451795055764, -3.3656918303259067 56.35156153980084, -3.3637522774605726 56.35072032732707, -3.3619492080963673 56.3501192851989, -3.360213347436079 56.349222766693025, -3.359222904832943 56.34903686079832, -3.354729883580077 56.34900609828994, -3.3516636917738873 56.34891918332411, -3.3503475919006362 56.349132104493854, -3.348854720818663 56.349792598259505, -3.3478619763926853 56.35041169396056, -3.346521167178028 56.350981552070415, -3.345326594333411 56.35129373190588, -3.344383785383013 56.3510353094647, -3.344328297170549 56.34987233868126, -3.34480561155652 56.34862990817849, -3.344907840567962 56.34767278162545, -3.344307970270694 56.346811328499534, -3.343477450881367 56.34633783543135, -3.341546311398933 56.345714526490674, -3.340219576240292 56.34497683006273, -3.3397130145525296 56.34428057059534, -3.339743240414178 56.34361983740193, -3.34202352215997 56.34151959515768, -3.3423068610213007 56.34074290618707, -3.3422901998673766 56.339946105744836, -3.3418929829884183 56.3393223481495, -3.3409160687150186 56.33872822633597, -3.3394365691009367 56.33837853613707, -3.3374286732701437 56.338229511027194, -3.3351184464022365 56.33882588303511, -3.3333390905073603 56.3396635900119, -3.331998125151201 56.340502847990294, -3.331024200954196 56.341477417572285, -3.3303193092675047 56.342606330066104, -3.3304445224847883 56.34360053558521, -3.3311505296147765 56.34403591820366, -3.3316711014788964 56.34523163316106, -3.3323417047727615 56.34622806035274, -3.334702027651151 56.3483024770911, -3.3356133367367695 56.349283714722134, -3.3358566698944405 56.34999540762013, -3.335070433899498 56.35106592081034, -3.333636602873434 56.35171211521771, -3.332496267186567 56.351727078538, -3.331672537551843 56.35154005858432, -3.329417726808496 56.35045281371876, -3.3275151424671554 56.349672639600506, -3.325308075214248 56.34888221608455, -3.322972009349526 56.348475895986, -3.3213716817646732 56.348428279842636, -3.3197529550607405 56.34859737960544, -3.3169225235415416 56.34868050640722, -3.314670851842136 56.34841959020106, -3.3113453281010314 56.34793818784662, -3.3101031665381764 56.34748140844534, -3.3079478881760784 56.34743319617419, -3.306697240164285 56.347672815418925, -3.3046723628049515 56.3483635403224, -3.3043945351819564 56.34866207400307, -3.301928270485389 56.35022086334953, -3.3011431498221047 56.3508769327449, -3.2997578481954437 56.35134881067839, -3.29778136755905 56.3515680963777, -3.2945211487070605 56.351439569289866, -3.2926268366367215 56.35117092470571, -3.288455565097855 56.35084867695079, -3.2857760114569703 56.35042096892288, -3.2829669547287854 56.350230850587586, -3.27714946450999 56.350418535101866)))
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>