gis-ops / routingpy

🌎 Python library to access all public routing, isochrones and matrix APIs in a consistent manner.
https://routingpy.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
270 stars 26 forks source link

feat: added expansion example #101

Closed Ananya2001-an closed 1 year ago

Ananya2001-an commented 1 year ago

closes #97

I feel the plot is very small....are there any ways to zoom in?

chrstnbwnkl commented 1 year ago

Thanks! You didn't do anything wrong that led to the plot being small. This is due to a bug in Valhalla. What we can do is pass durations into the expansion_props array and then filter the response by that:

valhalla_public_url = "https://valhalla1.openstreetmap.de"
api = rp.Valhalla(base_url=valhalla_public_url)

expansions = api.expansion(locations=coordinates[0],
                      profile='auto',
                      intervals=[200],
                      expansion_properties=["durations"])

Add the durations to the DataFrame:

expansion_df = gpd.GeoDataFrame(
                            {"id": [x for x in range(len(expansions))], "duration": [x.duration for x in expansions]},
                            geometry=[LineString(X.geometry) for X in expansions], crs="EPSG:4326",
                                ).to_crs("EPSG:3857")

And finally filter:

fig, ax = plt.subplots(1,1, figsize=(10,10))
expansion_df[expansion_df["duration"] <= 200].plot(ax=ax, column="duration", cmap="RdYlGn_r", linewidth=1, alpha=1)
start_end.iloc[:-1].plot(ax=ax, color="black", markersize=20)
cx.add_basemap(ax=ax, crs="EPSG:3857", source=BASEMAP_SOURCE)
_ = ax.axis("off") 
Ananya2001-an commented 1 year ago

Okay so that's happening because of the random edges being created outside the limit and we are using durations to filter out the ones that are inside...