コード例 #1
0
        public void DiscretizationBinding()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(100, 100));
            var discretization = new Discretization {Network = network};

            var discretizationBindingList = new DiscretizationBindingList(discretization);

            Assert.AreEqual(4, discretizationBindingList.ColumnNames.Count());
            Assert.AreEqual(DiscretizationBindingList.ColumnNameLocationName, discretizationBindingList.ColumnNames[2]);

            Assert.AreEqual(0, discretizationBindingList.Count());

            discretization[new NetworkLocation(network.Branches.First(), 0.0) { Name = "haha" }] = 1.0;

            Assert.AreEqual(1, discretizationBindingList.Count());

            Assert.AreEqual("haha", discretizationBindingList.First()[2].ToString());


        }
コード例 #2
0
 private static INetworkCoverage CreateNetworkDiscretisation(INetwork network, double offset)
 {
     var locations = new List<INetworkLocation>();
     var chainage = offset;
     foreach (var branch in network.Branches)
     {
         chainage = Math.Max(0, chainage);
         while (chainage < branch.Length)
         {
             locations.Add(new NetworkLocation {Branch = branch, Chainage = chainage});
             chainage += offset;
         }
         chainage -= branch.Length;
     }
     var coverage = new Discretization
         {
             Name = "grid",
             Network = network
         };
     coverage.Locations.Values.AddRange(locations);
     return coverage;
 }
