使用esri、google、bing地图、美国人口普查局、openstreetmap、pelias和mapquest地理编码器的地理编码库
python-omgeo的Python项目详细描述
omgeo-python版本
python-omgeo是用python编写的地理编码抽象层。目前 支持的地理编码器:
- US Census Geocoder
- Bing Maps REST Locations API
- ESRI World Geocoding Service
- MapQuest Licensed Data API
- MapQuest-hosted Nominatim Open Data API
- Pelias geocoder。默认使用geocode.earth
- Google geocoder
安装:
sudo pip install python-omgeo
文档
用法示例
制作新的地理编码器,地理编码和地址:
>>> from omgeo import Geocoder >>> g = Geocoder() >>> result = g.geocode('340 12th St, Philadelphia PA')
查看结果:
>>> result {'candidates': [ <340 S 12th St, Philadelphia, PA, 19107 (-75.161461, 39.94532) EsriWGS>, <340 N 12th St, Philadelphia, PA, 19107 (-75.158434, 39.958728) EsriWGS> ], 'upstream_response_info': [<EsriWGS 1054ms>]}
仔细查看地址候选对象中的信息:
>>> [c.__dict__ for c in result["candidates"]] [{'geoservice': 'EsriWGS', 'locator': u'USA.AddressPoint', 'locator_type': u'PointAddress', 'match_addr': u'340 S 12th St, Philadelphia, PA, 19107', 'score': 90.87, 'wkid': 4326, 'x': -75.161461, 'y': 39.94532}, {'geoservice': 'EsriWGS', 'locator': 'interpolation', 'locator_type': u'StreetAddress', 'match_addr': u'340 N 12th St, Philadelphia, PA, 19107', 'score': 90.87, 'wkid': 4326, 'x': -75.158434, 'y': 39.958728}]
一些地理编码器(esriwgs和us census)可以返回除 完整地址:
>>> [{'geoservice': 'EsriWGS', 'locator': 'interpolation', 'locator_type': u'StreetAddress', 'match_addr': u'340 N 12th St, Phila, Pennsylvania, 19107', 'match_city': u'Phila', 'match_country': u'USA', 'match_postal': u'19107', 'match_region': u'Pennsylvania', 'match_streetaddr': u'340 N 12th St', 'match_subregion': u'', 'score': 90.1, 'wkid': 4326, 'x': -75.158384, 'y': 39.958774}]
这些是可选的,它们的存在可能取决于地理编码器的响应而改变。
测试
存储库的根目录中有一个shell脚本,名为test.dummy.sh。 使用cp test.dummy.sh test.sh复制它。编辑test.sh以包括 从给定地理编码服务提供程序获取的API密钥。然后,跑 使用./test.sh的测试。