This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How to concatenate strings for a query to overpass

1

I would like to write a query that takes the lateral and longitudinal gps coordinates as variables. I have tried it as followed :

lat = 30.74797
long = 53.81236
import overpy
api = overpy.Overpass()

result = api.query("""
way(around:5,""" + lat + """ , """ + long + """)
  ['highway']
  ['highway' !~ 'path']
  ['highway' !~ 'steps'];
(
  ._;
  >;
);
out;""")

Unfortunately it does not work as expected.

How could I manage that ? Thanks

asked 17 Dec '20, 14:32

Dykay's gravatar image

Dykay
36337
accept rate: 0%

edited 17 Dec '20, 14:34


One Answer:

3

Format strings are a nice way to solve this problem:

https://docs.python.org/3.4/library/string.html#format-string-syntax

I'd suggest using keywords so that you don't have to remember what order to pass in the values, so

"""way(around:5, {lat}, {long})...""".format(lat=lat,long=long)

answered 17 Dec '20, 17:30

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

Thank you @maxerickson

(17 Dec '20, 17:52) Dykay

Source code available on GitHub .