API Reference
Base classes
- class overpassforge.base.Statement(label=None)
Represents a generic Overpass QL statement.
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.base.Set(filters=[], label=None)
Represents a set, i.e. a statement that always returns a set of elements.
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- out(*options)
Indicate that this set must be outputed.
- Parameters:
options (
str|tuple[float,float,float,float]) – empty or any combination of “ids”, “skel”, “body”, “tags”, “meta”, “noids”, “geom”, “bb”, “center”, “asc”, “qt”, “count” or a bounding box (south,west,north,east).- Raises:
ValueError – Invalid output options.
- filter(*filters)
Adds filters to the set.
- where(*keys, **tags)
Adds filters “key”, ~”key”, “key”=”value”, or “key”~”value”.
- within(area)
Filters the elements that are in the specified area.
- Parameters:
area (
tuple[float,float,float,float] |BoundingBox|Polygon|Area|Areas) – A bounding box (filter object or as a tuple), polygon filter, area filter or set of areas.- Return type:
- intersection(*others)
Returns the statement computing the intersection of this statement with the others.
- changed_since(date)
Filters the elements that were changed since the specified datetime.
- Parameters:
date (
datetime) – The lower bound of change dates to consider- Return type:
- changed_between(lower, upper)
Filters the elements that were changed between the two specified dates.
- Parameters:
lower (datetime) – Lower bound datetime.
upper (datetime) – Upper bound datetime.
- Return type:
- last_changed_by(*users)
Filters the elements that last changed by any of the given users.
- Parameters:
users (
str|int) – The list of user names or user ids.- Return type:
- outlines_of(area)
Filters the elements that are part of the outline of the given area.
- around(radius, other=None, lats=None, lons=None)
Filters elements that are within a given radius of the elements of another set or a list of given coordinates (cannot specify both).
- recursed_down()
Returns the recursed down (
>) set.- Return type:
- recursed_down_rels()
Returns the recursed down relations (
>>) set.- Return type:
- recursed_up_rels()
Returns the recursed up relations (
<<) set.- Return type:
- overlapping_areas()
Returns the set of areas that overlap at least one of the elements of this set.
- Return type:
- elements(*filters)
Returns the elements (nodes, ways, relations) in this set.
- Return type:
Statements
- class overpassforge.statements.RawStatement(raw='', label=None, **dependencies)
Bases:
StatementRepresents a raw Overpass query string. It can be formated to support dependency from other statements (raw or not).
Example:
>>> foo = Nodes().where(name="Foo") >>> bar = Statement("node.{x}[amenity=\"bar\"]->.{:out_var};", x=foo) >>> baz = Nodes(input_set=bar).within((50.6,7.0,50.8,7.3)) >>> print(build(baz)) node["name"="Foo"]->.set_0; node.set_0[amenity="bar"]->.set_1; node.set_1(50.6,7.0,50.8,7.3);
- Parameters:
raw (
str) – A formatable string of the query. Named placeholders (e.g. “{name}”) indicating dependency on other statements. An optional special {:out_var} placeholder indicates where the name of the output set must be placed.dependencies (
Statement) – The list of statements whose results it depends on Their keyword names must match the placeholders in the raw query string.
- Raises:
ValueError – Invalid unamed placholder “{}”.
- class overpassforge.statements.Elements(ids=None, label=None, *, bounding_box=None, input_set=None, within=None, around=None, filters=[], **tags)
Bases:
SetRepresents a query set, e.g. node, rel, way…
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.Nodes(ids=None, label=None, *, bounding_box=None, input_set=None, within=None, around=None, filters=[], **tags)
Bases:
ElementsA node query.
Example:
>>> all_nodes = Nodes(bounding_box=(50.6,7.0,50.8,7.3)) >>> cinemas = all_nodes.where(amenity="cinema") >>> non_cinemas = all_nodes - cinemas >>> print(build(non_cinemas)) node(50.6,7.0,50.8,7.3)->.set_0; (.set_0; - node.set_0["amenity"="cinema"];);
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.Ways(ids=None, label=None, *, bounding_box=None, input_set=None, within=None, around=None, filters=[], **tags)
Bases:
ElementsA way query.
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.Relations(ids=None, label=None, *, bounding_box=None, input_set=None, within=None, around=None, filters=[], **tags)
Bases:
ElementsA relation query.
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.Areas(ids=None, label=None, *, bounding_box=None, input_set=None, within=None, around=None, filters=[], **tags)
Bases:
ElementsAn area query.
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.Union(*statements, label=None)
Bases:
CombinationRepresents a union of sets: (set_1; set_2; …);
Example:
>>> union = Union(Ways(42), Nodes(42)) >>> print(build(union)) (way(42); node(42)); >>> union = Ways(42) + Nodes(42) >>> print(build(union)) (way(42); node(42));
- Parameters:
statements (
Set) – The list of statement whose results to combine.
- class overpassforge.statements.Difference(a, b, label=None)
Bases:
CombinationRepresents the difference of two sets: (set_1 - set_2;);
Example:
>>> bbox_ways = Ways(bounding_box=(50.6,7.0,50.8,7.3)) >>> one_way = Ways(41) >>> print(build(Difference(bbox_ways, one_way))) (way(50.6,7.0,50.8,7.3); - way(42);); >>> print(build(bbox_ways - one_way)) (way(50.6,7.0,50.8,7.3); - way(42););
- class overpassforge.statements.RecurseDown(input_set, label=None)
Bases:
_RecurseRecurse down elements (
>). Takes an input set and produces a set composed of: - all nodes that are part of a way which appears in the input set; plus - all nodes and ways that are members of a relation which appears in the input set; plus - all nodes that are part of a way which appears in the result set.(taken from the Overpass QL documentation)
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.RecurseDownRels(input_set, label=None)
Bases:
_RecurseRecurse down relations (
>>). Similar to simple recurse down but also it continues to follow the membership links including nodes in ways until for every object in its input or result set all he members of that object are in the result set as well.(taken from the Overpass QL documentation)
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.RecurseUp(input_set, label=None)
Bases:
_RecurseRecurse up elements (
<). Takes an input set and produces a set composed of: - all ways that have a node which appears in the input set; plus - all relations that have a node or way which appears in the input set; plus - all relations that have a way which appears in the result set.(taken from the Overpass QL documentation)
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.RecurseUpRels(input_set, label=None)
Bases:
_RecurseRecurse up relations (
<<). Similar to simple recurse up but also it continues to follow backlinks onto the found relations until it contains all relations that point to an object in the input or result set.(taken from the Overpass QL documentation)
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
- class overpassforge.statements.OverlappingAreas(lat=None, lon=None, input_set=None, label=None)
Bases:
AreasCorresponds to the
is_instatement. Represents the areas and closed ways that cover: - the given coordinates (when specified) or - one or more nodes from the input set (when no coordinates are specified).(taken from the Overpass QL documentation)
- Parameters:
label (
Optional[str]) – A label for this statement which may be used as variable name for the result of this statement at compilation.
Filters
- class overpassforge.filters.Filter(raw=None)
Bases:
objectRepresents a generic filter that can be applied on a query statement.
- class overpassforge.filters.Regex(pattern)
Bases:
objectWrapper around a string to indicate it should be treated as a regex.
- class overpassforge.filters.Tag(comparison, case_sensitive=True)
Bases:
FilterRepresents a generic tag filter.
- Parameters:
comparison (
str) – the comparison expression string of the tag filter (e.g. “name”=”Foo”, !”tourism”)case_sensitive – ignore case (e.g. if comparison is “name”=”Foo” then a tag “name”=”fOO” is also valid)
- class overpassforge.filters.Key(key, case_sensitive=True)
Bases:
TagRepresents a key of an element’s tags. Used to build tag filter expressions.
Examples:
>>> Key("amenity") <Tag "amenity", case=True> >>> ~Key("amenity") <Tag !"amenity", case=True> >>> Key("amenity") == "cinema" <Tag "amenity"="cinema", case=True> >>> Key("name", case_sensitive=False) == Regex("^Foo$") <Tag "name"~"^Foo$", case=False> >>> Key(Regex("^addr:.*$")) != Regex("^Foo$") <Tag ~"^addr:.*$"!~"^Foo$", case=True>
- Parameters:
key (
str|Regex) – The key string.
- class overpassforge.filters.BoundingBox(south, west, north, east)
Bases:
FilterBounding box filter on a query statement.
- Parameters:
south (
float) – Minimum latitude.west (
float) – Minimum longitude.north (
float) – Maximum latitude.east (
float) – Maximum longitude.
- class overpassforge.filters.Ids(*ids)
Bases:
FilterRepresents an id filter.
- Parameters:
ids (
int) – The list of OSM ids to select.
- class overpassforge.filters.Intersect(*statements)
Bases:
FilterIntersection with other statement results.
- Parameters:
statements (
Statement) – The other statement whose results intersect with.
- class overpassforge.filters.Newer(date)
Bases:
FilterFilter by newer change dates.
- Parameters:
date (
datetime) – The oldest when the element has been modified.
- class overpassforge.filters.Changed(lower, upper=None)
Bases:
FilterFilter that selects elements that have been changed between two given dates. If only the lower date is given, the second is assumed to be the front date of the database.
- Parameters:
lower (
datetime) – Dates’ range lower bound.upper (
Optional[datetime]) – Dates’ range upper bound. If not given, it is assumed to be the front date of the database.
- class overpassforge.filters.User(*users)
Bases:
FilterFilter the elements last edited by the specified users.
- Parameters:
users (
int|str) – A list of user names or user ids.- Raises:
ValueError – No user specified.
- class overpassforge.filters.Area(input_area)
Bases:
FilterFilters the elements which are within the given area.
- Parameters:
input_area (
Areas) – The areas in which the elements must lay in.
- class overpassforge.filters.Pivot(input_area)
Bases:
FilterFilters the elements which are part of the outline of the given area.
- Parameters:
input_area (
Areas) – The areas to consider the outlines of.
- class overpassforge.filters.Around(radius, input_set=None, lats=None, lons=None)
Bases:
FilterFilters elements within a certain radius around elements in the input set.
- Parameters:
radius (
float) – The radius in meters around each elements.input_set (
Optional[Statement]) – The input set of elements around which to filter (cannot be used in combination with lats, lons).lats (
Optional[Iterable[float]]) – Latitude and longitudes of points around which to filter (cannot be used in combination with input_set).lons (
Optional[Iterable[float]]) – Latitude and longitudes of points around which to filter (cannot be used in combination with input_set).
Builder
- class overpassforge.builder.Settings(out='json', timeout=25, maxsize=None, bbox=None, date=None, diff=None, csv_fields=None, csv_header_line=True, csv_separator=None)
Global settings of an Overpass query. See the Overpass reference for more details.
-
out:
Literal['json','xml','csv'] = 'json'
-
timeout:
Optional[int] = 25
-
maxsize:
Optional[int] = None
-
bbox:
Optional[tuple[float,float,float,float]] = None
-
date:
Optional[datetime] = None
-
diff:
UnionType[tuple[datetime],tuple[datetime,datetime],None] = None
-
csv_fields:
Optional[tuple[str,...]] = None
-
csv_header_line:
bool= True
-
csv_separator:
Optional[str] = None
-
out:
- overpassforge.builder.build(*statements, settings=None, beautify=False)
Builds the Overpass query string of the given statement, with the optional global settings.
- Parameters:
statement – The statement to compile.
settings (
Optional[Settings]) – Global query settings to append at the top of the generated query.beautify (
bool) – If True, generates a more readable query (indentations, line breaks…)
- Return type:
str- Returns:
The compiled Overpass query.
- Raises:
CircularDependencyError – One of the substatements requires its own result.
InvalidFilterAttributes – Invalid filter.
InvalidQuerySettings – Invalid query settings.
UnexpectedCompilationError – Unexpected internal compilation error.