Python 如何在立交桥查询中连接字符串
我试图编写一个函数,将Python 如何在立交桥查询中连接字符串,python,jupyter-lab,overpass-api,Python,Jupyter Lab,Overpass Api,我试图编写一个函数,将lat和longps坐标作为查询overpy(openstreemap)的变量 以下是我尝试过的: def query_overpass(lat, lon): import overpy api = overpy.Overpass() result = api.query(""" way(around:5,""" + lat + """ ,
lat
和lon
gps坐标作为查询overpy(openstreemap)的变量以下是我尝试过的:
def query_overpass(lat, lon):
import overpy
api = overpy.Overpass()
result = api.query("""
way(around:5,""" + lat + """ , """ + long + """)
['highway' !~ 'elevator']
['highway' !~ 'bus_guideway']
['highway' !~ 'footway']
['highway' !~ 'cycleway']
['foot' !~ 'no']
['access' !~ 'private']
['access' !~ 'no'];
(
._;
>;
);
out;""")
return result
调用函数:query_overpass(40.74797, -73.81236)
不幸的是,它不起作用
有人知道如何管理吗?谢谢使用设置立交桥查询格式:
import overpy
def query_overpass(lat, lon):
api = overpy.Overpass()
result = api.query(
f"""
way(around:5,{lat},{lon})
['highway' !~ 'elevator']
['highway' !~ 'bus_guideway']
['highway' !~ 'footway']
['highway' !~ 'cycleway']
['foot' !~ 'no']
['access' !~ 'private']
['access' !~ 'no'];
(
._;
>;
);
out;
"""
)
return result
res = query_overpass(40.74797, -73.81236)
for way in res.ways:
print(way)
输出:
<overpy.Way id=284487961 nodes=[2882270459, 2882270744, 2882270769, 2882270775, 2882270940, 2882270752, 2882270701, 2882270478, 2882270459]>