Coder Social home page Coder Social logo

overpass-api-python-wrapper's Introduction

Overpass API python wrapper

Python bindings for the OpenStreetMap Overpass API.

Build Status

Install it

pip install overpass

Usage

Simplest example:

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

response will be a dictionary representing the JSON output you would get from the Overpass API directly.

Note that the Overpass query passed to get() should not contain any out or other meta statements.

Another example:

>>> print [(
...     feature['properties']['name'],
...     feature['id']) for feature in response["features"]]
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637)]

You can find more examples in the examples/ directory of this repository.

Response formats

You can set the response type of your query using get()'s responseformat parameter to GeoJSON (geojson, the default), plain JSON (json), CSV (csv), and OSM XML (xml).

response = api.get('node["name"="Salt Lake City"]', responseformat="xml")

Parameters

The API object takes a few parameters:

endpoint

The default endpoint is https://overpass-api.de/api/interpreter but you can pass in another instance:

api = overpass.API(endpoint=https://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 sending your query and parse the result, overpass 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:

MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157)
response = api.get(MapQuery)

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:

WayQuery = overpass.WayQuery('[name="Highway 51"]')
response = api.get(WayQuery)

Testing

Using pytest.

py.test

FAQ

I need help or have an idea for a feature

Create a new issue.

Where did the CLI tool go?

The command line tool was deprecated in version 0.4.0.

overpass-api-python-wrapper's People

Contributors

mvexel avatar tbolender avatar themiurgo avatar mharnold avatar johnjohndoe avatar gendelf avatar jose1711 avatar atlefren avatar thepolytheist avatar pe-perry avatar donfaq avatar nebulon42 avatar scott-vsi avatar trypy avatar ydong-vsi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.