Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ons api 使用API将英国邮政编码转换为人口普查数据_Ons Api - Fatal编程技术网

Ons api 使用API将英国邮政编码转换为人口普查数据

Ons api 使用API将英国邮政编码转换为人口普查数据,ons-api,Ons Api,使用国家统计局的网站,我可以得到英国邮政编码的人口普查摘要 我希望我能够使用API做同样的事情 但我不清楚如何从邮政编码到国家统计局所称的街区或下层超级输出区。似乎我需要像这样使用交付端点 但是,我如何找出用于特定邮政编码的参数呢?您是否尝试过查看中的代码 功能运行区 微弱TXT响应 将邮政编码设置为字符串 Dim extCode Set rootSheet=GetSheetQuery 设置areaSheet=GetSheetAreas 端点=http://neighbourhood.stati

使用国家统计局的网站,我可以得到英国邮政编码的人口普查摘要

我希望我能够使用API做同样的事情

但我不清楚如何从邮政编码到国家统计局所称的街区或下层超级输出区。似乎我需要像这样使用交付端点


但是,我如何找出用于特定邮政编码的参数呢?

您是否尝试过查看中的代码

功能运行区 微弱TXT响应 将邮政编码设置为字符串 Dim extCode Set rootSheet=GetSheetQuery 设置areaSheet=GetSheetAreas 端点=http://neighbourhood.statistics.gov.uk/NDE2/Disco/FindAreas?HierarchyId=27&Postcode= 邮编=rootSheet.RangeA2.Value Application.StatusBar=获取+邮政编码的区域 txtResponse=GetAreaspostcode 德利姆= 数据=GetElementstxtResponse,区域 如果UBounddata<0,则 Application.StatusBar=False MsgBox邮政编码+邮政编码+未找到,请使用感叹号 退出功能 如果结束 对于i=0到UBounddata curLevelType=GetValuedatai,LevelTypeId curHierarchy=GetValuedatai,HierarchyId curId=GetValuedatai,AreaId curName=GetValuedatai,Name 选择案例类型 案例15 extCode=UpdateArea输出区域,2,curId,curName,curHierarchy 案例14 extCode=UpdateAreaWard,3,curId,curName,curHierarchy 案例13 extCode=UpdateAreaLA,4,curId,curName,curHierarchy 案例11 extCode=UpdateAregion,5,curId,curName,curHierarchy 案例10 extCode=UpdateAreaCountry,6,curId,curName,curHierarchy 结束选择 下一个 发现MsgBox区域 Application.StatusBar=获取已完成的区域 端函数
看起来需要三个调用才能获取数据集

将xml.etree.ElementTree作为ElementTree导入 导入json 导入请求 API\U密钥=您的API\U密钥 def get_area_idlevel_类型,邮政编码: 获取pos的区域id :param level_type:您感兴趣的分辨率。14=病房级别数据。 :param邮政编码:英国邮政编码 :return:字符串区域标识符 基本url=http://neighbourhood.statistics.gov.uk/NDE2/Disco/FindAreas 有效负载={'HierarchyId':'27','Postcode':Postcode} response=requests.getbase\u url,params=payload xml=ElementTree.fromstringresponse.content 名称空间={'ns1':'http://neighbourhood.statistics.gov.uk/nde/v1-0/discoverystructs'} xpath_for_area='.//ns1:area' areas=xml.findallxpath_表示_区域,名称空间 病房\区域\ id= 对于区域中的区域: level\u type\u id=区域。查找'ns1:LevelTypeId',namespaces.text 如果级别类型id==strlevel类型:查找病房=14 ward\u area\u id=area.find'ns1:AreaId',namespaces.text 返回病房\区域\ id def get_ext_codearea_id: 从区域id获取外部代码 :param area_id:邮政编码的区域id :return:我认为某个区域的ext代码是GSS代码 基本url=http://neighbourhood.statistics.gov.uk/NDE2/Disco/GetAreaDetail 有效负载={'AreaId':区域\ id} response=requests.getbase\u url,params=payload xml=ElementTree.fromstringresponse.content 名称空间={'ns1':'http://neighbourhood.statistics.gov.uk/nde/v1-0/discoverystructs', '结构':'http://www.SDMX.org/resources/SDMXML/schemas/v2_0/structure'} xpath_for_ext_code='.//ns1:ExtCode' ext_code=xml.findxpath_表示_ext_代码,namespaces.text 返回外部代码 def get_datadata_集合,地理编码: 获取地理代码的数据 :param data_set:来自的字符串标识符http://www.nomisweb.co.uk/census/2011 /快速统计 :param geog_code:地理区域的外部代码 :return:包含数据的json对象 基本url=http://data.ons.gov.uk/ons/api/data/dataset/ 有效载荷={'apikey':API_键,'context':'Census','geog':'2011WARDH','dm/2011WARDH':geog_代码, '总计':'假','jsontype':'json stat'} r=requests.getbase_url+/+data_set+.json,params=payload obj=json.loadsr.text 返回obj def processjson_对象,数据_集: 数据={} values=json\u对象[数据集]['value'] index=json_对象[data_set][dimension'][json_对象[data_set][dimension'][id'][1][category'][index'] labels=json_object[data_set]['dimension'][json_object[data_set]['dimension']['id'][1]['category']['label'] 对于l in标签: num=索引[l] 计数=值[strnum] 数据[标签[l]]=计数 返回数据 区域标识=获取区域标识14,SW1A 0AA gss\U代码=获取外部代码区域\U id 返回的数据=获取数据QS208EW,gss代码QS208EW=宗教 返回的printprocessdata_,QS208EW
谢谢你的建议。