{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n# Editing network geometry: Nodes\n\nIn this example, we show how to mode a node in the network and look into\nwhat happens to the links.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Imports\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from uuid import uuid4\nfrom tempfile import gettempdir\nfrom os.path import join\nfrom aequilibrae.utils.create_example import create_example\nfrom shapely.geometry import Point\nimport matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We create the example project inside our temp folder\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fldr = join(gettempdir(), uuid4().hex)\n\nproject = create_example(fldr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's move node one from the upper left corner of the image above, a bit to the left and to the bottom\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# We also add the node we want to move\nall_nodes = project.network.nodes\nlinks = project.network.links\nnode = all_nodes.get(1)\nnew_geo = Point(node.geometry.x + 0.02, node.geometry.y - 0.02)\nnode.geometry = new_geo\n\n# We can save changes for all nodes we have edited so far\nnode.save()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to show the path in Python\nWe do NOT recommend this, though.... It is very slow for real networks\nWe plot the entire network\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "links.refresh()\ncurr = project.conn.cursor()\ncurr.execute(\"Select link_id from links;\")\n\nfor lid in curr.fetchall():\n geo = links.get(lid[0]).geometry\n plt.plot(*geo.xy, color=\"blue\")\n\nplt.plot(*node.geometry.xy, \"o\", color=\"black\")\n\nplt.show()\n\n# Did you notice the links are matching the node?\n# Look at the original network and see how it used to look like" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "project.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" } }, "nbformat": 4, "nbformat_minor": 0 }