[英]Using Latitude and Longitude values in esy-osm-pbf to get amenities list at a given radius in Python
I have a dataset that had latitude and longitude of some elements.我有一个数据集,其中包含一些元素的纬度和经度。 I am trying to pull information regarding all the amenities around a particular latitude longitude.
我正在尝试获取有关特定纬度经度周围所有便利设施的信息。 I have used overpass query and I am able to fetch the amenities.
我使用过天桥查询,我能够获取便利设施。 But, I want to use the OSM.pbf file downloaded directly in the python query.
但是,我想使用直接在 python 查询中下载的 OSM.pbf 文件。 I was able to pull all amenities at a particular latitude longitude value using the following query
我能够使用以下查询以特定纬度经度值提取所有便利设施
import esy.osm.pbf
osm = esy.osm.pbf.File('california-latest.osm.pbf')
amenities = [entry for entry in osm if entry.tags.get('amenity')]
After this I was able to pass lonlat value and get the amenities.在此之后,我能够通过 lonlat 价值并获得便利设施。 Is there anyway I can pass the radius and longitude and latitude values in the code to get the required information
无论如何我可以在代码中传递半径和经度和纬度值来获取所需的信息
Code using overpass query.使用立交桥查询的代码。 I want to replicate the following using the above method
我想使用上述方法复制以下内容
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']])
The first element unfolds the structure of the object ( esy.osm.pbf.file.Node
):第一个元素展开对象的结构(
esy.osm.pbf.file.Node
):
amenities[0]
When you look closer, you see the tags
itself is a dict
inside the Node
object:当您仔细观察时,您会看到
tags
本身是Node
对象内的一个dict
:
type(amenities[0].tags) # := dict
And so is the longlat
too! longlat
也是如此! ( tuple
inside Node
): (
Node
内的tuple
):
type(amenities[0].longlat) # := tuple
So let's say you are looking for the "exact" coordinations (long, lat)
, you just have to run the following piece of code:因此,假设您正在寻找“精确”坐标
(long, lat)
,您只需要运行以下代码:
for entry in osm :
if entry.loglat == (long, lat)
target = entry
break
And you have the Node
you are looking for in target
.并且您在
target
有您正在寻找的Node
。 I guess you get the idea and know how to look for similar coordinations (using regex etc.)我想你明白了,知道如何寻找类似的协调(使用正则表达式等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.