.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/network_manipulation/plot_centroid_connection.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__auto_examples_network_manipulation_plot_centroid_connection.py: .. _plot_centroid_connection: Create centroid connectors ========================== We use Coquimbo example to show how we can create centroids and connect them to the existing network efficiently. We use Folium to visualize the resulting network. .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. seealso:: Several functions, methods, classes and modules are used in this example: * :func:`aequilibrae.project.Zoning` .. GENERATED FROM PYTHON SOURCE LINES 20-30 .. code-block:: Python # Imports import folium from uuid import uuid4 from tempfile import gettempdir from os.path import join from aequilibrae.utils.create_example import create_example .. GENERATED FROM PYTHON SOURCE LINES 32-39 .. code-block:: Python # Let's create an arbitrary project folder fldr = join(gettempdir(), uuid4().hex) # And create our Coquimbo project project = create_example(fldr, "coquimbo") .. GENERATED FROM PYTHON SOURCE LINES 40-42 As Coquimbo already has centroids and centroid connectors, we should remove them for the sake of this example. .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python with project.db_connection as conn: conn.execute("DELETE FROM links WHERE name LIKE 'centroid connector%'") conn.execute("DELETE FROM nodes WHERE is_centroid=1;") conn.commit() centroids = conn.execute("SELECT COUNT(node_id) FROM nodes WHERE is_centroid=1;").fetchone()[0] .. GENERATED FROM PYTHON SOURCE LINES 50-52 If you want to make sure your deletion process has worked, you can check the number of centroids! .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python print("Current number of centroids: ", centroids) .. rst-class:: sphx-glr-script-out .. code-block:: none Current number of centroids: 0 .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python zoning = project.zoning .. GENERATED FROM PYTHON SOURCE LINES 58-65 This centroid connector creation is effective because it uses the existing zone layer to create the centroids and connect them to the existing network. First thing to do is add the centroids to all zones that doesn't have a centroid at the geographic centroid of the zone, using ``add_centroids()``, which has a ``robust`` argument set to ``True`` as default. This means that it will automatically move the centroid location around to avoid conflicts with existing nodes. .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: Python zoning.add_centroids() .. rst-class:: sphx-glr-script-out .. code-block:: none Connecting zones : 0%| | 0/133 [00:00
Make this Notebook Trusted to load map: File -> Trust Notebook


.. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: Python project.close() .. rst-class:: sphx-glr-script-out .. code-block:: none This project at /tmp/68459fe8061f4b399b9d87c3d5ac8a1b is already closed .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.055 seconds) .. _sphx_glr_download__auto_examples_network_manipulation_plot_centroid_connection.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_centroid_connection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_centroid_connection.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_centroid_connection.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_