Coder Social home page Coder Social logo

krafpy / overpass-forge Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 131 KB

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

Home Page: https://pypi.org/project/overpassforge/

License: MIT License

Python 100.00%
openstreetmap openstreetmap-api overpass-api overpass-ql

overpass-forge's Introduction

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. Checkout the documentation.

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

overpass-forge's People

Contributors

krafpy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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.