Package: osmrx
OsmRxA geographic Python library to extract Open Street Map roads (and POIs) from a location or a bounding box, in order to create a graph thanks toRustworkx. OsmRx is able to clean a network based on Linestring geometries and connect Point geometries. The graph built is able to process graph-analysis (shortest-path, isochrones...)Capabilities:load data from a location name or a bounding box (roads and pois)graph creation (and topology processing and cleaning)shortest pathisochrone builderCheck the demohereHow to install it ?with pippipinstallosmrxHow to use it ?Check the jupyter notebookhereCheck the wiki: TODOGet POIsFind the Points of interest from a location (Point(s)) or a bounding box:OSM attributes are returnedfeatures ready to be used with shapely, GeoPandas (...):fromosmrx.main.poisimportPoislocation_name="lyon"# Initialize the Pois classpois_object=Pois()# call .from_location(location: str) or .from_bbox(bounds: Tuple[float, float, float, float]) to get data from your locationpois_object.from_location(location_name)# nominatim api is used to get Lyon coordinates# It returns a list of dictionnaries [{"geometry": Point(...), "attribute": "...", ...}# Free for you to use it with GeoPandas or something else (epsg=4326)pois_data_found=pois_object.dataGet RoadsFind the vehicle or pedestrian network (LineString(s)) from a location or a bounding box:OSM attributes availableOSM features ready to be used with shapely, GeoPandas (...):data cleaned regarding classical topology rulesfromosmrx.main.roadsimportRoads# Choose the vehicle or the pedestrian networkroads_object=Roads("vehicle")# from_location(location: str) is availableroads_object.from_bbox({6.019674,4.023742,46.072575,4.122018})# It returns a list of dictionnaries [{"geometry": Point(...), "attribute": "...", ...}# Free for you to use it with GeoPandas or something else (epsg=4326)roads_data_found=roads_object.data# return the rustworkx graph (directed for vehicle / undirected for pedestrian)graph=roads_object.graph# Free for you to compute graph analysisCompute a shortest pathCompute the shortest path from an ordered list of Point(s) (at least 2)fromshapelyimportPointfromosmrx.main.roadsimportGraphAnalysis# use the GraphAnalysis class and set:# the network type (pedestrian or vehicle) and an ordered list of 2 Shapely Points defining the source and the target# of your shortest path)analysis_object=GraphAnalysis("pedestrian",[Point(4.0793058,46.0350304),Point(4.0725246,46.0397676)])# (epsg=4326)paths_built=analysis_object.get_shortest_path()forpath_objectinpaths_built:print(path_object.path)# LineString shortest path (epsg=4326)print(path_object.features())# List of LineString (with osm attributes) composing the path foundCompute an IsochroneBuild an isochrone (Polygon(s)) from a PointfromshapelyimportPointfromosmrx.main.roadsimportGraphAnalysis# use the GraphAnalysis class and set:# the network type (pedestrian or vehicle) and a list of one Shapely Point (epsg=4326) to build the isochoneanalysis_object=GraphAnalysis("vehicle",[Point(4.0793058,46.0350304)])# Set the distance intervals to compute the isochone with a list of integer or floatisochrones_built=analysis_object.isochrones_from_distance([0,250,500,1000,1500])# List of Polygons with a distance attributes based on the intervals definedprint(isochrones_built.data)