• Stars
    star
    360
  • Rank 117,499 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python bindings for the OpenStreetMap Overpass API

Overpass API python wrapper

Looking for a maintainer Hi there, I am the original author of this project. I no longer have time to maintain it but it looks like it's still useful. I'd like to talk to someone who thinks they can take this on. Drop me a line at [email protected]. Thanks! Martijn van Exel

Python bindings for the OpenStreetMap Overpass API.

Install it

pip install overpass

Usage

API() constructor

First, create an API object.

import overpass
api = overpass.API()

The API constructor takes several parameters, all optional:

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.

Getting data from Overpass: get()

Most users will only ever need to use the get() method. There are some convenience query methods for common queries as well, see below.

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. See verbosity below for how to control the output.

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.

The get() method takes a few parameters, all optional having sensible defaults.

verbosity

You can set the verbosity of the Overpass query out directive using the same keywords Overpass does. In order of increased verbosity: ids, skel, body, tags, meta. As is the case with the Overpass API itself, body is the default.

>>> import overpass
>>> api = overpass.API()
>>> data = api.get('way(42.819,-73.881,42.820,-73.880);(._;>;)', verbosity='geom')
>>> [f for f in data.features  if f.geometry['type'] == "LineString"]

(from a question on GIS Stackexchange)

responseformat

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

If you choose csv, you will need to specify which fields you want, as described here in the Overpass QL documentation. An example:

response = api.get('node["name"="Springfield"]["place"]', responseformat="csv(name,::lon,::lat)")

The response will be a list of lists:

[
    ['name', '@lon', '@lat'],
    ['Springfield', '-3.0645656', '56.2952787'],
    ['Springfield', '0.4937446', '51.7487585'],
    ['Springfield', '-2.4194716', '53.5732892'],
    ['Springfield', '25.5454526', '-33.9814866'],
    ....
]

build

We will construct a valid Overpass QL query from the parameters you set by default. This means you don't have to include 'meta' statements like [out:json], [timeout:60], [out body], etcetera. You just supply the meat of the query, the part that actually tells Overpass what to query for. If for whatever reason you want to override this and supply a full, valid Overpass QL query, you can set build to False to make the API not do any pre-processing.

date

You can query the data as it was on a given date. You can give either a standard ISO date alone (YYYY-MM-DD) or a full overpass date and time (YYYY-MM-DDTHH:MM:SSZ, i.e. 2020-04-28T00:00:00Z). You can also directly pass a date or datetime object from the datetime library.

Pre-cooked Queries: MapQuery, WayQuery

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.

See also

There are other python modules that do similar things.

More Repositories

1

thenandnow

OSM Then And Now
105
star
2

openstreetmap-vintage-tile-server

A Bash script to create a vintage OpenStreetMap tile server
CSS
27
star
3

meetyourmappers

Find other OpenStreetMap mappers around you
JavaScript
26
star
4

osmdiff

A read-only interface to OpenStreetMap diff / change APIs and files.
Python
24
star
5

OSMQualityMetrics

OSMJS script that calculates quality metrics from OpenStreetMap data
JavaScript
19
star
6

next_global_entry

Global Entry Interview Openings Checker
Python
18
star
7

remapatron

MapRoulette (formerly known as the Remap-A-Tron) - remapping the OpenStreetMap road network one deleted way at a time.
JavaScript
17
star
8

bingimageanalyzer

Bing Aerial Image Analyzer for OpenStreetMap
PHP
13
star
9

socrata-geojson

Convert the data from a Socrata SODA 'geo' json endpoint to actual geoJSON
Python
11
star
10

osm-editing-metrics

A suite of scripts that parse OSM files and output meaningful metrics about users and their OSM mapping activity
JavaScript
5
star
11

CamCrowd

Add CCTV Cameras to OpenStreetMap with your iPhone
Objective-C
5
star
12

magical-maproulette-machine

The MMM is a magical MapRoulette Challenge creation / maintenance tool
Python
4
star
13

osmhistoryparser

python script to parse OSM full history XML files and store them in a DB
Python
4
star
14

staleness

Displays OpenStreetMap data staleness in an OpenLayers client.
4
star
15

shape2osm

script to convert POINT shapefiles to OSM XML files
Python
4
star
16

TwitterScraper

scrapes twitter for geotweets mentioning terms of your choice, puts them in PostGIS database
Python
4
star
17

bravemappers

The Brave Mappers Of Wherever You Are
Python
3
star
18

osm-audio-tools

A tiny collection of tools that are useful for audio mapping
Python
3
star
19

maproulette-api-wrapper

A python wrapper for the MapRoulette API
Python
3
star
20

osm-extracts

keep a set of OSM PBF extracts up to date
Python
3
star
21

canvec-ogr2osm-translation

ogr2osm translation file for Canvec 2016 data
Python
3
star
22

whathappened

What happened in this OSM changeset?
Python
2
star
23

OSM-Microtasking-Platform

A configurable platform to deploy microtasks for OSM, built on leaflet.
JavaScript
2
star
24

imposm.parser

A mirror of my BitBucket fork of olt's imposm.parser
C++
2
star
25

maproulette2-dead

New MapRoulette
2
star
26

osmhistoryretriever

Objective-C
2
star
27

makeyourfirstmap

I use this to teach people how to make web maps using simple, free and open tools.
CSS
2
star
28

Anticipation

Mac OSX Status Bar item counting down to a date you set.
Objective-C
2
star
29

opengeofiction-tools

Some scripts / tools to make my life on OpenGeoFiction easier
Shell
2
star
30

osmcameras_gearth

View CCTV camera locations from OpenStreetMap in Google Earth
Python
2
star
31

NBI-convert

scripts to convert the ASCII files from the National Bridge Inventory to a shapefile, filtering out pure 'road over road' type bridges.
Python
2
star
32

osrm-processing-script

Shell script to update local planet, prepare new OSRM data, and shut down EC2 instance
Shell
2
star
33

gpxtouch

python script to update modification date of GPX files according to the most recent trackpoint in the file.
Python
1
star
34

python-osmium-examples

A set of examples showing practical usage of PyOsmium, a thin wrapper around the osmium library.
Python
1
star
35

osm-gradesep

analysis of grade separations in OpenStreetMap using PostGIS
Python
1
star
36

usermetrics

OSM full history parser for user metrics
Python
1
star
37

abcde-mac-autorip

rip cd's on insert no itunes no hands
Shell
1
star
38

us-poly

OpenStreetMap POLY files for the United States
1
star
39

battlegrid2

OpenStreetMap US BattleGrid DESPECIALIZED EDITION
JavaScript
1
star
40

maproulette-loader

Challenge loader for MapRoulette
Python
1
star
41

gnismicrotasking

microtasking web app for GNIS points in OSM
Python
1
star
42

whotouchedme

Who touched the things I edited in OSM?
Python
1
star
43

osmoauth

simple example flask app with OpenStreetMap OAuth authentication
Python
1
star
44

sqftenvy

Python
1
star
45

llparse

parse a dirty string containing some N-American coordinates and redirect to openstreetmap.org
Python
1
star
46

py-openstreetmap

OpenStreetMap objects, python-friendly
Python
1
star
47

overpass-guide

A beginner's guide to using the OpenStreetMap Overpass API
1
star
48

osm-editorbreakdown

python script to parse editor information out of changesets-latest.osm.bz
Python
1
star
49

hdsrchart

A simple demo for the HDSR API, drawing a chart of water levels for a specific (hard coded) sensor.
Python
1
star
50

VisitUtah

A web.py recipe for leeching an open dir of webcam images and throwing out the bad ones (black / white / 'image not availble').
Python
1
star