Return individual address components (city, state, etc.) from GeoPy geocoder(返回单个地址部分(城市、州等)来自GeoPy地理编码器)
本文介绍了返回单个地址部分(城市、州等)来自GeoPy地理编码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用GeoPy对地址进行地理编码,以将其转换为LNG。我还想提取每个地址的详细地址组成部分(街道、城市、州、邮政编码)。GeoPy返回一个带有地址的字符串--但是我找不到一种可靠的方法来分隔每个组件。例如:
123 Main Street, Los Angeles, CA 90034, USA =>
{street: '123 Main Street', city: 'Los Angeles', state: 'CA', zip: 90034, country: 'USA'}
Google地理编码API确实返回这些单独的组件...有没有办法从GeoPy那里弄到这些?(或其他地理编码工具?)
推荐答案
您还可以从Nominatim()
地理编码器(这是来自geopy的标准开源地理编码器)获取各个地址组件。
from geopy.geocoders import Nominatim
# address is a String e.g. 'Berlin, Germany'
# addressdetails=True does the magic and gives you also the details
location = geolocator.geocode(address, addressdetails=True)
print(location.raw)
给予
{'type': 'house',
'class': 'place',
'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright',
'display_name': '2, Stralauer Allee, Fhain, Friedrichshain-Kreuzberg, Berlin, 10245, Deutschland',
'place_id': '35120946',
'osm_id': '2825035484',
'lon': '13.4489063',
'osm_type': 'node',
'address': {'country_code': 'de',
'road': 'Stralauer Allee',
'postcode': '10245',
'house_number': '2',
'state': 'Berlin',
'country': 'Deutschland',
'suburb': 'Fhain',
'city_district': 'Friedrichshain-Kreuzberg'},
'lat': '52.5018003',
'importance': 0.421,
'boundingbox': ['52.5017503', '52.5018503', '13.4488563', '13.4489563']}
与
location.raw['address']
您获得的词典仅包含组件。
查看geopy documentation了解更多参数,或查看Nominatim了解所有地址组件。
这篇关于返回单个地址部分(城市、州等)来自GeoPy地理编码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:返回单个地址部分(城市、州等)来自GeoPy地理编码器


猜你喜欢
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01