Skip to main content

Network

Network(
    lines_gdf,
    name_col=None,
    id_col=None,
    tolerance=None,
    snap_line_boundaries=True,
    verbose=False,
    _graph=None,
    _graph_undirected=None,
    _node_locations=None,
)

Create a network from a GeoDataFrame with lines.

When creating nodes and links the following fixes aremade: - All nodes are snapped/dissolved within tolerance if set - Lines shorter than tolerance are dissolved into one nodes - Gaps between lines, within tolerance, are filled - If link-segments intersect nodes, these segments are split

Attributes

lines_gdf : GeoDataFrame GeoDataFrame with LineStrings tolerance : float | None tolerance for snapping nodes and filling gaps. Defaults to None name_col: str column in lines_gdf to preserve as ‘name’ column in network-links. Defaults to ‘name’ id_col: str column in lines_gdf to preserve as ‘id’ column in network-links. Defaults to ‘id’

Methods

from_lines_gpkg(gpkg_file, layer=None, **kwargs) returns a Network from a layer with LineStrings within a GeoPackage. Optionally the user specifies a layer in a multilayer-GeoPackage. nodes returns GeoDataFrame with the nodes in the network links returns GeoDataFrame with the links in the network graph returns networkx.Graph with nodes and links to_file(path) write nodes and links to a (multi-layer) file, e.g. GeoPackage

Attributes

Name Description
links Return graph links as GeoDataFrame
node_locations Node types and geometries, cached for repeated nearest-node searches.
nodes Return graph nodes as GeoDataFrame
snap_tolerance Snap tolerance for shapely.ops.snap

Methods

Name Description
add_link Add a link (link) to the network
from_lines_gpkg Instantiate class from a lines_gpkg
from_network_gpkg Instantiate class from a network gpkg
get_nodes Get nodes from lines_gdf
move_node Move network nodes and links to new location
set_graph Set graph directly
set_node_types Node types to seperate boundaries from connections
to_file Write output to geopackage
validate_inputs Validate if inputs are good-to-go for generating a graph

from_lines_gpkg

Network.from_lines_gpkg(gpkg_file, layer=None, **kwargs)

Instantiate class from a lines_gpkg

from_network_gpkg

Network.from_network_gpkg(gpkg_file, **kwargs)

Instantiate class from a network gpkg

get_nodes

Network.get_nodes()

Get nodes from lines_gdf

Approach if tolerance is set: 1. create polygons using buffer (tolerance/2) 2. dissolving to a multipolygon using unary_union 3. explode to individual polygons 4. convert to points taking the centroid

Returns

GeoDataFrame GeoDataFrame with nodes and index

move_node

Network.move_node(point, max_distance, align_distance, node_types=None)

Move network nodes and links to new location

Parameters

point : Point Point to move node to max_distance : float Max distance to find closes node align_distance : float Distance over link, from node, where vertices will be removed to align adjacent links with Point

set_graph

Network.set_graph(graph)

Set graph directly

set_node_types

Network.set_node_types()

Node types to seperate boundaries from connections

to_file

Network.to_file(path)

Write output to geopackage

validate_inputs

Network.validate_inputs()

Validate if inputs are good-to-go for generating a graph