gboeing / osmnx-examples

Gallery of OSMnx tutorials, usage examples, and feature demonstations.
https://osmnx.readthedocs.io
MIT License
1.52k stars 521 forks source link

new example: interpolate external measurements to estimate graph's new node/edge weights #26

Closed mmortazavi closed 4 years ago

mmortazavi commented 4 years ago

Thanks for the super awesome OSMnx package you have put together. I truly enjoyed going through your demos and examples and learned a lot. However, I miss seeing an example relevant to the following use case I am working on.

I want to find the shortest path between two points on the map with the least X attribute (temperature, pollution etc.)! And here by X attribute I mean data points that we gather from sensors on the street. The trick is that these data points not necessarily align on the edges or nodes on the graph or we may have multiple measurements around each node or edge.

The question is what is the best way to estimate X attribute value for the graph nodes and edges from such data? I find the 12-node-elevations-edge-grades.ipynb example the most relevant to this use case, when calculating shortest paths, considering grade impedance. But here these lines using Google elevation API:

# add elevation to each of the nodes, using the google elevation API, then calculate edge grades
G = ox.add_node_elevations(G, api_key=google_elevation_api_key)
G = ox.add_edge_grades(G)

does the trick neatly and one easily access the elevations at node and edge as you showed!

I was thinking of using the average of M nearest neighbors to estimate the node X attribute, maybe also a similar approach for the edge? Edge sounds a bit trickier though. I further come across the Voronoi diagrams as an alternative options to interpolate the X attribute impedance for node and edge on the graph using the measurements. At the same time I do not want to over-complicate the solutions, as it seems there are many features within OSMnx and NetworkX that may do the trick and I am not aware of (not to mention I am new to graphs as well).

Happy to contribute if I get to learn how if you find this a useful demo to have in this repo.

sumanjnu commented 4 years ago

@gboeing I am getting the point geometry of my place, instead of the polygon geometry in ox.gdf_from_places function. Error in ox gdf_from_places

mmortazavi commented 4 years ago

@sumanjnu How is this issue related to my question?

gboeing commented 4 years ago

@mmortazavi a straightforward solution may be to:

  1. attach each sensor reading to its nearest edge, via get_nearest_edge()
  2. aggregate then average the sensor readings per edge
  3. use this as an impedance value for shortest-path calculation