net2
Overview
net2 is a Python package for working with spatial networks.
Data structures
net2 is intended to work with spatial network data represented using
networkx.DiGraph objects, following several conventions:
- An object of type
nx.Graphornx.DiGraph - The network is associated with:
'crs'(Noneorint)
- Node IDs are
int - Nodes are associated with:
'geometry'(shapely)
- Edges are associated with:
'geometry'(shapely)'length'(float, in $m$)'time'(float, in $sec$)
Installation
The package can be installed with:
pip install net2
Use
Once installed, the package can be loaded with:
import net2
Sample data
The package comes with a small spatial network for demonstration, accessible as follows:
G = net2.data['roads']
G
<networkx.classes.digraph.DiGraph at 0x7f2bfcedffe0>
Here is a plot of the network:
import matplotlib.pyplot as plt
import networkx as nx
fig, ax = plt.subplots()
nx.draw(G, with_labels=True, pos=net2.pos(G))
ax.set_aspect('equal')
Example
Calculating the shortest route between two custom points, using
net2.route2:
import shapely
pnt1 = shapely.Point(4100, 3100)
pnt2 = shapely.Point(1100, 3700)
x = net2.route2(G, pnt1, pnt2, 'length')
x
Plot of the resulting route and modified network:
fig, ax = plt.subplots()
nx.draw(x['network'], with_labels=True, pos=net2.pos(x['network']), edge_color='grey', width=0.1, ax=ax)
nx.draw_networkx_edges(G, pos=net2.pos(x['network']), edgelist=list(zip(x['route'], x['route'][1:])), edge_color='r', width=3)
plt.plot(pnt1.x, pnt1.y, 'ro')
plt.plot(pnt2.x, pnt2.y, 'ro')
ax.annotate('pnt1', [pnt1.x, pnt1.y], ha='left')
ax.annotate('pnt2', [pnt2.x, pnt2.y], ha='left')
plt.axis('on')
ax.set_aspect('equal')
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True);
Metadata
Release files for net2 0.0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| net2-0.0.16.tar.gz | 3.8 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| net2-0.0.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.8 MB
Release files / net2-0.0.16.tar.gz
| Download URL | net2-0.0.16.tar.gz |
|---|---|
| Size | 3.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80fdce8567ea946038919b71998a79c8317e534cd36b45459e9ad12f7b5847a2
|
|
BLAKE2b-256 checksum How to use checksums |
3149bf4a1d2c5c91bd835d44beb319d9bf96ff84a285fb77dbcdbcc7b6f01895
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / net2-0.0.16-py3-none-any.whl
| Download URL | net2-0.0.16-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bb0e8d559af0e085d6c4da0166f85fdb8825a42e5ecb63bbeac04db8b07bf77
|
|
BLAKE2b-256 checksum How to use checksums |
e096374bdea2e6439ad519767c99948c3f24cbc6aef13d43c49962398508a469
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|