IHydroNetwork network = new Network(); INode node1 = new Node(); INode node2 = new Node(); INode node3 = new Node(); network.Nodes.Add(node1); network.Nodes.Add(node2); network.Nodes.Add(node3); IChannel channel1 = new Channel { Name = "channel2", Length = 100.0, Source = node1, Target = node2 }; IChannel channel2 = new Channel { Name = "channel2", Length = 100.0, Source = node2, Target = node3 }; network.Channels.Add(channel1); network.Channels.Add(channel2); // add first cross-section directly to branch ICrossSection crossSection1 = new CrossSection { Name = "cross-section1", Offset = 50.0 }; branch1.CrossSections.Add(crossSection1); // add second cross-section via network (performance will be smaller!) ICrossSection crossSection2 = new CrossSection { Name = "cross-section2", Offset = 50.0, Branch = branch2 }; network.CrossSections.Add(crossSection2);
Note, that IChannel is an interface extending IBranch from GeoAPI.Extensions.Networks.
You can also use var instead of IChannel, INode types in the code above, to make it a bit simpler:
var network = new Network(); var node1 = new Node(); var node2 = new Node(); var node3 = new Node(); network.Nodes.Add(node1); network.Nodes.Add(node2); network.Nodes.Add(node3); var channel1 = new Channel { Name = "channel2", Length = 100.0, Source = node1, Target = node2 }; var channel2 = new Channel { Name = "channel2", Length = 100.0, Source = node2, Target = node3 }; network.Channels.Add(channel1); network.Channels.Add(channel2); // add first cross-section directly to branch var crossSection1 = new CrossSection { Name = "cross-section1", Offset = 50.0 }; branch1.CrossSections.Add(crossSection1); // add second cross-section via network (performance will be smaller!) var crossSection2 = new CrossSection { Name = "cross-section2", Offset = 50.0, Branch = branch2 }; network.CrossSections.Add(crossSection2);
All features which are created in the code must be added to the network either directly to the branch or via network.