Table of Contents

Class NetworkBuilder<TNodeId, TEdgeId, TSource>

Namespace
SpatialNET.Network.Building
Assembly
SpatialNET.Network.Building.dll

Builds a network from the host's points and lines (ADR 0050): joins every line end and point within the tolerance into one node, splits lines at real nodes and T junctions (and, if asked, at crossings), assigns shards from polygons and writes all nodes, then all edges, to a writer. The geometry is not changed; no vertex moves.

public sealed class NetworkBuilder<TNodeId, TEdgeId, TSource> where TNodeId : notnull, IEquatable<TNodeId> where TEdgeId : notnull, IEquatable<TEdgeId>

Type Parameters

TNodeId

The host's node id.

TEdgeId

The host's edge id.

TSource

The host's reference to a source object, passed on unchanged.

Inheritance

Inherited Members

Remarks

A builder is used once: the Add… calls may come in any order, SpatialNET.Network.Building.NetworkBuilder`3.Build(SpatialNET.Network.INetworkWriter{`0,`1,`2},System.IProgress{SpatialNET.Network.Building.BuildProgress},System.Threading.CancellationToken) handles the points before the lines, and every call after it throws. It is not thread-safe.

The same input in the same order gives the same nodes, edges, ids and output order; another order gives the same nodes and edges. Every search inside goes through a grid or a spatial index.

Constructors

NetworkBuilder(NetworkBuildOptions, INetworkIdFactory<TNodeId, TEdgeId, TSource>)

Creates a builder.

public NetworkBuilder(NetworkBuildOptions options, INetworkIdFactory<TNodeId, TEdgeId, TSource> ids)

Parameters

options NetworkBuildOptions
ids INetworkIdFactory<TNodeId, TEdgeId, TSource>

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

The tolerance or the fallback cell size is not finite and greater than 0.

ArgumentException

A shard region or a weight definition is null, or two weights share an id.

Properties

ResolveCoincidentNodes

Decides about real nodes within the tolerance of each other (ADR 0054): called once per group before the first write, it returns the node that stays (the others are merged into it and written as SpatialNET.Network.BuiltNode`2.Merged) or -1. Without it, or on -1, the group is a SpatialNET.Network.Building.NodeConflictKind.RealNodesTooClose conflict (ADR 0050). A resolver that decides by the nodes, not by their order, keeps the result independent of the input order.

public CoincidentNodesResolver<TNodeId, TSource>? ResolveCoincidentNodes { get; set; }

Property Value

CoincidentNodesResolver<TNodeId, TSource>?

Methods

AddLine(TSource, IPolyline2D, int, LineAttributes?)

Adds a line from any feature class: cable, overhead line, connector. Multi-part lines are allowed.

public void AddLine(TSource source, IPolyline2D line, int typeId, LineAttributes? attributes = null)

Parameters

source TSource

The host's reference to the line.

line IPolyline2D

The geometry; the coordinates are copied, so the host may release it.

typeId int

The edge type.

attributes LineAttributes?

Direction, switching state, surveyed length and weights; null for the defaults.

Exceptions

ArgumentNullException

line is null.

ArgumentOutOfRangeException

The surveyed length is negative or not finite, or the direction is unknown.

ArgumentException

The line is empty, a path has fewer than two points, a coordinate is not finite, or a weight is not in the options.

InvalidOperationException

The builder has built already.

AddNode(TSource, TNodeId, IPoint2D, int, bool)

Adds a real node: a box, a transformer, a switch, a customer.

public void AddNode(TSource source, TNodeId id, IPoint2D point, int typeId, bool blocked = false)

Parameters

source TSource

The host's reference to the point.

id TNodeId

The node id; unique.

point IPoint2D

The location; Z and M are not used.

typeId int

The node type, not 0 (which is the untyped helper node).

blocked bool

The normal switching state.

Exceptions

ArgumentNullException

id or point is null.

ArgumentOutOfRangeException

typeId is 0.

ArgumentException

The location is not finite, or the id was added before.

InvalidOperationException

The builder has built already.

AddNode(TSource, TNodeId, Coordinate, int, bool)

Adds a real node at a coordinate; Z and M are not used.

public void AddNode(TSource source, TNodeId id, Coordinate location, int typeId, bool blocked = false)

Parameters

source TSource
id TNodeId
location Coordinate
typeId int
blocked bool

Exceptions

ArgumentNullException

id is null.

ArgumentOutOfRangeException

typeId is 0.

ArgumentException

The location is not finite, or the id was added before.

InvalidOperationException

The builder has built already.

Build(INetworkWriter<TNodeId, TEdgeId, TSource>, IProgress<BuildProgress>?, CancellationToken)

Joins, splits, assigns shards, checks the ids and writes every node and then every edge to the writer.

public BuildResult Build(INetworkWriter<TNodeId, TEdgeId, TSource> writer, IProgress<BuildProgress>? progress = null, CancellationToken cancellationToken = default)

Parameters

writer INetworkWriter<TNodeId, TEdgeId, TSource>

Where the network goes: the host's database, or an InMemoryGraph.

progress IProgress<BuildProgress>?

Reported at most every 250 ms and at the end of each phase, on the building thread.

cancellationToken CancellationToken

Stops the build between two items.

Returns

BuildResult

The counts and the notes about the input.

Exceptions

ArgumentNullException

writer is null.

NetworkBuildException

The input cannot form a network; thrown before the first write.

InvalidOperationException

The builder has built already.

OperationCanceledException

The token was cancelled.