繁体   English   中英

如何在立交桥查询中连接字符串

[英]How to concatenate strings in overpass query

我正在尝试编写一个 function ,它将latlon 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

致电 function:

query_overpass(40.74797, -73.81236)

不幸的是,它不起作用。

有人有任何提示如何管理吗?
谢谢

使用f-string格式化您的立交桥查询:

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]>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM