mirrorworld.vector: OpenStreetMap features

OpenStreetMap features through the Overpass API as GeoJSON (ODbL). Keep requests modest, or set endpoint to your own Overpass instance.

OpenStreetMap

find_features(north, west, south, east, tags, endpoint='https://overpass-api.de/api/interpreter', session=None)[source]

Fetches OSM features matching tag filters inside a bounding box as a GeoJSON FeatureCollection.

Nodes become Points, ways LineStrings (or Polygons when closed and area-like, see AREA_KEYS), multipolygon relations MultiPolygons. Each feature’s properties hold its OSM tags plus @id (e.g. way/123). Ways and relations are returned whole, so they may extend beyond the box.

Parameters:
  • north (float) – Latitude of the top edge.

  • west (float) – Longitude of the left edge.

  • south (float) – Latitude of the bottom edge.

  • east (float) – Longitude of the right edge.

  • tags (Dict[str, str | bool | Iterable[str]] | Iterable[str]) – Tag filters; see build_query().

  • endpoint (str) – (optional) Overpass interpreter URL.

  • session (Session) – (optional) A requests session.

Returns:

A GeoJSON FeatureCollection (dict).

Return type:

dict

async find_features_async(north, west, south, east, tags, session, endpoint='https://overpass-api.de/api/interpreter')[source]
Parameters:
Return type:

dict

query(ql, endpoint='https://overpass-api.de/api/interpreter', session=None)[source]

Runs a raw Overpass QL query.

Parameters:
  • ql (str) – The query, which should request [out:json].

  • endpoint (str) – (optional) Overpass interpreter URL.

  • session (Session) – (optional) A requests session.

Returns:

The Overpass JSON response.

Return type:

dict

async query_async(ql, session, endpoint='https://overpass-api.de/api/interpreter')[source]
Parameters:
  • ql (str)

  • session (ClientSession)

  • endpoint (str)

Return type:

dict

download_features(north, west, south, east, tags, path, **kwargs)[source]

Same as find_features(), then writes a GeoJSON file.

Parameters:
Returns:

The FeatureCollection.

Return type:

dict

build_query(north, west, south, east, tags, timeout=180)[source]

Builds an Overpass QL query for nodes, ways and relations matching any of the tag filters in a box.

Parameters:
  • tags (Dict[str, str | bool | Iterable[str]] | Iterable[str]) – Either a dict, where each entry is one alternative: {"power": "pole"} (exact value), {"highway": ["footway", "path"]} (any of the values), {"building": True} (any value); or a list of raw Overpass filters, e.g. ['["footway"="sidewalk"]["surface"]'].

  • north (float)

  • west (float)

  • south (float)

  • east (float)

  • timeout (int)

Returns:

The query text.

Return type:

str

to_geojson(response)[source]

Converts an Overpass out geom JSON response to a GeoJSON FeatureCollection.

Parameters:

response (dict)

Return type:

dict

Usage sample:

from mirrorworld.vector import osm

assets = osm.find_features(47.61, -122.34, 47.60, -122.33,
                           {"man_made": "street_cabinet", "power": ["pole", "tower"]})
sidewalks = osm.find_features(47.61, -122.34, 47.60, -122.33, ['["footway"="sidewalk"]'])
osm.download_features(47.61, -122.34, 47.60, -122.33, {"building": True}, "buildings.geojson")