跳转到主要内容

Ordnance Survey的CodePoint-Open数据的Python接口

项目描述

Ordnance Survey的CodePoint-Open的接口。CodePoint-Open是一个免费的地图数据集,将英国邮政编码映射到坐标。

oscodepoint读取此数据,无论是在原始zip文件中还是在解压缩后,解析数据,并将网格参考转换为纬度和经度。

数据集可以从http://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/下载

示例

>>> from oscodepoint import open_codepoint
>>> codepoint = open_codepoint('codepo_gb.zip')
>>> for entry in codepoint.entries():
...    print entry['Postcode'], entry['Latitude'], entry['Longitude']
...    break  # Over 1.6 million rows
AB101AA 57.1482995075 -2.09663094048

数据量太大?尝试限制邮政编码区域

>>> from oscodepoint import open_codepoint
>>> codepoint = open_codepoint('codepo_gb.zip')
>>> for entry in codepoint.entries(areas=['NR', 'IP']):
...    print entry['Postcode'], entry['Eastings'], entry['Northings']
...    break
NR1 1AA 624068 308352

需要邮政编码所在的县?

邮政编码条目有一个Admin_country_code字段。 Doc/Codelist.xls将这些代码映射到县名,而codepoint.codelist可以用来访问此文件。例如

>>> from oscodepoint import open_codepoint
>>> codepoint = open_codepoint('codepo_gb.zip')
>>> county_list = codepoint.codelist['County']
>>> for entry in codepoint.entries(areas=['NR']):
...    print entry['Postcode'], entry['Latitude'], entry['Longitude'], county_list.get(entry['Admin_county_code'])
...    break
NR1 1AA 52.6266175146 1.30932087485 Norfolk County

获取邮政编码总数以供进度条使用

>>> from oscodepoint import open_codepoint
>>> codepoint = open_codepoint('codepo_gb.zip')
>>> print codepoint.metadata['area_counts']['NR']
22730
>>> print codepoint.metadata['total_count']
1692241

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

oscodepoint-0.3.0.tar.gz (4.7 kB 查看哈希值)

上传时间: 源代码

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面