Creating Delaunay Lines#

In this example, we show how to create AequilibraE’s famous Delaunay Lines, but in Python.

For more on this topic, see its first publication.

We use the Sioux Falls example once again.

See also

Several functions, methods, classes and modules are used in this example:

# Imports
import pandas as pd
from uuid import uuid4
from os.path import join
import sqlite3
from tempfile import gettempdir
from geopandas import read_postgis

from aequilibrae.utils.create_example import create_example
from aequilibrae.utils.create_delaunay_network import DelaunayAnalysis
# We create an empty project on an arbitrary folder
fldr = join(gettempdir(), uuid4().hex)

project = create_example(fldr)
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path

Get the Delaunay Lines generation class

da = DelaunayAnalysis(project)

# Let's create the triangulation based on the zones, but we could create based on the network (centroids) too
da.create_network("zones")
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path

Now we get the matrix we want and create the Delaunay Lines

And we will call it ‘delaunay_test’./ It will also be saved in the results_database.sqlite

da.assign_matrix(demand, "delaunay_test")
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
/home/runner/work/aequilibrae/aequilibrae/aequilibrae/paths/graph.py:218: ChainedAssignmentError: A value is being set on a copy of a DataFrame or Series through chained assignment.
Such chained assignment never works to update the original DataFrame or Series, because the intermediate object on which we are setting values always behaves as a copy (due to Copy-on-Write).

Try using '.loc[row_indexer, col_indexer] = value' instead, to perform the assignment in a single step.

See the documentation for a more detailed explanation: https://pandas.pydata.org/pandas-docs/stable/user_guide/copy_on_write.html#chained-assignment
  build_compressed_graph(self, remove_dead_ends)

delaunay                                          :   0%|          | 0/24 [00:00<?, ?it/s]
Equilibrium Assignment                            :   0%|          | 0/250 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: delaunay          :   0%|          | 1/250 [00:00<00:00, 41120.63it/s]
All-or-Nothing - Traffic Class: delaunay          :   0%|          | 1/250 [00:00<00:00, 11155.06it/s]
All-or-Nothing - Traffic Class: delaunay          :   0%|          | 0/250 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: delaunay - Zones: 0/24:   0%|          | 0/250 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: delaunay - Zones: 10/24:   0%|          | 0/250 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: delaunay - Zones: 20/24:   0%|          | 0/250 [00:00<?, ?it/s]
All-or-Nothing - Traffic Class: delaunay - Zones: 24/24:   0%|          | 0/250 [00:00<?, ?it/s]

Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path

we retrieve the results

results = project.results.get_results("delaunay_test").set_index("link_id")

Now we get the matrix we want and create the Delaunay Lines

with project.db_connection as conn:
    links = read_postgis(
        "Select link_id, st_asBinary(geometry) geometry from delaunay_network",
        conn,
        geom_col="geometry",
        crs=4326
    )
    links.set_index("link_id", inplace=True)

df = links.join(results)

max_vol = df.matrix_tot.max()

df.plot(linewidth=4 * df["matrix_tot"] / max_vol, color="blue")
plot delaunay lines
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path

<Axes: >

Close the project

Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path
Environment variable 'AEQ_SPATIALITE_DIR' was provided (C:\path\to\existing\download), but mod_spatialite could not be loaded from this directory. Trying system path

Total running time of the script: (0 minutes 0.538 seconds)

Gallery generated by Sphinx-Gallery