Skip to main content

A library for generating OpenStreetMap's Overpass QL queries from Python objects.

Project description

Overpass Forge: a query builder for the Overpass query language

PyPI latest version License Documentation status CI tests

An object-oriented model to build Overpass queries in Python. Primarly intended to generate complex queries in Python.

Install

Requires Python 3.10 or higher. Install with:

pip install overpassforge

Example

from overpassforge import Areas, Nodes, Ways, build, beautify

# Find both cinema nodes and ways in Bonn, which
# are at most 100m away from bus stop nodes

bus_stops = Nodes(within=Areas(name="Bonn"), highway="bus_stop")
ways = Ways(around=(bus_stops, 100.0)).where(amenity="cinema")
nodes = Nodes(around=(bus_stops, 100.0)).where(amenity="cinema")
result = ways + nodes
result.out("meta")

query = build(result)
print(beautify(query))

Output:

area["name"="Bonn"]->.set_0;
node(area.set_0)["highway"="bus_stop"]->.set_1;
(
  way(around.set_1:100.0)["amenity"="cinema"];
  node(around.set_1:100.0)["amenity"="cinema"];
);
out meta;

Features

List of currently implemented features, based on the Overpass QL wiki.

  • Settings: all except augmented-difference between dates (adiff)
  • Block statements
    • union, difference, intersection
    • For-each loop (foreach)
    • Block statements if, for, complete, retro, compare
  • Standalone statements
    • out
    • Item (implicit)
    • Recurse up (<) and down (>)
    • Recurse up relations (<<) and down (>>)
    • Query for areas (is_in)
    • Statements timeline, local, convert, make
    • The Query Statement (node, way, rel, area only)
    • The Query Filter
    • Map way/relation to area (map_to_area)
  • Filters
    • By tag (has-kv)
    • Bounding box
    • Recurse (n, w, r, bn, bw, br)
    • Recurse (way_cnt, way_link)
    • By input set (.setname)
    • By element id
    • Relative to other elements (around)
    • By polygon (poly)
    • newer
    • By date of change (changed)
    • By user (user, uid)
    • By area (area)
    • Area pivot (pivot)
    • Conditional query filter (if:)

Contributing

Setup the development environment

Windows

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt

Linux

python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

Unit tests

Run all the tests with:

python -m pytest ./tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

overpassforge-0.4.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

overpassforge-0.4.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file overpassforge-0.4.1.tar.gz.

File metadata

  • Download URL: overpassforge-0.4.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for overpassforge-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2bfb50cd23608961b13ab07358bc480940dfed32f0dbc1ccdb25967d3ccac597
MD5 ef7910ba2e4be9460b5c471537d6a574
BLAKE2b-256 f836bf8bb2d61c2574a0a7b45a20419a7f038c8167ff3e9207a28f5cdcf0848b

See more details on using hashes here.

File details

Details for the file overpassforge-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for overpassforge-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90a3387a7abda67c2bcbb82f92c7146557e7f637b1e00c2792f100b5a8dfb532
MD5 0694e1db484fd92cf05234b95e210502
BLAKE2b-256 a69b76245fcf434cee63e983537bd4e452926e83a321a777f9a5a213a5d5b7a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page