简体   繁体   English

在 esy-osm-pbf 中使用纬度和经度值在 Python 中获取给定半径的便利设施列表

[英]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.

相关问题 如何在 Python Pandas 中找到 5 英里半径内给定纬度和经度的点列表的密度? - How do I find the density of a list of points given latitude and longitude in a 5 mile radius in Python Pandas? 使用GDAL / OGR python模块解析osm.pbf数据 - Parsing osm.pbf data using GDAL/OGR python module 获取经度/纬度Python熊猫 - Get Latitude/Longitude Python Pandas 如何使用 python 获取纬度和经度 - How To Get Latitude & Longitude with python 如何删除经度/纬度半径之外的 CSV 表值? - How to delete CSV table values outside of a longitude/latitude radius? Python:Web Scraping - Airbnb 获取列表的纬度和经度值 - Python: Web Scraping - Airbnb get the latitude and longitude values for a listing 使用 python 提取纬度和经度 - Extracting Latitude and Longitude using python 如何使用 python 获取 eumetsat 图像像素的纬度和经度? - How to get latitude and longitude for a pixel of a eumetsat image using python? Python Flask 将基于纬度和经度的半径过滤器计算转换为 SQLalchemy - Python Flask translating calculation for radius filter based on latitude & longitude to SQLalchemy python:使用纬度和经度在提供位置的半径内查找位置的优雅方法 - python: elegant way to find the locations inside the radius of provided location using Latitude and Longitude
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM