A library for generating OpenStreetMap's Overpass QL queries from Python objects.
Project description
Overpass Forge: a query builder for the Overpass query language
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
- 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.1.1.tar.gz
(25.3 kB
view details)
Built Distribution
File details
Details for the file overpassforge-0.1.1.tar.gz
.
File metadata
- Download URL: overpassforge-0.1.1.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfb1c771c7f9f64c7a8892df0684923be89b996b4cd223d5ce218fe3f5974a22 |
|
MD5 | 1049ffe3577d144b1e012f1f26df2037 |
|
BLAKE2b-256 | e4ff816ca5a879d891c64289632e4523d39ca4fedfae304897b24aa6d4c33767 |
File details
Details for the file overpassforge-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: overpassforge-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8a18389c8b284b01898b6a00006773276f6abd2f07315cd10e8e74ac9ac0621 |
|
MD5 | d4f48ec7d5fa2928a4bc4234e3b1de49 |
|
BLAKE2b-256 | 7d75497857bd2c25325c6448fe49d3cea0b0062d429e19a48e8f953ba042729d |