User avatar
sayhello
Posts: 88
Joined: Sat Mar 05, 2016 1:02 pm

headstart with python - using the overpass-api-python wrapper

Sat Oct 14, 2017 9:00 am

hello dear community


i am pretty new to this great site.

currently want to dive into Python with some real world projects +

connecting to the endpoint of Overpass.

(BTW - this is what i want to let to do the Raspi - automatically - with cron jobs. )

one question:

is this the same https://github.com/DinoTools/python-overpy like this- https://github.com/mvexel/overpass-api-python-wrapper

guess no:

with the overpass-api-python wrapper i want to do the first steps today:

the examples that are shown here: https://github.com/mvexel/overpass-api-python-wrapper - they are written in Python version 2xy

so they do not work with the Version 3 xy


well this example code here:

Code: Select all

import overpass
api = overpass.API()
response = api.Get('node["name"="Salt Lake City"]')
should give with this command #

Code: Select all

print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]

a list of comma seperated values - is this correct.... ?

any idea !?

DirkS
Posts: 10006
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: headstart with python - using the overpass-api-python wrapper

Sat Oct 14, 2017 9:20 am

sayhello wrote:
Sat Oct 14, 2017 9:00 am
the examples that are shown here: https://github.com/mvexel/overpass-api-python-wrapper - they are written in Python version 2xy

so they do not work with the Version 3 xy
The only example I see there is written for Python 3
https://github.com/mvexel/overpass-api- ... list.py#L1

User avatar
scruss
Posts: 2613
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: headstart with python - using the overpass-api-python wrapper

Mon Oct 16, 2017 12:02 am

(posted from duplicate thread - please don't do that)

Can you fix up what's supposed to be in the code bits and what's supposed to be in text mode, please?

I'm fairly well acquainted with OpenStreetMap's Overpass servers, but never used the Python module. Until now …

Looks like the docs are incorrect, as the example query

Code: Select all

print( [(feature['tags']['name'], feature['id']) for feature in response['elements']] )
doesn't work, under python3 at least. This works as expected, however:

Code: Select all

print( [(feature['properties']['name'], feature['id']) for feature in response['features']] )
[('Salt Lake City', 150935219), ('Salt Lake City', 585370637)]
The output isn't CSV, but GeoJSON. The result above is a list of lists, so is a special case that could easily be represented as CSV:

Code: Select all

Name,ID
'Salt Lake City', 150935219
'Salt Lake City', 585370637
By the looks of things (aka my many errors), the wrapper simply takes whatever you pass to Get() and wraps it in:

Code: Select all

[out:json];
 /* *** YOUR QUERY HERE *** */
out body geom;
So you wouldn't specify the output format, the fields you want, or the out command at the end. You'd have to iterate through the response structure, pulling out the name, postcode, city, etc as in the Salt Lake City example.

OpenStreetMap Help Forum might be a better place to ask, or ask Martijn (the author) directly.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Python”