gboeing / osmnx-examples

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

Existing alternate isochrones example doesn't respect geometry of curved links #30

Closed asongtoruin closed 4 years ago

asongtoruin commented 4 years ago

First of all, a quick thanks for creating such a useful and easy-to-use module! I've got a slight improvement to suggest to one of the existing examples.

The improved isochrones method added in #4 by @kuanb provides, for me, a much better way of visualising the isochrones. However, when the input links are curved this is not respected in the output buffers.

If we alter the call to make_iso_polys in cell 13 to have edge_buff=10 and up the output fig_height, we can observe the buffer not "following" the link along the curved edges for example in the two links indicated by the arrows:

curved link issue

This comes about as a result of the way the buffers are defined in the function:

edge_lines = []
for n_fr, n_to in subgraph.edges():
    f = nodes_gdf.loc[n_fr].geometry
    t = nodes_gdf.loc[n_to].geometry
    edge_lines.append(LineString([f,t]))

As the line is defined just by the start and end nodes, curvature is lost. It should be possible to instead look up the geometry of the link in the original graph, and thus keep the curvature.

I'm not sure of the best method to do this, but a slightly messy alternative method I've created is as follows:

edge_lines = []
for n_fr, n_to in subgraph.edges():
    f = nodes_gdf.loc[n_fr].geometry
    t = nodes_gdf.loc[n_to].geometry
    edge_lookup = G.get_edge_data(n_fr, n_to)[0].get('geometry',  LineString([f,t]))
    edge_lines.append(edge_lookup)

It seems as though the straight edges don't have a geometry key, hence the slightly awkward call to .get(). The result of this modification is that the curved edges are indeed followed:

fixed curved edges

I'm happy to submit a PR including this fix, but I wasn't sure if this was the best method, and I don't want to tread on anyone's toes!

gboeing commented 4 years ago

@asongtoruin this looks great. I'd be happy to review a PR.

gboeing commented 4 years ago

closed by #34