Skip to main content

Extends 'networkx' for working with spatial networks

Project description

net2

badge

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.Graph or nx.DiGraph
  • The network is associated with:
    • 'crs' (None or int)
  • 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))
plt.axis('on')
ax.set_aspect('equal')
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True);

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);

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

net2-0.0.11.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

net2-0.0.11-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file net2-0.0.11.tar.gz.

File metadata

  • Download URL: net2-0.0.11.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for net2-0.0.11.tar.gz
Algorithm Hash digest
SHA256 e66f8fc4ff4d1dd4cc80a2aee7f5f177043be3d721bedf3fe0b7b2568ab61934
MD5 2002fcf0d0da46006e122f48517b1623
BLAKE2b-256 f6d29a2aa6ea4e9c8ca799c1fdfc8a6f328232e1612591f3ac3b29a715cd1f4f

See more details on using hashes here.

File details

Details for the file net2-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: net2-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for net2-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 22c9f6bc11bd3253ae08e6a557b47c6738b03dba51563c1b89e6c99b3e1ca15b
MD5 e5265b852276e4f2772098a3a7d570fe
BLAKE2b-256 a7f0ea1e2cebea295467a7c3768f4444d86be6e8eba323e5a0713a53647ed8c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page