Getting data for LSOA via the ons API

三世轮回 提交于 2019-12-12 10:16:28

问题


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.


回答1:


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.




回答2:


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);
}


来源:https://stackoverflow.com/questions/33153682/getting-data-for-lsoa-via-the-ons-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!