.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/plot_delaunay_lines.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_plot_delaunay_lines.py: Creating Delaunay Lines ======================= On this example we show how to create AequilibraE's famous Delaunay Lines, but in Python For more on this topic, the firs publication is here: https://xl-optim.com/delaunay/ We use the Sioux-Falls example once again. .. GENERATED FROM PYTHON SOURCE LINES 13-24 .. code-block:: python import pandas as pd from uuid import uuid4 from os.path import join import sqlite3 from tempfile import gettempdir import matplotlib.pyplot as plt import shapely.wkb from aequilibrae.utils.create_example import create_example from aequilibrae.utils.create_delaunay_network import DelaunayAnalysis .. GENERATED FROM PYTHON SOURCE LINES 25-26 We create an empty project on an arbitrary folder .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: python fldr = join(gettempdir(), uuid4().hex) project = create_example(fldr) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Get the Delaunay Lines generation class .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: python da = DelaunayAnalysis() # Let's create the triangulation based on the zones, but we could create based on the network (centroids) too da.create_network('zones') .. GENERATED FROM PYTHON SOURCE LINES 38-39 Now we get the matrix we want and create the Delaunay Lines .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: python demand = project.matrices.get_matrix("demand_omx") demand.computational_view(["matrix"]) # And we will call it 'delaunay_test'./ It will also be saved in the results_database.sqlite da.assign_matrix(demand, 'delaunay_test') .. GENERATED FROM PYTHON SOURCE LINES 46-47 we retrieve the results .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: python conn = sqlite3.connect(join(fldr, 'results_database.sqlite')) results = pd.read_sql('Select * from delaunay_test', conn).set_index('link_id') .. GENERATED FROM PYTHON SOURCE LINES 51-52 Now we get the matrix we want and create the Delaunay Lines .. GENERATED FROM PYTHON SOURCE LINES 52-66 .. code-block:: python links = pd.read_sql('Select link_id, st_asBinary(geometry) geometry from delaunay_network', project.conn) links.geometry = links.geometry.apply(shapely.wkb.loads) links.set_index('link_id', inplace=True) df = links.join(results) max_vol = df.matrix_tot.max() for idx, lnk in df.iterrows(): geo = lnk.geometry plt.plot(*geo.xy, color='blue', linewidth=4 * lnk.matrix_tot / max_vol) plt.show() .. image-sg:: /_auto_examples/images/sphx_glr_plot_delaunay_lines_001.png :alt: plot delaunay lines :srcset: /_auto_examples/images/sphx_glr_plot_delaunay_lines_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-68 Close the project .. GENERATED FROM PYTHON SOURCE LINES 68-68 .. code-block:: python project.close() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.057 seconds) .. _sphx_glr_download__auto_examples_plot_delaunay_lines.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_delaunay_lines.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_delaunay_lines.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_