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
optionsNetworkBuildOptionsidsINetworkIdFactory<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
sourceTSource-
The host's reference to the line.
lineIPolyline2D-
The geometry; the coordinates are copied, so the host may release it.
typeIdint-
The edge type.
attributesLineAttributes?-
Direction, switching state, surveyed length and weights;
nullfor the defaults.
Exceptions
- ArgumentNullException
-
lineisnull. - 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
sourceTSource-
The host's reference to the point.
idTNodeId-
The node id; unique.
pointIPoint2D-
The location; Z and M are not used.
typeIdint-
The node type, not 0 (which is the untyped helper node).
blockedbool-
The normal switching state.
Exceptions
- ArgumentNullException
-
idorpointisnull. - ArgumentOutOfRangeException
-
typeIdis 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
sourceTSourceidTNodeIdlocationCoordinatetypeIdintblockedbool
Exceptions
- ArgumentNullException
-
idisnull. - ArgumentOutOfRangeException
-
typeIdis 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
writerINetworkWriter<TNodeId, TEdgeId, TSource>-
Where the network goes: the host's database, or an
InMemoryGraph. progressIProgress<BuildProgress>?-
Reported at most every 250 ms and at the end of each phase, on the building thread.
cancellationTokenCancellationToken-
Stops the build between two items.
Returns
- BuildResult
-
The counts and the notes about the input.
Exceptions
- ArgumentNullException
-
writerisnull. - NetworkBuildException
-
The input cannot form a network; thrown before the first write.
- InvalidOperationException
-
The builder has built already.
- OperationCanceledException
-
The token was cancelled.