Skip to content

mharnold/overpass-api-python-wrapper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overpass API python wrapper

This is a thin wrapper around the OpenStreetMap Overpass API.

travis

Install it

$ python setup.py install

The module is not on PyPi yet.

If you get an error similar to

OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so']

you can install the required libraries on linux with

$ sudo apt-get install libgeos-c1 libgeos-3.4.2

Use it

>>> import overpass
>>> api = overpass.API()
>>> response = api.Get('node["name"="Salt Lake City"]')

Note that you don't have to include any of the output meta statements. The wrapper will, well, wrap those.

You will get your result as a dictionary, which (for now) represents the JSON output you would get from the Overpass API directly. So you could do this for example:

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

Parameters

The API takes a few parameters:

endpoint

The default endpoint is http://overpass-api.de/api/interpreter but you can pass in the rambler instance (http://overpass.osm.rambler.ru/cgi/interpreter) or your own:

api = overpass.API(endpoint=http://overpass.myserver/interpreter)

timeout

The default timeout is 25 seconds, but you can set it to whatever you want.

api = overpass.API(timeout=600)

debug

Setting this to True will get you debug output.

Simple queries

In addition to just send your query and parse the result, the wrapper provides shortcuts for often used map queries. To use them, just pass them like to normal query to the API.

MapQuery

This is a shorthand for a complete ways and relations query in a bounding box (the 'map call'). You just pass the bounding box to the constructor:

>>> map_query = overpass.MapQuery(50.746,7.154,50.748,7.157)
>>> response = api.Get(map_query)

WayQuery

This is shorthand for getting a set of ways and their child nodes that satisfy certain criteria. Pass the criteria as a Overpass QL stub to the constructor:

>>> way_query = overpass.WayQuery('[name=Highway 51]')
>>> response = api.Get(way_query)

Need help? Want feature?

Create a new issue.

Test it

py.test

There are almost no tests yet.

Fork it

Yes please. Help wanted.

About

A thin Python wrapper around the OpenStreetMap Overpass API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%