Please see the section on the ohsome filter in the ohsome API documentation.
# USAGE:
# after running ohsome-filter-to-sql type in ohsome filter and hit enter
$ uvx ohsome-filter-to-sql
natural = tree and leaftype = broadleaf
('tags @> $1 AND tags @> $2', ('{"natural": "tree"}', '{"leaftype": "broadleaf"}'))uv add ohsome-filter-to-sqlTo generate the SQL WHERE clause (query) alongside its query arguments:
from ohsome_filter_to_sql import ohsome_filter_to_sql
query, query_args = ohsome_filter_to_sql("natural = tree")The generated SQL WHERE clause contains native PostgresSQL syntax for query arguments: $n.
ohsome-filter-to-sql can also be used to validate a give ohsome filter in Python:
from ohsome_filter_to_sql import validate_filter, ParserValueError
validate_filter("natural = tree")
try:
validate_filter("geometry:foo")
except ParserValueError:
passAlternatively, ohsome filter can be validated during runtime with Pydantic:
from ohsome_filter_to_sql import OhsomeFilter
from pydantic import validate_call
@validate_call
def request(ohsome_filter: OhsomeFilter):
passuv run ohsome-filter-to-sqluv run prek install # pre-commit hooks
export OHSOME_FILTER_TO_SQL_SCHEMA=""
export OHSOME_FILTER_TO_SQL_DATABASE=""
export OHSOME_FILTER_TO_SQL_USER=""
export OHSOME_FILTER_TO_SQL_PASSWORD=""
export OHSOME_FILTER_TO_SQL_HOST="localhost"
export OHSOME_FILTER_TO_SQL_PORT="5432"
uv run pytestTo develop new features you will need access to the ohsomeDB in production or a local instance of the ohsomeDB.
Execute antlr4-parse, type in an ohsome filter and press ctlr+d.
antlr4-parse OFL.g4 root -tree
buildings=yes
(root:1 (expression:8 (tagMatch:1 (string:1 buildings) = (string:1 yes))) <EOF>)ANTLR Lab can also be used to try out the grammar.
When the grammar file has changed generate new Python code with antlr4 and move generated files to ohsome_filter_to_sql/.
export ANTLR4_TOOLS_ANTLR_VERSION=$(uv pip show antlr4-python3-runtime | awk '/^Version:/{print $2}')
uv run antlr4 -Dlanguage=Python3 OFL.g4 && mv *.py ohsome_filter_to_sql/This project uses SemVer.
To make a new release run ./scripts/release.sh <version number>.