public void UpdateChainagesRegardlessOfOrderingAfterSplitBranch() { var network = new Network(); var branch = new Branch { Source = new Node("n1"), Target = new Node("n2"), IsLengthCustom = false, Length = 1000, Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)") }; network.Branches.Add(branch); var f1 = new SimpleBranchFeature(); var f2 = new SimpleBranchFeature(); var f3 = new SimpleBranchFeature(); var f4 = new SimpleBranchFeature(); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 5); NetworkHelper.AddBranchFeatureToBranch(f2, branch, 50); NetworkHelper.AddBranchFeatureToBranch(f3, branch, 15); NetworkHelper.AddBranchFeatureToBranch(f4, branch, 10); NetworkHelper.SplitBranchAtNode(network.Branches.First(), 20); Assert.AreEqual(5, f1.Chainage); Assert.AreEqual(30, f2.Chainage); Assert.AreEqual(15, f3.Chainage); Assert.AreEqual(10, f4.Chainage); }
[NUnit.Framework.Category(TestCategory.Jira)] // TOOLS-9546 public void MapChainageShouldNotThrowWhenFeatureNotOnBranch() { var featureNotOnBranch = new SimpleBranchFeature { Chainage = 600 }; Assert.AreEqual(600, NetworkHelper.MapChainage(featureNotOnBranch)); Assert.AreEqual(600, NetworkHelper.MapChainage(null, 600)); Assert.AreEqual(600, NetworkHelper.MapChainage(null, null, 600)); }
public void SplitBranchFeaturesWithLengthIntoTwoFeaturesWithBranchWithCustomLength() { // n1 f1 n2 n1 f1_1 n3 f1_2 n2 // O--------==================----------O ==> O--------=========O=========----------O // ^ // split var network = new Network(); var node1 = new Node("n1"); var node2 = new Node("n2"); var branch = new Branch("Branch", node1, node2, 100) { Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)"), IsLengthCustom = true, Length = 200 }; var f1 = new SimpleBranchFeature { Name = "f1", Length = 100, Chainage = 50, Geometry = GeometryFromWKT.Parse("LINESTRING(25 0, 75 0)") }; network.Nodes.AddRange(new[] { node1, node2 }); network.Branches.Add(branch); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 50); // split is geometry based --> offset 50 (geometry based) == 100 m (custom length format) NetworkHelper.SplitBranchAtNode(branch, 50); Assert.AreEqual(2, network.Branches.Count); Assert.AreEqual(3, network.Nodes.Count); var branch2 = network.Branches[1]; Assert.AreEqual(1, branch.BranchFeatures.Count); Assert.AreEqual(1, branch2.BranchFeatures.Count); var f2 = branch2.BranchFeatures[0]; Assert.AreEqual(50, f1.Length); Assert.AreEqual(50, f2.Length); Assert.AreEqual(25, f1.Geometry.Length); Assert.AreEqual(25, f2.Geometry.Length); Assert.AreEqual(50, f1.Chainage); Assert.AreEqual(0, f2.Chainage); Assert.AreEqual("f1_1", f1.Name); Assert.AreEqual("f1_2", f2.Name); }
public void SplitBranchFeaturesWithLengthIntoTwoFeaturesWhereTheFeatureWithTheLongestLengthShouldBeOrginalFeature() { // n1 f1 n2 n1 f1_1 n3 f1_2 n2 // O--------==================----------O ==> O--------====O==============----------O // ^ (f1_B = original feature) // split var network = new Network(); var node1 = new Node("n1"); var node2 = new Node("n2"); var branch = new Branch("Branch", node1, node2, 100) { Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)") }; var f1 = new SimpleBranchFeature { Name = "f1", Length = 50, Geometry = GeometryFromWKT.Parse("LINESTRING(25 0, 75 0)") }; network.Nodes.AddRange(new[] { node1, node2 }); network.Branches.Add(branch); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 25); NetworkHelper.SplitBranchAtNode(branch, 40); Assert.AreEqual(2, network.Branches.Count); Assert.AreEqual(3, network.Nodes.Count); var branch2 = network.Branches[1]; Assert.AreEqual(1, branch.BranchFeatures.Count); Assert.AreEqual(1, branch2.BranchFeatures.Count); var feature1 = branch.BranchFeatures[0]; var feature2 = branch2.BranchFeatures[0]; Assert.AreEqual(15, feature1.Length); Assert.AreEqual(35, feature2.Length); Assert.AreEqual(15, feature1.Geometry.Length); Assert.AreEqual(35, feature2.Geometry.Length); Assert.AreEqual(25, feature1.Chainage); Assert.AreEqual(0, feature2.Chainage); Assert.AreEqual("f1_1", feature1.Name); Assert.AreEqual("f1_2", feature2.Name); Assert.AreEqual(f1, feature2); }