コード例 #3
0
        public void CreateSegmentsMultipleCrossSectionsAndFixedPoint()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            var discretization = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      5.0, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      true, // gridAtFixedLength
                                                      2); // fixedLength
            Assert.AreEqual(51, discretization.Locations.Values.Count);


            INetworkLocation networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 8).First();
            //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true);
            discretization.ToggleFixedPoint(networkLocation);
            networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 32).First();
            discretization.ToggleFixedPoint(networkLocation);

            AddTestCrossSectionAt(network, branch1, 10.0);
            AddTestCrossSectionAt(network, branch1, 20.0);
            AddTestCrossSectionAt(network, branch1, 30.0);

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      5.0, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      true, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength
            // expect gridpoints at:
            // begin and end 0 and 100
            // fixed locations 8 and 32.
            // 20 for the cross section, 10 and 30 should not be generated due to existing 
            // fixed points and minimium distance 0f 5.
            Assert.AreEqual(5, discretization.Locations.Values.Count);
            Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(8.0, discretization.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(20.0, discretization.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(32.0, discretization.Locations.Values[3].Offset, 1.0e-6);
            Assert.AreEqual(100.0, discretization.Locations.Values[4].Offset, 1.0e-6);
        }
コード例 #4
0
        public void CreateSegmentsMultipleStructuresAndFixedPoint()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            var discretization = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      5.0, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      true, // gridAtFixedLength
                                                      2); // fixedLength
            Assert.AreEqual(51, discretization.Locations.Values.Count);


            INetworkLocation networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 8).First();
            //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true);
            discretization.ToggleFixedPoint(networkLocation);
            networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 32).First();
            discretization.ToggleFixedPoint(networkLocation);
            //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true);

            AddTestStructureAt(network, branch1, 10.0);
            AddTestStructureAt(network, branch1, 20.0);
            AddTestStructureAt(network, branch1, 30.0);

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      6.0, // minimumDistance
                                                      true,  // gridAtStructure
                                                      4.0, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength
            // expect gridpoints with no minimumDistance
            // 0  8 (6 14) (16 24) (26 34) 32 100 
            // 0  6 8 14 16 24 26 32 34 100
            //        10   20   30                 // structure locations
            // 0    8   14    24    32      100    // result 

            // fixed locations 8 and 32.
            // first structure (6) and 14
            // second structure 16 and 24; 16 will be merged into 14 -> 15
            // third structure 26 and (34); 26 will be merged into 24 -> 25
            // fixed points and minimium distance 0f 5.

            Assert.AreEqual(6, discretization.Locations.Values.Count);
            Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(8.0, discretization.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(15.0, discretization.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(25.0, discretization.Locations.Values[3].Offset, 1.0e-6);
            Assert.AreEqual(32.0, discretization.Locations.Values[4].Offset, 1.0e-6);
            Assert.AreEqual(100.0, discretization.Locations.Values[5].Offset, 1.0e-6);
        }
コード例 #5
0
        public void CreateSegmentsCrossSectionAndMinimumDistanceNearEnd()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            AddTestCrossSectionAt(network, branch1, 99.0);

            var networkCoverage = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      5.0, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      true, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength

            Assert.AreEqual(2, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
        }
コード例 #6
0
        public void CreateSegmentsMultipleCrossSectionAndMinimumDistance()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            // add multiple cross sections and generate calculation points at the cross section locations
            // Grid cells too smal should not be generated.
            AddTestCrossSectionAt(network, branch1, 1.0);
            AddTestCrossSectionAt(network, branch1, 2.0);
            AddTestCrossSectionAt(network, branch1, 3.0);
            AddTestCrossSectionAt(network, branch1, 4.0);
            AddTestCrossSectionAt(network, branch1, 5.0);
            AddTestCrossSectionAt(network, branch1, 6.0);

            var networkCoverage = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      5.0, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      true, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength

            Assert.AreEqual(3, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(5.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
        }
コード例 #7
0
        public void CreateSegments2StructureAtNearMinimumEndBranch()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            AddTestStructureAt(network, branch1, 99.2);
            AddTestStructureAt(network, branch1, 98.8);

            var networkCoverage = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      0.5, // minimumDistance
                                                      true,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength

            // structure at near minimumdistance; expect 1 point centered at first segment
            // structure at less than minimumdistance; expect 1 point left out
            // [-----------------------------------------------------------]
            //                                             98.8   99.2
            // x----------------------------------------x-------x------x---x
            // 0                                      98.3     99   (99.6) 100

            Assert.AreEqual(4, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(98.3, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(99.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
            //Assert.AreEqual(99.6, networkCoverage.Locations.Values[3].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[3].Offset, 1.0e-6);
        }
コード例 #8
0
        public void CreateSegmentsFixedLocations()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();
            var discretization = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      0.5, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      true, // gridAtFixedLength
                                                      10); // fixedLength
            Assert.AreEqual(11, discretization.Locations.Values.Count);
            Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(50.0, discretization.Locations.Values[5].Offset, 1.0e-6);
            Assert.AreEqual(100.0, discretization.Locations.Values[10].Offset, 1.0e-6);

            INetworkLocation networkLocation = discretization.Locations.Values[7];
            Assert.AreEqual(70.0, networkLocation.Offset, 1.0e-6);
            discretization.ToggleFixedPoint(networkLocation);
            //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true);

            HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage
                                                      branch1, // branch
                                                      0.5, // minimumDistance
                                                      false,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      true, // gridAtFixedLength
                                                      40); // fixedLength
            // expect values at 
            // - 0 and 100 start and end
            // - 70 for fixed location
            // - none between 70 and 100
            // - (0 - 70) > 40, divide in equal parts -> 35
            Assert.AreEqual(4, discretization.Locations.Values.Count);
            Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(35.0, discretization.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(70.0, discretization.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(100.0, discretization.Locations.Values[3].Offset, 1.0e-6);
        }
コード例 #9
0
        public void CreateSegments2StructureAtNearMinimumBeginBranch()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            AddTestStructureAt(network, branch1, 0.8);
            AddTestStructureAt(network, branch1, 1.2);

            var networkCoverage = new Discretization()
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      0.001, // minimumDistance
                                                      true,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength

            // structure at near minimumdistance; expect 1 point centered at first segment
            // [----------------------
            //                0.8   1.2
            // x       x          x             x ------------------ x
            // 0      0.3        1.0           1.7                  100
            //         ^

            Assert.AreEqual(5, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(0.3, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(1.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(1.7, networkCoverage.Locations.Values[3].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[4].Offset, 1.0e-6);

            // repeat with minimumDistance set to 0.5
            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      0.5, // minimumDistance
                                                      true,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength
            // expect gridpoints at 0.3 eliminated
            Assert.AreEqual(4, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(1.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(1.7, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[3].Offset, 1.0e-6);
        }
コード例 #10
0
        public void CreateSegments1StructureAtNearMinimumBeginBranch()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            AddTestStructureAt(network, branch1, 0.8);

            var networkCoverage = new Discretization
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1, // branch
                                                      0.5, // minimumDistance
                                                      true,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength

            // structure at near minimumdistance; expect point centered at 0.8 - 0.5 = 0.3 not created
            // [----------------------
            //                0.8
            // x       x             x ----------------------------- x
            // 0    (0.3)           1.3                             100
            //        ^

            Assert.AreEqual(3, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(1.3, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
        }
コード例 #11
0
        public void CreateSegmentsMultipleStructures()
        {
            IHydroNetwork network = CreateSegmentTestNetwork();
            var branch1 = network.Channels.First();

            AddTestStructureAt(network, branch1, 20);
            AddTestStructureAt(network, branch1, 40);
            AddTestStructureAt(network, branch1, 60);

            var networkCoverage = new Discretization
                                      {
                                          Network = network,
                                          SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations
                                      };

            HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage
                                                      branch1,  // branch
                                                      0, // minimumDistance
                                                      true,  // gridAtStructure
                                                      0.5, // structureDistance
                                                      false, // gridAtCrossSection
                                                      false, // gridAtFixedLength
                                                      -1); // fixedLength
            Assert.AreEqual(8, networkCoverage.Locations.Values.Count);
            Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6);
            Assert.AreEqual(19.5, networkCoverage.Locations.Values[1].Offset, 1.0e-6);
            Assert.AreEqual(20.5, networkCoverage.Locations.Values[2].Offset, 1.0e-6);
            Assert.AreEqual(39.5, networkCoverage.Locations.Values[3].Offset, 1.0e-6);
            Assert.AreEqual(40.5, networkCoverage.Locations.Values[4].Offset, 1.0e-6);
            Assert.AreEqual(59.5, networkCoverage.Locations.Values[5].Offset, 1.0e-6);
            Assert.AreEqual(60.5, networkCoverage.Locations.Values[6].Offset, 1.0e-6);
            Assert.AreEqual(100.0, networkCoverage.Locations.Values[7].Offset, 1.0e-6);
        }
コード例 #12
0
ファイル: DataItemTest.cs プロジェクト: lishxi/_SharpMap
        public void LinkAndUnlinkTwoDiscretizationItemsCheckValueAndName()
        {
            var grid1 = new Discretization { Name = "grid1" };
            var grid2 = new Discretization { Name = "grid2" };

            var dataItem1 = new DataItem(grid1, "a1");
            var dataItem2 = new DataItem(grid2, "a2");

            dataItem2.LinkTo(dataItem1);

            dataItem2.Unlink();

            Assert.AreEqual(typeof(Discretization), dataItem2.Value.GetType());
            Assert.AreEqual(typeof(Discretization), dataItem1.Value.GetType());

            var grid2X = (Discretization)dataItem2.Value;

            Assert.AreEqual("computational grid", grid2X.Name);
        }
コード例 #13
0
ファイル: DataItemTest.cs プロジェクト: lishxi/_SharpMap
        public void LinkAndUnlinkTwoDiscretizationItems()
        {
            var dataObject1 = new Discretization();
            var dataObject2 = new Discretization();

            var dataItem1 = new DataItem(dataObject1, "a1");
            var dataItem2 = new DataItem(dataObject2, "a2");

            dataItem2.LinkTo(dataItem1);

            Assert.IsTrue(dataItem2.IsLinked);
            Assert.AreSame(dataItem1, dataItem2.LinkedTo);
            Assert.AreSame(dataItem2, dataItem1.LinkedBy[0]);

            dataItem2.Unlink();

            Assert.AreEqual(null, dataItem2.LinkedTo);
            Assert.AreEqual(0, dataItem1.LinkedBy.Count);
        }