Reputation: 279
Using code I obtained from the following link : http://python-overpy.readthedocs.org/en/latest/example.html I want to instead input variables that I have already obtained instead of directly inputting them,such as follows:
import overpy
api = overpy.Overpass()
result = api.query("node(min_lat,min_lon,max_lat,max_lon);out;")
len(result.nodes)
The variables min_lat etc are of type float. This is the error I am getting:
overpy.exception.OverpassBadRequest: Error: line 1: parse error: Unknown query clause
Error: line 1: parse error: ')' expected - 'min_lat' found.
Error: line 1: parse error: An empty query is not allowed
Error: line 1: parse error: Unknown type ";"
Error: line 1: parse error: An empty query is not allowed
Any help is greatly appreciated as I am quite stuck and new to all of this thank you!
Upvotes: 0
Views: 1124
Reputation: 6323
You are literally sending the query node(min_lat,min_lon,max_lat,max_lon);out;
to the Overpass API, min_lat
etc. are unchanged.
To fill the variables you can use string substitution:
"node(%s, %s, %s, %s);out;" % ( min_lat, min_lon, max_lat, max_lon )
The %s
will get replaced with the variables you supply in the brackets.
import overpy
api = overpy.Overpass()
min_lat = 50.745
min_lon = 7.17
max_lat = 50.75
max_lon = 7.18
query = "node(%s, %s, %s, %s);out;" % ( min_lat, min_lon, max_lat, max_lon )
result = api.query(query)
print query
print len(result.nodes)
Upvotes: 1