GithubHelp home page GithubHelp logo

digideskio / overpass-api-python-wrapper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mvexel/overpass-api-python-wrapper

0.0 1.0 0.0 151 KB

A thin Python wrapper around the OpenStreetMap Overpass API

License: Apache License 2.0

Python 100.00%

overpass-api-python-wrapper's Introduction

Overpass API python wrapper

This is a thin wrapper around 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"]')

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

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.

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

Parameters

The API object takes a few parameters:

endpoint

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

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 <http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Completed_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)

Testing

Using nose.

py.test

FAQ

I need help or have an idea for a feature

Create a new issue.

Where did the CLI tool go?

I decided that it does not belong in this repo. If you still want it, get version 0.4.0 or below.

overpass-api-python-wrapper's People

Contributors

atlefren avatar gendelf avatar johnjohndoe avatar jose1711 avatar mharnold avatar mvexel avatar nebulon42 avatar tbolender avatar themiurgo avatar thepolytheist avatar trypy avatar

Watchers

 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.