1

I have been able to get valid data for electoral wards for a range of census concepts.

e.g. http://data.ons.gov.uk/ons/api/data/dataset//QS201EW.json?dm%2F2011WARDH=E05001107&apikey=MYAPIKEY&jsontype=json-stat&totals=false&context=Census&geog=2011WARDH

However the geographical scale of this data is too large (this is electoral ward level - Metropolitan I believe). I want the smallest/finest grained data I can get and believe that Lower Super Output Layer LSOA represents that. However when I adjust my API call to that geographical hierarchy e.g.

http://data.ons.gov.uk/ons/api/data/dataset//QS201EW.json?dm%2F2011LSOAH=E01008368&apikey=MYAPIKEY&jsontype=json-stat&totals=false&context=Census&geog=2011LSOAH

I get a the following response

'404 INTERNAL ERROR: Dataset QS201EW for context Census and hierarchy 2011LSOAH not found'

Why is this? Is the data just not available for this geographical hierarchy or is there something wrong with my API call? Thanks for your help in advance.

2 Answers2

0

Thanks to help elsewhere I have an answer. The problem was that the geographical hierarchy which I'd defined as 2011LSOAH should have been 2011STATH. Lower Super Output layer is part of the 'statistical hierarchy'.

I also found that by using the ONS's data explorer here there's a feature which constructs the API url for any given query.

mbatchkarov
  • 15,487
  • 9
  • 60
  • 79
  • I am looking for a similar answer. However, your link (ONS's data exporer) doesn't seem to work.. – wildcolor Jan 28 '16 at 11:20
  • Just in case - the correct url is http://www.ons.gov.uk/ons/data/dataset-finder/-/q/datasetDownload/Census/QS208EW?p_auth=UtquyTF9&p_p_auth=v5CuJwBq&p_p_lifecycle=1&_FOFlow1_WAR_FOFlow1portlet_geoTypeId=2011STATH&_FOFlow1_WAR_FOFlow1portlet_UUID=9124922 – tomschofield Jan 29 '16 at 14:16
  • I actually want to find the LSOA code for a given postcode. Have you done that? The 2011STATH seems to be MLOA code?? – wildcolor Jan 29 '16 at 15:11
  • As far as I understand it (not far) the 2011STATH is the hierarchy that encompasses LSOA , MSOA etc. I wanted the LSOA code to use in my ONS API query. To get this I had to use another api from neighbourhood.statistics.gov.uk. The process is described in this post http://stackoverflow.com/questions/29622849/uk-postcode-to-census-data-using-the-api – tomschofield Jan 30 '16 at 16:20
0

I can belatedly add a few extra tips:

To get data for one or more named LSOAs ....

http://data.ons.gov.uk/ons/api/data/dataset/QS201EW.json?dm/2011STATH=E01008397,E01008396&apikey=12345&jsontype=json-stat&totals=false&context=Census&geog=2011STATH

To get all the LSOAs within an LA

http://data.ons.gov.uk/ons/api/data/dataset/QS201EW.json?pdm/E08000021=LSOA&apikey=12345&jsontype=json-stat&totals=false&context=Census&geog=2011STATH

This uses the alternative pdm/{parent area code}={list of child area types} syntax.

The parent area code can also be a grandparent or older ancestor. You can get the codes for potential parent areas with a call like this http://data.ons.gov.uk/ons/api/data/hierarchy/QS601EW.xml?context=Census&apikey=12345&geog=2011WARDH&levels=0,1,2,3,4,5,6

Another PDM Example: Get a count of males for all the local authorities (of any type) within South East region and return as JSON-Stat:

http://data.ons.gov.uk/ons/api/data/dataset/QS104EW.json?context=Census&apikey=12345&geog=2011WARDH&totals=true&jsontype=json-stat&dm/CL_0000035=CI_0000071&pdm/E12000008=NMD,UA,LONB,MD

Note that an alternative to using the NeSS service to get an area for a postcode, you can use ArcGIS. First a call to the ESRI world service to get the x and y coordinates of a postcode or placename, then do a query against the ONS ArcGIS service to return the name / code of admin area it falls within:

function getCentroid() {
    var searchstring = document.getElementById("postcodeorplace").value;
    var testURL = "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?text=" +
    searchstring + "&outFields=*&bbox=%20-5.4188710000000002,49.865400000000001,%201.7641,55.813870000000001&sourceCountry=GBR&outSR=27700&f=json&maxLocations=6";
    getJSONResponse1(testURL);
}

function getExtCode() {
    var layer = document.getElementById("layerpicker");
    var layerval = layer.options[layer.selectedIndex].value;
    var xpos = document.getElementById("xcoord").value;
    var ypos = document.getElementById("ycoord").value;

    var testURL = "http://services1.arcgis.com/ESMARspQHYMw9BZ9/ArcGIS/rest/services/" + layerval + "/FeatureServer/0/query?returnGeometry=false&outFields=*&geometryPrecision=0&f=json&geometry=" +
                  xpos + "," + ypos + "&geometryType=esriGeometryPoint&inSR=27700"
    getJSONResponse2(testURL);
}
krlzlx
  • 5,752
  • 14
  • 47
  • 55