https://github.com/krafpy/overpass-forge
A library for generating OpenStreetMap's Overpass QL queries from Python objects.
https://github.com/krafpy/overpass-forge
openstreetmap openstreetmap-api overpass-api overpass-ql
Last synced: about 2 months ago
JSON representation
A library for generating OpenStreetMap's Overpass QL queries from Python objects.
- Host: GitHub
- URL: https://github.com/krafpy/overpass-forge
- Owner: Krafpy
- License: mit
- Created: 2023-08-07T11:45:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-09T09:50:35.000Z (over 1 year ago)
- Last Synced: 2025-03-04T09:18:42.748Z (about 2 months ago)
- Topics: openstreetmap, openstreetmap-api, overpass-api, overpass-ql
- Language: Python
- Homepage: https://pypi.org/project/overpassforge/
- Size: 128 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Overpass Forge: a query builder for the Overpass query language
[](https://pypi.org/project/overpassforge/)

[](https://overpassforge.readthedocs.io/en/latest/?badge=latest)
An object-oriented model to build Overpass queries in Python. Primarly intended
to generate complex queries in Python. Checkout the [documentation](https://overpassforge.readthedocs.io/en/latest/).## Install
Requires **Python 3.10 or higher**. Install with:
```cmd
pip install overpassforge
```## Example
```python
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 nodesbus_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:
```text
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](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL).
- Settings: all except augmented-difference between dates (*adiff*)
- Block statements
- [x] union, difference, intersection
- [ ] For-each loop (*foreach*)
- [ ] Block statements *if, for, complete, retro, compare*
- Standalone statements
- [x] out
- [x] Item (implicit)
- [x] Recurse up (<) and down (>)
- [x] Recurse up relations (<<) and down (>>)
- [x] Query for areas (*is_in*)
- [ ] Statements *timeline*, *local*, *convert*, *make*
- [x] The Query Statement (*node, way, rel, area* **only**)
- [ ] The Query Filter
- [x] Map way/relation to area (*map_to_area*)
- Filters
- [x] By tag (*has-kv*)
- [x] Bounding box
- [ ] Recurse (*n, w, r, bn, bw, br*)
- [ ] Recurse (way_cnt, way_link)
- [x] By input set (*.setname*)
- [x] By element id
- [x] Relative to other elements (*around*)
- [x] By polygon (*poly*)
- [x] *newer*
- [x] By date of change (*changed*)
- [x] By user (*user, uid*)
- [x] By area (*area*)
- [x] Area pivot (*pivot*)
- [ ] Conditional query filter (*if:*)## Contributing
### Setup the development environment
#### Windows
```cmd
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
```#### Linux
```cmd
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
```### Unit tests
Run all the tests with:
```cmd
python -m pytest ./tests
```