.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_auto_examples/network_manipulation/plot_moving_nodes.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_moving_nodes.py: .. _editing_network_nodes: Editing network geometry: Nodes =============================== In this example, we show how to mode a node in the network and look into what happens to the links. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. admonition:: References * :ref:`modifications_on_nodes_layer` .. GENERATED FROM PYTHON SOURCE LINES 16-20 .. seealso:: Several functions, methods, classes and modules are used in this example: * :func:`aequilibrae.project.network.Nodes` .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python # Imports from uuid import uuid4 from tempfile import gettempdir from os.path import join from aequilibrae.utils.create_example import create_example from shapely.geometry import Point import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python # We create the example project inside our temp folder. fldr = join(gettempdir(), uuid4().hex) project = create_example(fldr) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Let's move node one from the upper left corner of the image above, a bit to the left and to the bottom. .. GENERATED FROM PYTHON SOURCE LINES 40-51 .. code-block:: Python # We also add the node we want to move. all_nodes = project.network.nodes links = project.network.links node = all_nodes.get(1) new_geo = Point(node.geometry.x + 0.02, node.geometry.y - 0.02) node.geometry = new_geo # We can save changes for all nodes we have edited so far. node.save() .. GENERATED FROM PYTHON SOURCE LINES 52-55 If you want to show the path in Python. We do NOT recommend this, though.... It is very slow for real networks. .. GENERATED FROM PYTHON SOURCE LINES 55-59 .. code-block:: Python # Let's refresh the links in memory for usage links.refresh() .. GENERATED FROM PYTHON SOURCE LINES 60-61 Let's access our links data using a context manager instead of directly accessing the DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 61-72 .. code-block:: Python with project.db_connection as conn: link_ids = conn.execute("Select link_id from links;").fetchall() for lid in link_ids: geo = links.get(lid[0]).geometry plt.plot(*geo.xy, color="blue") plt.plot(*node.geometry.xy, "o", color="black") plt.show() .. image-sg:: /_auto_examples/network_manipulation/images/sphx_glr_plot_moving_nodes_001.png :alt: plot moving nodes :srcset: /_auto_examples/network_manipulation/images/sphx_glr_plot_moving_nodes_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-75 Did you notice the links are matching the node? Look at the original network and see how it used to look like. .. GENERATED FROM PYTHON SOURCE LINES 77-78 .. code-block:: Python project.close() .. rst-class:: sphx-glr-script-out .. code-block:: none This project at /tmp/10eb24081fa3421e8c63fb6f27f3c383 is already closed .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.696 seconds) .. _sphx_glr_download__auto_examples_network_manipulation_plot_moving_nodes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_moving_nodes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_moving_nodes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_moving_nodes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_