Package: aio-overpass
A client for theOverpass API, a read-only API that serves up custom selected
parts ofOpenStreetMapdata.The Overpass API is optimized for data consumers that need a few elements within
a glimpse or up to roughly 10 million elements in some minutes, both selected by
search criteria like location, type of objects, tag properties, proximity, or
combinations of them. To make use of it, you should familiarize yourself withOverpass QL, the query language used to select the elements that you want.ContentsFeaturesGetting StartedChoosing ExtrasBasic UsageExampleCoordinatesSee alsoAn overview of modules, classes and functions can be found in theAPI referenceThere are some notebooks to check out inexamples/The version history is available inCHANGELOG.mdDevelopers can find some instructions inCONTRIBUTING.mdThe Overpass APIrepository,
itsblog,
itsuser's manualand  itsrelease notesOverpass Turboto prototype your queries in your browserFeaturesAsynchronous requests usingaiohttpParallel queries within rate limitsFault tolerance through a (customizable) retry strategyExtensionsTyped elements that simplify browsing result setsShapelygeometries for manipulation and analysisGeoJSONexportsSimplified querying and processing of public transportation routesDesign GoalsA small and stable set of core functionality.Good defaults for queries and retrying.Room for extensions that simplify querying and/or processing of spatial data
in specific problem domains.Sensible and spec-compliant GeoJSON exports for all objects that represent spatial features.Detailed documentation that supplements learning about OSM and the Overpass API.Getting Startedpipinstallaio-overpass
pipinstallaio-overpass[shapely,networkx,joblib]poetryaddaio-overpass
poetryaddaio-overpass[shapely,networkx,joblib]Choosing ExtrasThis library can be installed with a number of optional extras.Install no extras, if you're fine withdictresult sets.Install theshapelyextra, if you would like the convenience of typed OSM elements.
It is also useful if you are interested in elements' geometries,
and either already use Shapely, or want a simple way to exportGeoJSON.This includes theptmodule to make it easier to interact with public transportation routes.
Something seemingly trivial like listing the stops of a route can have unexpected pitfalls,
since stops can have multiple route members, and may have a range of different tags and roles.
This submodule will clean up the relation data for you.Install thenetworkxextra to enable thept_orderedmodule, if you want a route's path as a
simple line from A to B. It is hard to do this consistently, mainly because ways are not always
ordered, and stop positions might be missing. You can benefit from this submodule if you wish torender a route's path between any two stopsmeasure the route's travelled distance between any two stopsvalidate the order of ways in the relationcheck if the route relation has gapsInstall thejoblibextra to speed uppt_ordered.collect_ordered_routes(), which can benefit
greatly from parallelization.Basic UsageThere are three basic steps to fetch the spatial data you need:Formulate a queryEither write your own custom query, f.e.Query("node(5369192667); out;"),or use one of theQuerysubclasses, f.e.SingleRouteQuery(relation_id=1643324).Call the Overpass APIPrepare your client withclient = Client(user_agent=...).Useawait client.run_query(query)to fetch the result set.Collect resultsEither access the raw result dictionaries withquery.result_set,or use a collector, f.e.collect_elements(query)to get a list of typedElements.Collectors are often specific to queries -collect_routesrequires aRouteQuery,
for instance.ExampleResults as Dictionariesfromaio_overpassimportClient,Queryquery=Query("way(24981342); out geom;")client=Client()awaitclient.run_query(query)query.result_set[{"type":"way","id":24981342,# ..."tags":{"addr:city":"Hamburg","addr:country":"DE","addr:housename":"Elbphilharmonie",# ...},}]Results as Objectsfromaio_overpass.elementimportcollect_elementselems=collect_elements(query)elems[0].tags{"addr:city":"Hamburg","addr:country":"DE","addr:housename":"Elbphilharmonie",# ...}Results as GeoJSONimportjsonjson.dumps(elems[0].geojson,indent=4){"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[9.9832434,53.5415472],...]]},"properties":{"id":24981342,"type":"way","tags":{"addr:city":"Hamburg","addr:country":"DE","addr:housename":"Elbphilharmonie",...},...},"bbox":[9.9832434,53.540877,9.984967453.5416212,]}CoordinatesGeographic point locations are expressed by latitude (lat) and longitude (lon) coordinates.Latitude is given as an angle that ranges from –90° at the south pole to 90° at the north pole,
with 0° at the Equator.Longitude is given as an angle ranging from 0° at the Prime Meridian (the line that divides the
globe into Eastern and Western hemispheres), to +180° eastward and −180° westward.lat/lonvalues arefloatsthat are exactly those degrees, just without the ° sign.This might help you remember which coordinate is which:If you think of a world map, usually it’s a rectangle.Thelongside (the largest side) is the longitude.Longitude is the x-axis, and latitude is the y-axis.Be wary of coordinate order:The Overpass API explicitly names the coordinates:{ "lat": 50.2726005, "lon": 10.9521885 }Shapely geometries returned by this library uselat/lonorder, which is the order
stated byISO 6709, and seems like the most common order.GeoJSON, on the other hand, useslon/latorder.OpenStreetMap uses theWGS84spatial reference system
used by the Global Positioning System (GPS).OpenStreetMap node coordinates have seven decimal places, which gives them centimetric precision.
However, the position accuracy of GPS data is onlyabout 10m.
A reasonable display accuracy could be five places, which is precise to1.1 metresat the equator.Spatial features that cross the 180th meridian areproblematic,
since you go from longitude180.0to-180.0.
Such features usually have their geometries split up, like thearea of Russia.