OSMnx underwent a major overhaul this summer, with the development of several new features, improvements, and optimizations. This project concluded yesterday with the release of v0.16.0.
This post briefly summarizes what’s changed since the previous mid-summer updates. It covers the new k shortest paths solver, auto-selecting the first polygon when geocoding, better conversion of graph types, and the new geometries module that lets you flexibly download any OSM geospatial objects as a geopandas GeoDataFrame.
First, check out those two previous updates covering what was new along the way, including topological intersection consolidation, automatic max speed imputation and travel time calculation, querying historical OSM snapshots by date, improved visualization and plotting, better graph simplification, a new geocoder module, and API streamlining and efficiency improvements throughout. Here’s what’s new since then…
New geometries module
The footprints and pois modules have been deprecated in the current release and will be removed in a future release. They have been replaced by the new geometries module, which is a more flexible and powerful replacement enabling users to download any geospatial objects from OSM as a GeoDataFrame.
The geometries module uses the same tag:value querying logic as the deprecated pois module did. Those deprecated modules’ functions, such as pois_from_place() or footprints_from_place(), are replaced by the geometries module’s new geometries_from_place() (and equivalent) functions. For example, to download all the building footprints in some place as a GeoDataFrame:
gdf = ox.geometries_from_place(place, tags={'building':True})
Or, to get all local amenities, objects tagged landuse = either retail or commercial, and objects tagged highway = bus_stop:
tags = {'amenity':True, 'landuse':['retail','commercial'], 'highway':'bus_stop'} gdf = ox.geometries_from_place(place, tags)
Auto-select first polygon when geocoding
In the past, OSMnx’s geocode_to_gdf() function would geocode queries to the first result provided by Nominatim, regardless of its geometry type. This often caused (somewhat confusing) extra work when trying to get place boundaries: if the first result was a point, the user would have to increment the which_result argument until it found the first polygon.
In the latest release, OSMnx by default now auto-selects the first polygon or multipolygon geometry when geocoding to a GeoDataFrame:
gdf = ox.geocode_to_gdf('Alameda, California')
If you want to retrieve the first geocoding result, regardless of its geometry type, pass a which_result argument:
gdf = ox.geocode_to_gdf('Alameda, California', which_result=1)
Use which_result similarly to retrieve any specific result.
Solve k shortest paths
The latest release of OSMnx includes a new shortest_path convenience function and a new k_shortest_paths function to solve k shortest paths from an origin to a destination:
routes = ox.k_shortest_paths(G, origin, destination, k=30, weight='travel_time')
The code above will return the 30 shortest paths by travel time between some origin and destination.
Better DiGraph conversion
Finally, the latest OSMnx release includes a new get_digraph function to correctly convert a MultiDiGraph to a DiGraph by choosing between parallel edges to minimizing some weight attribute value:
ox.utils_graph.get_digraph(G, weight='length')
This function is useful for algorithms that cannot handle parallel edges in the graph. See also the similar get_undirected function to convert a MultiDiGraph to a MultiGraph by maintaining parallel edges only when their geometries differ (which is important in modeling a street network).
Conclusion
For more information, check out the two previous mid-summer updates on this project’s progress and changes. Also see the current OSMnx documentation and usage examples.
2 replies on “OSMnx Summer Wrap-Up”
[…] Update: as of v0.16.0, the pois module and functionality has been incorporated into and superseded by the new geometries module: more info. […]
[…] of this development occurred in a major overhaul over the summer, which I covered at the time in three previous posts. Among these dozens of enhancements were major speed and efficiency improvements […]