snkit

a spatial networks toolkit

snkit on github License Build Status PyPI version

/ˈsnɪkɪt/ – sounds like [snicket] (noun, Northern English) A narrow passage between houses; an alleyway. Alternatively, a python package to help clean spatial networks data.

Say you have some edges and nodes (lines and points, connections and vertices). None of them are quite connected, and there’s no explicit data to define which node is at the end of which edge, or which edges are connected.

For example:

Unconnected network

snkit has methods to:

Unconnected network
  • connect nodes to nearest edges
  • split edges at connecting points
  • create node and edge ids, and add from_id and to_id to each edge

Spatial network

The output of a snkit data cleaning process might look something like this:

Connected network

Nodes

Connected network
——————- | —— | ——————- |
POINT (0.03 0.04) | node_0 | … |
POINT (0.03 0.03) | node_1 | … |
POINT (0.02 0.03) | node_2 | … |

Edges

geometry id from_id to_id other attributes…
LINESTRING (0.04 -0.04... edge_0 node_10 node_22
LINESTRING (0.01 -0.03... edge_1 node_22 node_21
LINESTRING (0.02 -0.02... edge_2 node_21 node_25

Getting started

Install system libraries (only tested on Ubuntu):

sudo apt-get install -y libgeos-dev gdal-bin

Maybe set up a virtualenv or conda environment, as you wish. Then install snkit in editable mode, with development packages:

pip install -e .[dev]

Run the tests:

python -m pytest tests/

Testimonials 💯 👍 😊

With five lines of snkit I replaced four or five hundred lines of custom code!
  1. Contented Customer (@czor847)

Acknowledgements

``` MIT License

Copyright (c) 2018 Tom Russell and snkit contributors

Indices and tables