I'm tryin to use osmnx to calculate shortest path, I have that working without issue. My question regards the selection of suitable roads for walking along. I can set the network_type='walk' and run the following:
G = ox.graph_from_point((self.selected_origin.Lat, self.selected_origin.Long), dist=dist, network_type='walk', simplify=False, custom_filter=cf)
I've noticed that the paths go onto dual carriageways, so I'm investigating the custom_filter option.
Question 1: Is there a list of all path types anywhere? I've found the following options:
cf =["highway"~"bridleway|corridor|elevator|footway|living_street|path|pedestrian|primary|primary_link|residential|secondary|secondary_link|service|steps|tertiary|tertiary_link|track|trunk|trunk_link|unclassified"]'
The above does not limit travel on 2 lane dual carriageways, these seem to be classed as trunk, removing this from the list takes out all trunk roads not just dual carriageways.
Question 2: How could I specify to omit 2+ lane carriageways (trunk roads)?
Related
I spent a lot of time reading and testing the example notebooks of OSMnx but I couldn't figure out a way to simply calculate the travel time from a given point (GPS coordonates) to an other one.
I would like to estimate, for each point from my list, how long it takes to go to a specific point (sometimes 100km away). I don't need to generate a graph/map/plot, as I only need the duration of each trip (and I think that OSMnx maps render better at a city-scale).
I am pretty desperate as I could not find a simple way to do this across different Python libraries... If doing this calculation for +-10k points within a country-scale map is asking too much from OSMnx, could a locally stored pbf file of the country be helpful for another solution?
There are inherent trade-offs when you want to model a large study area such as an entire region or an entire country: 1) model precision vs 2) area size vs 3) memory/speed. You need to trade off one of these three.
For the first, you can model a coarser-grained network, such as only major roads in the region/country, rather than millions of fine-grained residential streets and paths. For the second, you can study a smaller area. For the third, you can provision a machine with lots of memory and then let the script run for a while to complete the process. What you trade off will be up to your own needs for this analysis.
In the example code below, I chose to trade off #1: I've modeled this region (West Midlands) by its motorways and trunk roads. Given a different analytical goal, you may trade off other things instead. After creating the model, I randomly sample 1000 origin and destination lat-long points, snap them to the nearest nodes in the graph, and solve the shortest paths by travel time (accounting for speed limits) with multiprocessing.
import osmnx as ox
# get boundaries of West Midlands region by its OSM ID
gdf = ox.geocode_to_gdf('R151283', by_osmid=True)
polygon = gdf.iloc[0]['geometry']
# get network of motorways and trunk roads, with speed and travel time
cf = '["highway"~"motorway|motorway_link|trunk|trunk_link"]'
G = ox.graph_from_polygon(polygon, network_type='drive', custom_filter=cf)
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)
# randomly sample lat-lng points across the graph
origin_points = ox.utils_geo.sample_points(ox.get_undirected(G), 1000)
origin_nodes = ox.nearest_nodes(G, origin_points.x, origin_points.y)
dest_points = ox.utils_geo.sample_points(ox.get_undirected(G), 1000)
dest_nodes = ox.nearest_nodes(G, dest_points.x, dest_points.y)
%%time
# solve 1000 shortest paths between origins and destinations
# minimizing travel time, using all available CPUs
paths = ox.shortest_path(G, origin_nodes, dest_nodes, weight='travel_time', cpus=None)
# elapsed time: 9.8 seconds
For faster modeling, you can load the network data from a .osm XML file instead of having to make numerous calls to the Overpass API. OSMnx by default divides your query area into 50km x 50km pieces, then queries Overpass for each piece one a time to not exceed the server's per-query memory limits. You can configure this max_query_area_size parameter, as well as the server memory allocation, if you prefer to use OSMnx's API querying functions rather than its from-file functionality.
I'm working me throu the impressiv OSMnx jupyter notebook of gboenig, I'm a MA Architecture Student from Germany and would like to use some Code to bring some fundametal Arguments to my MasterThesis, so I tried a lot and I'm very happy with the possibilities and the results. But there is one scenario that i want to evaluate:
First, all of my questions based on the osmnx-examples from Geoff Boeing (https://github.com/gboeing/osmnx-examples/tree/master/notebooks) so I don't post code snippets because there are no changes at the moment.
My idea is to analyse the impact of changing the maxspeed in some streets to raise the traveltime and force the driver to use another way throu the area, so that the lineare distance isn't the fastest way.
For this I made 2 OSM Files with JOSM, one with the current status and one with my changes.
To simplify I have the picture below:
Shortest - Fastest Way
The Red Vector is the shortest way, but with the parameter maxspeed from OSM the blue one could be the fastest, and I would like to analyse witch ways I have to manipulate to get the result I'm looking for.
From the OSMnx-Examples Notebook I know the Route function, witch reacts to oneway streets and on the other Hand I know the Isometric Workflow from the Example Notebook, where I can set the travel_speed, but is there a way to use the maxspeed key from highway?
The functionality to calculate edge travel times is available as of OSMnx v0.13.0. You can then use these new edge travel time attributes to solve network shortest paths by travel time rather than distance.
I would like to extract the building layer information from in Haiti using osmnx. I works for different cities it does not in the case of
import osmnx as ox
place_name = "Port-au-Prince"
buildings = ox.buildings_from_place(place_name)
I get the following error
TypeError: Geometry must be a shapely Polygon or MultiPolygon
I guess this is an internal bug of osmnx. "Port-au-Prince" is mapped in OSM as a node. This node is the first result when searching for "Port-au-Prince" in Nominatim (a geocoder). osmnx seems to expect an area instead, i.e. an administrative boundary relation. Such a relation comes second and third in Nominatim. osmnx seems to fail if it finds a node as first search result. Create an upstream bug report for osmnx.
See https://github.com/gboeing/osmnx/issues/16 for a comprehensive discussion of this issue and how to resolve it in your query.
Per the OSMnx documentation:
The query must be geocodable and OSM must have polygon boundaries for the geocode result. If OSM does not have a polygon for this place, you can instead get its street network using the graph_from_address function, which geocodes the place name to a point and gets the network within some distance of that point. Alternatively, you might try to vary the which_result parameter to use a different geocode result. For example, the first geocode result (ie, the default) might resolve to a point geometry, but the second geocode result for this query might resolve to a polygon, in which case you can use graph_from_place with which_result=2.
So I have been interested in a project to help my dad with his business, or at least for my own whimsy. Basically, the job involves going to different fields spread throughout the county, and a lot of how we do it now is inefficient and leapfroggy. So I would try to create a system that will find an optimized path. I'm not asking someone to build any of this for me, I just need to know the right direction to look, for gathering information on how to do this. So we have a map of our county and or county, and luckily because we live in Nebraska all county's are just big grids. And we have a bunch of different fields we need to get too, for this task, there are 2 to 3 different teams who each drive there own truck( so 1 to 2 trucks). And in some cases, there is certain fields truck A has to check. So I just would like some help researching this, I would prefer to write this all in python. I know about pathfinding algorithms, but that's about it. So really here are my questions: How do I make, or use a roadmap in python? How can I institute a pathfinding algorithm to that map? How can I make 2 of those algorithms making there own path of the same length, ignoring certain fields? Any help is appreciated. Here is a low-quality picture of our field map https://drive.google.com/file/d/1L5GNoUrtzTxJvfKoS04wGO8EgkK8Ulue/view?usp=sharing
I am trying to use the Levenshtein distance algorithm (in Python, if it makes any difference) to do a fuzzy string comparison between two lists of company names. An example would be where list A contains XYZ INDUSTRIAL SUPPLY but list B might say XYZ INDUSTRIAL SUPPLY, INC. but they should still match.
Right now, my implementation is terribly inaccurate. As a second example, currently the algorithm finds abc metal finishing and xyz's mach & metal finishing very similar because of their endings, but they are totally different companies. I want to improve this accuracy and one way I think I can do that is by weighting the beginning of strings somehow. If the company names are supposed to match, chances are they start out similarly. Looking at my first example, the whole beginning matches, it's only at the very end where variations occur. Is there a way to accomplish this? I haven't been able to work it out.
Thanks!
Edit for more examples:
Should match:
s west tool supply, southwest tool supply
abc indust inc, abc industries
icg usa, icg usa llc
Shouldn't match (but do currently):
ohio state university, iowa state university
m e gill corporation, s g corporation
UPDATE:
Progress has been made :) In case anyone is ever interested in this sort of thing, I ended up experimenting with the costs of inserts deletes and substitutions. My idea was to weight the beginning of the strings more heavily, so I based the weights off of the current location within the matrix. The issue that this created though, was that everything was matching to a couple of very short names because of how my weights were being distributed. I fixed this by including the lengths in my calculation. My insertion weight, for example, ended up being (1 if index<=2/3*len(target) else .1*(len(source)-index)) where source is always the longer of the two strings. I'm planning to continue tweaking this and experimenting with other values, but it has already shown a great improvement. This is by no means anywhere close to an exact science but if it's working, that's what counts!