Desire and Delaunay lines#

Creating Desire and Delaunay Lines

Creating county-to-county matrices#

sphinx_gallery_thumbnail_path = ‘../../examples/result_analysis/delaunay_lines.png’

from pathlib import Path

from polaris.analyze.mapping.flow_lines import delaunay_assignment, desire_lines
from polaris.analyze.trip_metrics import TripMetrics

Polaris Studio enables you to create Desire and Delaunay lines for trip matrices between counties or between zones. Let’s show that using the Austin model as an example.

project_dir = Path("/tmp/Austin")

last_iter = TripMetrics(project_dir / "Austin-Supply.sqlite", project_dir / "Austin-Demand.sqlite")

# Let's get all the trips for the last iteration
matrix_zones = last_iter.trip_matrix(from_start_time=0, to_start_time=24 * 3600, aggregation="zone")

# And let's see what modes we have:
matrix_zones.matrices
['BUS', 'HD_TRUCK', 'MD_TRUCK', 'RAIL', 'SOV', 'TAXI', 'TNC_AND_RIDE']

We can plot the zone-to-zone flows as Delaunay lines#

flows is a GeoDataFrame, so you can save it to a file for use elsewhere if you’d like

flows = delaunay_assignment(project_dir / "Austin-Supply.sqlite", aggregation="zone", matrix=matrix_zones)

flows.explore(
    style_kwds={
        "style_function": lambda x: {
            "weight": x["properties"]["SOV_tot"] / flows["SOV_tot"].max() * 10  # scale as needed
        }
    },
    tiles="CartoDB positron",
    attr="Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap contributors",
)
delaunay                                          :   0%|          | 0/2102 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/250 [00:00<?, ?it/s]
Make this Notebook Trusted to load map: File -> Trust Notebook


Desire lines#

To mix it up a little, we can plot desire lines for county-to-county vehicle flows.

matrix_county = last_iter.trip_matrix(from_start_time=0, to_start_time=24 * 3600, aggregation="county")
dls = desire_lines(project_dir / "Austin-Supply.sqlite", aggregation="county", matrix=matrix_county)

But we plot only flows larger than 50 trips, or the map will be impossibly heavy to render/navigate

dls.explore(
    style_kwds={
        "style_function": lambda x: {
            "weight": x["properties"]["HD_TRUCK_tot"] / dls["HD_TRUCK_tot"].max() * 20  # scale as needed
        }
    },
    tiles="CartoDB positron",
    attr="Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap contributors",
)
Make this Notebook Trusted to load map: File -> Trust Notebook


You can always simply plot the GeoDataFrame using the plot method, but it will not be interactive.

dls.plot(linewidth=5 * dls["HD_TRUCK_tot"] / dls["HD_TRUCK_tot"].max(), color="red")
plot desire delaunay
<Axes: >

Total running time of the script: (1 minutes 10.158 seconds)

Gallery generated by Sphinx-Gallery