![](/img/trans.png)
[英]How do I find the density of a list of points given latitude and longitude in a 5 mile radius in Python Pandas?
[英]Using Latitude and Longitude values in esy-osm-pbf to get amenities list at a given radius in Python
我有一個數據集,其中包含一些元素的緯度和經度。 我正在嘗試獲取有關特定緯度經度周圍所有便利設施的信息。 我使用過天橋查詢,我能夠獲取便利設施。 但是,我想使用直接在 python 查詢中下載的 OSM.pbf 文件。 我能夠使用以下查詢以特定緯度經度值提取所有便利設施
import esy.osm.pbf
osm = esy.osm.pbf.File('california-latest.osm.pbf')
amenities = [entry for entry in osm if entry.tags.get('amenity')]
在此之后,我能夠通過 lonlat 價值並獲得便利設施。 無論如何我可以在代碼中傳遞半徑和經度和緯度值來獲取所需的信息
使用立交橋查詢的代碼。 我想使用上述方法復制以下內容
import overpy
amenities = []
for latitude,longitude in zip(Dataset_Sample.Latitude, Dataset_Sample.Longitude):
overpass_query = """[out:json][timeout:25]; node["amenity"](around:1000.0,"""+ str(latitude) + "," +str(longitude)+"); out;"
response = requests.get(overpass_url, params={'data': overpass_query})
response_json = response.json()
amenities.append([element['tags']['amenity'] for element in response_json['elements']])
第一個元素展開對象的結構( esy.osm.pbf.file.Node
):
amenities[0]
當您仔細觀察時,您會看到tags
本身是Node
對象內的一個dict
:
type(amenities[0].tags) # := dict
longlat
也是如此! ( Node
內的tuple
):
type(amenities[0].longlat) # := tuple
因此,假設您正在尋找“精確”坐標(long, lat)
,您只需要運行以下代碼:
for entry in osm :
if entry.loglat == (long, lat)
target = entry
break
並且您在target
有您正在尋找的Node
。 我想你明白了,知道如何尋找類似的協調(使用正則表達式等)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.