I am working on a graph flow model in the context of transport networks. I have the position of sensors (lat/lon) and would like to associate these sensors with nodes on a graph retrieved using osmnx.
At present, I use get_nearest_node
to map a sensor to a node. However, this isn't optimal, as I'm at the mercy of the cartographer -- straight roads will be have fewer nodes, and so the mean displacement (and therefore error) will be higher, even when dealing with unsimplified graphs. I had considered using get_nearest_edge
, but I'd still need to edit the graph to insert a new node at the position of the sensor.
Instead, I thought a reasonable way of achieving this would be to upsample the graph (perhaps using redistribute_vertices
), applying get_nearest_node
, and then re-simplifying the graph, but somehow whitelisting the node that is now associated with a sensor to prevent it from being removed.
However, it's not clear to me how to go from the output of redistribute_vertices
to a graph -- it returns a LineString
or MultiLineString
rather than a new graph.
I saw this question posted on the osmnx GitHub project: https://github.com/gboeing/osmnx/issues/304, in which a GeoDataFrame is generated, with a new column containing the redistributed way as a (Multi
)LineString
. However, I'm not sure how I can map this new gdf back to a Graph -- the corresponding node
dataframe hasn't been updated, and u
and v
values remain the same in the new edges table.
Any pointers (including telling me I'm going about this the wrong way and should be using function XYZ
) would be really appreciated.