themiurgo / overpass-api-python-wrapper

A thin Python wrapper around the OpenStreetMap Overpass API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overpass API python wrapper

This is a thin wrapper around the OpenStreetMap Overpass API.

image

Install it

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

Use it

You can use the overpass command line interface or use it as a Python library.

Command line interface ---------------------

You can use the CLI to execute queries and save the result in a GeoJSON file.

Usage: overpass [OPTIONS] QUERY OUTPUT_FILE

Run query and save the result in output_file

Options:
--timeout INTEGER  Timeout in seconds
--endpoint TEXT    URL of your prefered API
--format TEXT      Format to save the data. Options are 'geojson', 'json', 'xml'. Default format is geojson.
--help             Show this message and exit.

For example:

To make a query and save the result as GeoJSON:

Or to get the result as an OSM XML file:

Python Library -------------

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:

You can specify the format of the response. By default, you will get GeoJSON using the responseformat parameter. Alternatives are plain JSON (json) and OSM XML (xml), as ouput directly by the Overpass API.

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:

timeout ^^^^^^^^^^

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

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:

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:

Need help? Want feature? =======================

Create a new issue.

Test it

py.test

Fork it

Yes please. Help wanted.

About

A thin Python wrapper around the OpenStreetMap Overpass API

License:Apache License 2.0


Languages

Language:Python 100.0%