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/S01011977 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01011977 geosparql: asWKT POLYGON ((-3.157315542254088 56.65621598477803, -3.156909798105426 56.655537837106266, -3.155613862856639 56.65460650827576, -3.1533105953739167 56.65374919154712, -3.151904100162486 56.65341272056331, -3.1508891286395726 56.65275636207148, -3.1518095165772966 56.65191588931641, -3.1517602096985122 56.651422201182775, -3.1505911374208027 56.650416872907705, -3.1500870633893427 56.64928859317395, -3.149934707441302 56.647766238901816, -3.1487653682547214 56.64610323469987, -3.1486057668027003 56.64401851871379, -3.148912667387941 56.643225054268626, -3.1500435849906467 56.64218229529762, -3.1510544306098223 56.64073274179059, -3.152596738691948 56.639122827053505, -3.1533904667080517 56.63809753351729, -3.1548230769105468 56.63738615446168, -3.1558826040827603 56.637165182702546, -3.1583971119675267 56.636966604388384, -3.161653754963192 56.6368320270125, -3.1647192077307165 56.636313719652506, -3.1664261203364483 56.636311208802056, -3.173744001697409 56.63565481557734, -3.1770410413255328 56.63577551179055, -3.1783533876736993 56.63551152591783, -3.1783786691193074 56.63506745223089, -3.177101414864061 56.63467793349003, -3.1767835566464453 56.633841787560684, -3.1779038922393212 56.633329852520795, -3.1780583151998574 56.631223321486345, -3.177501797385472 56.63005161886474, -3.1750116400529684 56.62959987841334, -3.1731387123348007 56.62876042925637, -3.1741421940729815 56.628582953916116, -3.174401655403477 56.62806749007746, -3.171816096348889 56.62658336902661, -3.17138989750226 56.62613725858878, -3.175626291765784 56.62425727491536, -3.183899512454759 56.623168068245796, -3.185566018143955 56.62277934154734, -3.191257614297361 56.621963986109364, -3.189625315601553 56.62089876505514, -3.187718695977057 56.619138942259966, -3.18585156702797 56.61759344466949, -3.180959393555141 56.61575951890446, -3.1799987257796065 56.61588723056567, -3.1781635069296943 56.616658426224284, -3.1740860853140185 56.617733062558976, -3.170474783341232 56.614952069253604, -3.173733906810357 56.61338500862523, -3.173404497272866 56.6122201190347, -3.178292778620131 56.61170672639252, -3.1806565098245994 56.61133714295691, -3.1795600861104174 56.609713976172856, -3.183629606154422 56.60782864595042, -3.184871825706615 56.60691836462233, -3.1807876961235957 56.60603179378954, -3.1814051914644166 56.60493880042301, -3.1815661149105985 56.60383217258639, -3.1810877100697255 56.603117952497186, -3.1832810585368114 56.60241427963123, -3.1855313373872947 56.6019705770519, -3.191355155712348 56.60641949149825, -3.197827694363625 56.60963339785115, -3.2003767669437106 56.609869377873416, -3.2024335788717426 56.60845690489914, -3.204180839310521 56.60909587604541, -3.206151525049092 56.60856465336791, -3.2050945607518186 56.60760457298268, -3.2088207188238504 56.606015810397444, -3.212870115273752 56.609048210835674, -3.2150774085959606 56.6092238806752, -3.2169639500176404 56.61140513403991, -3.2178841087125725 56.6117753859288, -3.215535359146327 56.60891600605152, -3.2132441137833148 56.60869564738309, -3.2120539852155723 56.60769867654684, -3.2179473954539266 56.60554770112384, -3.2175235975961067 56.60452761560086, -3.222306207682621 56.603312701708916, -3.2247849092559084 56.60490554690369, -3.2255918952914815 56.60517612067452, -3.225641939874219 56.60672097908038, -3.225452340936318 56.607908814315664, -3.225563758521976 56.60883313023658, -3.226612005369207 56.61101503971606, -3.223626420300149 56.61139484284895, -3.226042609346827 56.61405744556357, -3.220172645759092 56.615321007087466, -3.2211650858790883 56.615507564174514, -3.2217098578349885 56.616121603547725, -3.220275126739808 56.61660288323719, -3.2150509003210295 56.6168067641678, -3.2150418239703504 56.617031458147856, -3.217750658674534 56.61714872530265, -3.2184252116186 56.618036921491324, -3.222828551553379 56.61745829984463, -3.223318332496066 56.61838771950065, -3.224406809430984 56.61863281169044, -3.225586369604756 56.61962074098482, -3.224447671340378 56.62001104867329, -3.2219390734461215 56.62031790942969, -3.222221654211076 56.62239396689822, -3.223259761935935 56.62222487228871, -3.224468436908444 56.622497308590816, -3.2254310485086153 56.62225736766501, -3.2260852224291487 56.621697975646704, -3.2277125304640175 56.6214075209885, -3.228035100647304 56.62168592328371, -3.2297762339880456 56.62264579879606, -3.2291925839127718 56.622973969228774, -3.2305628662527552 56.62410848291245, -3.2315270015119015 56.62400429081209, -3.2319182044957016 56.62498591008835, -3.2318743013048303 56.625675399420075, -3.2337037746717563 56.625549098323354, -3.2341721420252068 56.62650158121445, -3.2403817171897953 56.62580043500246, -3.2399246693048758 56.62507038319813, -3.242451015989451 56.62456275300621, -3.241232133339645 56.62396509821545, -3.238118096514996 56.62369135031513, -3.235905634464579 56.623692566104154, -3.2340119845644226 56.622465325510085, -3.2360552174302515 56.622278100291595, -3.235843027827342 56.62182306311426, -3.239079960180236 56.6213051602953, -3.237705549137796 56.62015926187509, -3.235661569388747 56.62069443283315, -3.2342185182496492 56.62009291686216, -3.2331936125810623 56.61998847272685, -3.2326585241899464 56.6195714996814, -3.2355228497247763 56.618455950712665, -3.2350928889430857 56.61807410692659, -3.236717265701659 56.61735599402336, -3.2340911114893958 56.617272577526315, -3.235002581759255 56.61799391745301, -3.233295710150991 56.618621802457184, -3.230946227608656 56.6168910812107, -3.2333434319057135 56.616087673223056, -3.2329417996039913 56.613764643206515, -3.2382620519522427 56.612206077939334, -3.240753746075744 56.612942938772754, -3.2456873881902704 56.612508416808936, -3.2448829705384954 56.61138396723188, -3.247181113244459 56.61074762096104, -3.2487577104572654 56.6101388185173, -3.250713903091899 56.60967891833296, -3.2526693690248334 56.61067450485814, -3.2557898320369194 56.610951879807004, -3.258987508596731 56.61105995126518, -3.261003426438502 56.61141688685937, -3.262845346654691 56.61192829544866, -3.264387134201427 56.6127212429723, -3.2676688112760797 56.61389179615561, -3.2761313817043547 56.61599752833531, -3.276522026455938 56.61598453581805, -3.2769998382178493 56.617587885444195, -3.2791763406016092 56.617376847281044, -3.2796930035852916 56.618198122306616, -3.281628823173315 56.618097332823716, -3.2822263938347525 56.618899794764786, -3.283843876768537 56.61854169633203, -3.2866598824938746 56.61748835214542, -3.2969294139114904 56.62233227453676, -3.301911877042948 56.62456233649345, -3.300521734716698 56.62631991140354, -3.3054900910833194 56.62623194174188, -3.309913884488209 56.62595184475292, -3.311757108050692 56.6283403225916, -3.3179959463831628 56.63242532231381, -3.3230879338370762 56.635381157465275, -3.3237267450787815 56.63593141484605, -3.330707048248358 56.63738436594236, -3.3323767440887426 56.64358391357219, -3.3340310128639628 56.64748352025507, -3.336163738903928 56.650605285853466, -3.3385348232269383 56.65491941653773, -3.340632732735088 56.65933527634601, -3.342299837146501 56.66171622302369, -3.3473626018584857 56.66185919381521, -3.34730975462973 56.66083551060525, -3.3460389767702705 56.660426977069044, -3.345793019597746 56.65947725872406, -3.345917999355328 56.65840672870907, -3.3466956549904725 56.65871278255531, -3.355799797081061 56.66328600555588, -3.3568789827617325 56.662896890078095, -3.360964536025307 56.66489182200382, -3.3633293476613653 56.66395849137068, -3.364138172073413 56.664668408412766, -3.3644580449573986 56.665392655892596, -3.3651201977184364 56.665654947395794, -3.365011799573289 56.666267096524734, -3.363452289669663 56.667362350916406, -3.36312954173889 56.66791394335995, -3.3637612923990767 56.668688703480704, -3.3634483613185693 56.66906050389985, -3.3637548684389666 56.669865770567284, -3.362964378886407 56.67056302353933, -3.3585699990138234 56.66942309476665, -3.358110116171516 56.67149334378357, -3.357841122534887 56.6718216584211, -3.355593418247517 56.670911320657176, -3.3551177235311296 56.67157911110889, -3.3347078839798114 56.672175144090275, -3.340340174436732 56.674989732981, -3.342916139481368 56.67949924247455, -3.344358098624158 56.68240368977963, -3.333243288032651 56.68199309155693, -3.3262207911350283 56.683757191005164, -3.337166799857342 56.691366930652215, -3.3409312267848206 56.701721682001356, -3.3322459161862477 56.70644195266567, -3.331763823068305 56.710236597447334, -3.3279055166344653 56.70912078397864, -3.3266766561305037 56.709479783658864, -3.324729019370861 56.70937472504642, -3.3192856636461587 56.7102051634735, -3.3152832788781548 56.70996896175509, -3.3152111548757635 56.708370467527295, -3.3138357122592494 56.70710467806628, -3.3140301579783453 56.706356906695305, -3.3117664111038616 56.704907293215314, -3.3068068973445017 56.70272225986758, -3.3066075709927203 56.6988564883844, -3.3030975026923906 56.696525821982576, -3.30290524300894 56.69568777476346, -3.302022815530656 56.69496026661372, -3.3085279690311293 56.68995955072812, -3.307162479341296 56.68942582958174, -3.3067133246778497 56.688949867038694, -3.305115675820451 56.68878243557971, -3.3030463228797595 56.68819315179281, -3.3029535508418193 56.68668920278065, -3.3006474288072996 56.68467380628915, -3.2997367738832626 56.684539560570975, -3.299570214637669 56.68373268531131, -3.296065056706536 56.68315377049763, -3.2948082046213485 56.68244358561487, -3.2934890579051452 56.68229557215062, -3.2927516789385813 56.68149910858947, -3.2900754804914034 56.68052148724894, -3.289054008543268 56.67952848730979, -3.288344895020796 56.67960321039744, -3.287310333518353 56.67870287308412, -3.284242292018967 56.67790347919815, -3.2859470791398246 56.67711231233185, -3.2867988476791288 56.6764359580626, -3.286630449197586 56.66905595723945, -3.2867654020546415 56.66822797951861, -3.28436954653008 56.66567413911345, -3.2834084897678695 56.665481896706, -3.2811834368055286 56.66554524515811, -3.2757117893230143 56.665861986255166, -3.2718468478984697 56.66616657516124, -3.271003525450013 56.66680410809187, -3.270414221479886 56.66771756519017, -3.2701517429561946 56.66888823808907, -3.2688390318402734 56.67012801726448, -3.26771085550023 56.67054830736884, -3.264932483076811 56.670666411205886, -3.2624218483802405 56.670251649379054, -3.2605947203896855 56.66929084503076, -3.260387088871843 56.66844839834801, -3.2559985631445327 56.666515246821525, -3.2530806657981626 56.66542068184138, -3.249441173266582 56.66346987778742, -3.2448297540363713 56.66221331418092, -3.2442972799143313 56.661353425358506, -3.242225684357976 56.66052148065364, -3.2406879610640047 56.66034454639296, -3.2393390477118076 56.659855746835156, -3.235178930082093 56.659455054582295, -3.234237988589596 56.659466184220236, -3.2319764209393305 56.658851582848065, -3.226040305335685 56.65790841384584, -3.2251230593247175 56.65854815842052, -3.2237055623129014 56.65835096445731, -3.2129899542057054 56.65542356684329, -3.2050755842861567 56.654714293339985, -3.1947238246136638 56.65465056177916, -3.1913902917059884 56.6544614938507, -3.1893540970345815 56.6546004597368, -3.186219240644586 56.65429615053251, -3.1853347425798417 56.653555270528656, -3.183211068179501 56.65225475675018, -3.1811309797110625 56.65176958454364, -3.1758545419327793 56.6519776684885, -3.174767904036996 56.65275250746694, -3.1727146592728577 56.653391797161014, -3.172726945151017 56.6545228257578, -3.1702894983866337 56.655295968315436, -3.169580596711374 56.655791385734126, -3.166420426744616 56.655774318789256, -3.1650437909556364 56.65551318496967, -3.1630493726590467 56.65590109651947, -3.161776845719001 56.65557696120027, -3.1599191365600485 56.65622140005283, -3.1585578910338663 56.655716572782445, -3.157315542254088 56.65621598477803))
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>