Set up a virtual environment, and activate it.
pip install virtualenv
virtualenv venv
source venv/bin/activate
Install the requirements.
pip install -r requirements.txt
From the top-level directory, install topology
in editable mode.
pip install -e .
Deactivate your virtual environment once you're done
deactivate
This is structured into three files:
Example.py
my_graph.py
my_graph_helpers.py
Example.py imports a shapefile, finds the roads necessary to create a graph from that, and plots the graph.
This my_graph.py file includes four classes: MyNode
, MyEdge
, MyFace
,
and MyGraph
.
MyNode
MyNode
is a class that represents nodes. Floating point geometric inputs are
rounded to two decimal places1. MyNodes are hashable.
MyEdge
MyEdge
keeps track of pairs of nodes as an edge in a graph. Edges are
undirected. The geometric length is calculated iff called. Also has T/F
properties for being a road or barrier. Hashable.
MyFace
A MyFace
is a simple polygon, that makes up part of a planar graph.
Has area, a centroid, and a list of nodes and edges. Not hashable.
MyGraph
MyGraph
is the bulk of the work here. It's a wrapper around networkx graphs,
in order to make the graph explicitly spatial. Nodes must be MyNodes
, and are
thus located in space, in whatever the map units are and edges must by MyEdges
.
All networkx functions are availble through self.G
In addition, explicitly spatial functions for self are:
Finally, the last code section can break the geomotery of the graph to build in roads, rather than just defining roads as a property of some edges. I don't use this module, but it might be useful someday.
Several plotting and example functions are also included:
self.plot()
takes networkx.draw()
keywords
self.plot_roads()
specficially plots roads, interior parcels, and barriers.
self.plot_weak_duals()
plots the nested dual graphs.
This file includes a bunch of helper functions for my_graph.py, with a a variety of categories: