コード例 #1
0
        public void IsBranchFeatureInRoute()
        {
            var network           = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100));
            var branch            = network.Branches[0];
            var networkLocation0  = new NetworkLocation(branch, 0);
            var networkLocation10 = new NetworkLocation(branch, 10);
            var networkLocation20 = new NetworkLocation(branch, 20);
            var networkLocation30 = new NetworkLocation(branch, 30);
            var networkLocation40 = new NetworkLocation(branch, 40);

            branch.BranchFeatures.Add(networkLocation0);
            branch.BranchFeatures.Add(networkLocation10);
            branch.BranchFeatures.Add(networkLocation20);
            branch.BranchFeatures.Add(networkLocation30);
            branch.BranchFeatures.Add(networkLocation40);

            var route = RouteHelper.CreateRoute(
                new[] { new NetworkLocation(branch, 5), new NetworkLocation(branch, 35) });

            Assert.IsFalse(RouteHelper.IsBranchFeatureInRoute(route, networkLocation0));
            Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation10));
            Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation20));
            Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation30));
            Assert.IsFalse(RouteHelper.IsBranchFeatureInRoute(route, networkLocation40));
        }
コード例 #2
0
        public void ThrowExceptionWhenBranchIdsAreNotUnique()
        {
            var network = new Network();

            var node1 = new Node("node1");
            var node2 = new Node("node2");
            var node3 = new Node("node3");

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);

            var branch1 = new Branch("branch1", node1, node2, 100.0)
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)")
            };
            var branch2 = new Branch("branch2", node2, node3, 200.0)
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 300 0)")
            };

            network.Branches.Add(branch1);
            network.Branches.Add(branch2);

            var location = new NetworkLocation(network.Branches[0], 0);

            var typeConverter = new NetworkLocationTypeConverter(network);

            typeConverter.ConvertToStore(location); // throws exception since branch ids are not unique
        }
コード例 #3
0
        public void AddCoverages()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0),
                                                          new Point(100, 100));
            var location  = new NetworkLocation(network.Branches[0], 0);
            var coverageA = new NetworkCoverage {
                Network = network
            };
            var coverageB = new NetworkCoverage {
                Network = network
            };

            //add a uniform coverage B to a
            coverageB.DefaultValue = 100.0;

            coverageA[location] = 40.0;
            coverageA.Add(coverageB);

            Assert.AreEqual(140.0, coverageA[location]);

            //define a value for B so it no longer uses default value
            coverageB[location] = -20.0;

            //should substract the -20 now
            coverageA.Add(coverageB);
            Assert.AreEqual(120.0, coverageA[location]);
        }
コード例 #4
0
ファイル: NetworkHelperTest.cs プロジェクト: cugkgq/Project
        [NUnit.Framework.Category(TestCategory.Jira)] //TOOLS-7624
        public void GetShortestPathShouldStayWithinNetworkBranches()
        {
            // Create network with 2 orthogonal branches

            var network = new Network();
            var branch1 = new Branch
            {
                Name     = "Branch1",
                Geometry = new LineString(new[]
                {
                    new Coordinate(0, 0), new Coordinate(100, 0)
                })
            };
            var branch2 = new Branch
            {
                Name     = "Branch2",
                Geometry = new LineString(new[]
                {
                    new Coordinate(100, 0), new Coordinate(100, 100)
                })
            };
            var start = new Node {
                Network = network, Geometry = new Point(new Coordinate(0, 0)), Name = "StartNode"
            };
            var middle = new Node {
                Network = network, Geometry = new Point(new Coordinate(100, 0)), Name = "MiddleNode"
            };
            var end = new Node {
                Network = network, Geometry = new Point(new Coordinate(100, 100)), Name = "EndNode"
            };

            branch1.Source = start;
            branch1.Target = middle;
            branch2.Source = middle;
            branch2.Target = end;
            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Nodes.Add(start);
            network.Nodes.Add(middle);
            network.Nodes.Add(end);

            // Add a location to each node

            var startLocation  = new NetworkLocation(branch1, 0);
            var middleLocation = new NetworkLocation(branch1, 100);
            var endLocation    = new NetworkLocation(branch2, 100);

            // Compute the segment over the second branch

            var segments = NetworkHelper.GetShortestPathBetweenBranchFeaturesAsNetworkSegments(network, middleLocation, endLocation);

            // Validate

            Assert.AreEqual(1, segments.Count, "Unexpected number of segments found");

            var segment = segments.FirstOrDefault();

            Assert.AreEqual(0, segment.Chainage, "Incorrect offset of segment calculated");
            Assert.AreEqual(100, segment.EndChainage, "Incorrect final offset of segment calculated.");
        }
コード例 #5
0
        public void SegmentsForTimeFilteredCoverage()
        {
            var network = CreateNetwork();

            var dateTime = DateTime.Now;

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };
            // test for defaultvalue

            // set values for only one t.
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl13 = new NetworkLocation(network.Branches[1], 100.0);

            networkCoverage[dateTime, nl11] = 0.1;
            networkCoverage[dateTime, nl12] = 0.2;
            networkCoverage[dateTime, nl13] = 0.3;

            //action! filter on t1
            var filtered = (INetworkCoverage)networkCoverage.FilterTime(dateTime);

            //segments should not be affected
            Assert.AreEqual(networkCoverage.Segments.Values.Count, filtered.Segments.Values.Count);
        }
コード例 #6
0
        public void GeometryForTimeFilteredCoverage()
        {
            var network = RouteHelperTest.GetSnakeHydroNetwork(false, new Point(0, 0), new Point(100, 0), new Point(100, 200));

            var dateTime = DateTime.Now;

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };
            // test for defaultvalue

            // set values for only one t.
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl13 = new NetworkLocation(network.Branches[1], 100.0);

            networkCoverage[dateTime, nl11] = 0.1;
            networkCoverage[dateTime, nl12] = 0.2;
            networkCoverage[dateTime, nl13] = 0.3;

            //action! filter on t1
            var filtered = networkCoverage.FilterTime(dateTime);

            //segments should not be affected
            Assert.AreEqual(networkCoverage.Geometry.EnvelopeInternal, filtered.Geometry.EnvelopeInternal);
        }
コード例 #7
0
        public void CheckRouteChainages()
        {
            var network           = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100));
            var branch            = network.Branches[0];
            var networkLocation0  = new NetworkLocation(branch, 0);
            var networkLocation10 = new NetworkLocation(branch, 10);
            var networkLocation20 = new NetworkLocation(branch, 20);
            var networkLocation30 = new NetworkLocation(branch, 30);
            var networkLocation40 = new NetworkLocation(branch, 40);

            branch.BranchFeatures.Add(networkLocation0);
            branch.BranchFeatures.Add(networkLocation10);
            branch.BranchFeatures.Add(networkLocation20);
            branch.BranchFeatures.Add(networkLocation30);
            branch.BranchFeatures.Add(networkLocation40);

            var route  = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch, 5), new NetworkLocation(branch, 35) });
            var route2 = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch, 35), new NetworkLocation(branch, 5) });

            Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route, networkLocation0));
            Assert.AreEqual(5, RouteHelper.GetRouteChainage(route, networkLocation10));
            Assert.AreEqual(15, RouteHelper.GetRouteChainage(route, networkLocation20));
            Assert.AreEqual(25, RouteHelper.GetRouteChainage(route, networkLocation30));
            Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route, networkLocation40));

            Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route2, networkLocation0));
            Assert.AreEqual(25, RouteHelper.GetRouteChainage(route2, networkLocation10));
            Assert.AreEqual(15, RouteHelper.GetRouteChainage(route2, networkLocation20));
            Assert.AreEqual(5, RouteHelper.GetRouteChainage(route2, networkLocation30));
            Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route2, networkLocation40));
        }
コード例 #8
0
        public void SubstractTimeDependentCoverages()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0),
                                                          new Point(100, 100));
            var location  = new NetworkLocation(network.Branches[0], 0);
            var coverageA = new NetworkCoverage {
                Network = network, IsTimeDependent = true
            };
            var coverageB = new NetworkCoverage {
                Network = network, IsTimeDependent = true
            };

            var dates = new[] { new DateTime(2000, 1, 1), new DateTime(2001, 1, 1) };

            //add a uniform coverage B to a
            coverageB.DefaultValue = 100.0;
            coverageB.Time.SetValues(dates);

            coverageA[dates[0], location] = 40.0;
            coverageA[dates[1], location] = 10.0;
            coverageA.Substract(coverageB);

            Assert.AreEqual(-60.0, coverageA[dates[0], location]);
            Assert.AreEqual(-90.0, coverageA[dates[1], location]);
        }
コード例 #9
0
 private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     NetworkLocation location = (NetworkLocation)editorGrid.DataContext;
     if (location.Name.Trim().Length == 0)
     {
         MessageBox.Show("网络名称不能为空", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     networkLocationManager.Update(location);
     RefreshList();
 }
コード例 #10
0
        public void DefaultValueTest()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network, DefaultValue = 0.33
            };
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(nl11));
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            IPickResult pr = PickResult;

            if (EventSender == gviMouseSelectMode.gviMouseSelectClick)
            {
                if (PickResult != null)
                {
                    if (pr.Type == gviObjectType.gviObjectFeatureLayer)
                    {
                        IFeatureLayerPickResult flpr = pr as IFeatureLayerPickResult;
                        int           fid            = flpr.FeatureId;
                        IFeatureLayer fl             = flpr.FeatureLayer;
                        foreach (IFeatureClass fc in fcMap_POI.Keys)
                        {
                            if (fc.Guid.Equals(fl.FeatureClassId))
                            {
                                IRowBuffer row = fc.GetRow(fid);

                                int    pos   = row.FieldIndex("Geometry");
                                IPoint point = row.GetValue(pos) as IPoint;
                                try
                                {
                                    INetworkLocation location = new NetworkLocation();
                                    location.Position = point;
                                    routeSolver.AddLocation(location);
                                }
                                catch (COMException ex)
                                {
                                    MessageBox.Show("所选点距离网络太远,请调整LocationSearchTolerance大小");
                                    return;
                                }

                                pos = row.FieldIndex("Name");
                                if (row.GetValue(pos) == null)
                                {
                                    pos = 0;
                                }
                                if (txtLocationNames.Text == "")
                                {
                                    txtLocationNames.Text = row.GetValue(pos).ToString();
                                }
                                else
                                {
                                    txtLocationNames.Text = txtLocationNames.Text + Environment.NewLine + row.GetValue(pos).ToString();
                                }
                                this.axRenderControl1.FeatureManager.HighlightFeature(fc, fid, System.Drawing.Color.Yellow);
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        public void SubstractComplexCoveragesFromClonedNetworks()
        {
            var network   = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 0));
            var blNetwork = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(100, 100));

            var waterLevel = new NetworkCoverage {
                Network = network
            };
            var bedLevel = new NetworkCoverage {
                Network = blNetwork
            };

            var branchA   = network.Branches[0];
            var branchB   = network.Branches[1];
            var blBranchB = blNetwork.Branches[1];

            var locationA1 = new NetworkLocation(branchA, 0);
            var locationA2 = new NetworkLocation(branchA, branchA.Length / 2);
            var locationA3 = new NetworkLocation(branchA, branchA.Length);
            var locationB1 = new NetworkLocation(branchB, 0);
            var locationB2 = new NetworkLocation(branchB, branchB.Length / 2);
            var locationB3 = new NetworkLocation(branchB, branchB.Length);

            var blLocationB1 = new NetworkLocation(blBranchB, 0);
            var blLocationB2 = new NetworkLocation(blBranchB, blBranchB.Length / 2);
            var blLocationB3 = new NetworkLocation(blBranchB, blBranchB.Length);

            //add a uniform coverage B to a
            bedLevel.DefaultValue  = 100.0;
            bedLevel[blLocationB1] = 100.0;
            bedLevel[blLocationB2] = 120.0;
            bedLevel[blLocationB3] = 80.0;

            waterLevel[locationA1] = 140.0;
            waterLevel[locationA2] = 110.0;
            waterLevel[locationA3] = 90.0;
            waterLevel[locationB1] = 120.0;
            waterLevel[locationB2] = 130.0;
            waterLevel[locationB3] = 140.0;

            waterLevel.Substract(bedLevel);

            var waterDepth = waterLevel;

            Assert.AreEqual(40.0, waterDepth[locationA1]);
            Assert.AreEqual(10.0, waterDepth[locationA2]);
            Assert.AreEqual(-10.0, waterDepth[locationA3]);
            Assert.AreEqual(20.0, waterDepth[locationB1]);
            Assert.AreEqual(130.0, waterDepth[locationB2]);
            Assert.AreEqual(140.0, waterDepth[locationB3]);
        }
コード例 #13
0
        public void DefaultValueTestInvalidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network, DefaultValue = 0.33
            };

            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(DateTime.Now, nl11));
        }
コード例 #14
0
 public void Remove(NetworkLocation record)
 {
     if (record == null)
     {
         return;
     }
     if (record.ProfileId != null && record.ProfileId.Trim() != "")
     {
         networkProfileMapper.Remove(record.ProfileId);
     }
     if (record.SignatureId != null && record.SignatureId.Trim() != "")
     {
         networkSignatureMapper.Remove(record.SignatureId);
     }
 }
コード例 #15
0
        public void Update(NetworkLocation record)
        {
            if (record == null || record.ProfileId == null || record.SignatureId == null)
            {
                return;
            }
            NetworkProfile   profile   = new NetworkProfile(record.ProfileId);
            NetworkSignature signature = new NetworkSignature(record.SignatureId);

            profile.Category    = record.Category;
            profile.Description = signature.Description = record.Description;
            profile.ProfileName = signature.FirstNetwork = record.Name;
            networkProfileMapper.Update(profile);
            networkSignatureMapper.Update(signature);
        }
コード例 #16
0
        public void InterpolationTime()
        {
            var network = CreateNetwork();

            var dateTime = DateTime.Now;

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };
            // test for defaultvalue

            // set values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl13 = new NetworkLocation(network.Branches[1], 100.0);

            networkCoverage[dateTime, nl11] = 0.1;
            networkCoverage[dateTime, nl12] = 0.2;
            networkCoverage[dateTime, nl13] = 0.3;

            // test the exact networklocation
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl11));
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl12));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl13));

            INetworkLocation nl21 = new NetworkLocation(network.Branches[0], 0.0);
            INetworkLocation nl22 = new NetworkLocation(network.Branches[0], 100.0);
            INetworkLocation nl23 = new NetworkLocation(network.Branches[1], 0.0);
            INetworkLocation nl24 = new NetworkLocation(network.Branches[1], 200.0);

            // test for networklocations at same location but other instances
            // branch and offset nl21 equals nl11
            Assert.AreEqual(0.1, networkCoverage.Evaluate(dateTime, nl21));
            // branch and offset nl22 equals nl12
            Assert.AreEqual(0.2, networkCoverage.Evaluate(dateTime, nl22));

            // test for value at new location with constant interpolation (1 values available at branch)
            // expect value of nl13 to be set for complete branches[1]
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl23));
            Assert.AreEqual(0.3, networkCoverage.Evaluate(dateTime, nl24));

            // test for interpolation
            INetworkLocation nl1 = new NetworkLocation(network.Branches[0], 50.0);

            Assert.AreEqual(0.15, networkCoverage.Evaluate(dateTime, nl1), 1e-6);
        }
コード例 #17
0
ファイル: MainForm.cs プロジェクト: batuZ/Samples
        //private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    dsManager.DeleteNetworkDataset("newNetworkDataset");
        //}

        private void btnSelectLocation_Click(object sender, System.EventArgs e)
        {
            clear();
            clearDeep();

            #region 我在这(两点间最优路径)
            if (((Button)sender).Name == "btnImHere")
            {
                this.axRenderControl1.Camera.GetCamera2(out fdepoint, out ang);
                try
                {
                    INetworkLocation location = new NetworkLocation();
                    location.Position = fdepoint;
                    routeSolver.AddLocation(location);
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }

                if (txtLocationNames.Text == "")
                {
                    txtLocationNames.Text = "I'm Here!";
                }
                else
                {
                    txtLocationNames.Text = txtLocationNames.Text + Environment.NewLine + "I'm Here!";
                }
                IImagePointSymbol ips = new ImagePointSymbol();
                ips.ImageName = "#(i)";
                ips.Size      = 50;
                renderPoint   = this.axRenderControl1.ObjectManager.CreateRenderPoint(fdepoint, ips, rootId);
                renderPoint.MaxVisibleDistance = 10000;
                MessageBox.Show("请选择您想去的终点");
            }
            #endregion

            // 注册控件拾取事件
            this.axRenderControl1.RcMouseClickSelect -= new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);

            this.axRenderControl1.RcMouseClickSelect += new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);

            this.axRenderControl1.InteractMode          = gviInteractMode.gviInteractSelect;
            this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectFeatureLayer;
            this.axRenderControl1.MouseSelectMode       = gviMouseSelectMode.gviMouseSelectClick;
        }
コード例 #18
0
        private IFeature AddFeatureFromGeometryDelegate(IFeatureProvider provider, IGeometry geometry)
        {
            IBranch branch  = (IBranch)mapControl.SnapTool.SnapResult.SnappedFeature;
            double  offset  = GeometryHelper.Distance((ILineString)branch.Geometry, geometry.Coordinates[0]);
            var     feature = new NetworkLocation(branch, offset)
            {
                Geometry = geometry
            };

            //IFeatureInteractor FeatureInteractor = new NetworkLocationEditor(new CoordinateConverter(mapControl.Map),
            //                                               networkCoverageLayer.LocationLayer, feature,
            //                                               new VectorStyle());
            //FeatureInteractor.Start();
            //FeatureInteractor.Stop(mapControl.SnapTool.SnapResult); // hack
            provider.Features.Add(feature);
            return(feature);
        }
コード例 #19
0
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IList<object> removedList = (IList<object>)e.RemovedItems;
            foreach (object item in removedList)
            {
                selectedItems.Remove((NetworkLocation)item);
            }
            IList<object> addedList = (IList<object>)e.AddedItems;
            foreach (object item in addedList)
            {
                selectedItems.Add((NetworkLocation)item);
            }

            if (listView.SelectedItem != null)
            {
                NetworkLocation location = (NetworkLocation)listView.SelectedItem;
                editorGrid.DataContext = location.Clone();
            }
        }
コード例 #20
0
        public void ConvertToStore()
        {
            var network = new Network();

            var node1 = new Node("node1");
            var node2 = new Node("node2");
            var node3 = new Node("node3");

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);

            var branch1 = new Branch("branch1", node1, node2, 100.0)
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)")
            };
            var branch2 = new Branch("branch2", node2, node3, 200.0)
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 200 300)")
            };

            network.Branches.Add(branch1);
            network.Branches.Add(branch2);

            var location = new NetworkLocation(network.Branches[1], 22);

            var typeConverter = new NetworkLocationTypeConverter(network);
            var tuple         = typeConverter.ConvertToStore(location);

            Assert.AreEqual(5, tuple.Length);

            //id
            Assert.AreEqual(1, tuple[0]);
            //chainage
            Assert.AreEqual(22.0d, tuple[1]);
            //branch name
            Assert.AreEqual("branch2".PadRight(30).ToCharArray(), tuple[2]);
            //x
            Assert.AreEqual(106.957d, (double)tuple[3], 0.001d);
            //y
            Assert.AreEqual(20.871d, (double)tuple[4], 0.001d);
        }
コード例 #21
0
        public void ExtraPolationNoTime()
        {
            var network = CreateNetwork();

            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network
            };

            // test for defaultvalue

            // set two values
            INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 5.0);
            INetworkLocation nl12 = new NetworkLocation(network.Branches[0], 10.0);

            networkCoverage[nl11] = 0.1;
            networkCoverage[nl12] = 0.1;

            //extrapolation
            Assert.AreEqual(0.1, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 20.0)));
        }
コード例 #22
0
        public void DefaultValueTestValidTime()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network, DefaultValue = 0.33
            };

            var dateTime = DateTime.Now;

            networkCoverage[dateTime, new NetworkLocation(network.Branches[0], 50.0)] = 0.1;
            networkCoverage.Locations.ExtrapolationType = ApproximationType.Constant;

            // ask value form other branch; default value is expected
            INetworkLocation nl11 = new NetworkLocation(network.Branches[1], 0.0);

            // no network location set in networkCoverage expect the default value to return
            Assert.AreEqual(0.33, networkCoverage.Evaluate(dateTime, nl11));
        }
コード例 #23
0
        public void SubstractCoverages()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0),
                                                          new Point(100, 100));
            var location  = new NetworkLocation(network.Branches[0], 0);
            var coverageA = new NetworkCoverage {
                Network = network
            };
            var coverageB = new NetworkCoverage {
                Network = network
            };

            //add a uniform coverage B to a
            coverageB.DefaultValue = 100.0;

            coverageA[location] = 40.0;
            coverageA.Substract(coverageB);

            Assert.AreEqual(-60.0, coverageA[location]);
        }
コード例 #24
0
        public void GeometryForCoverage()
        {
            var network = RouteHelperTest.GetSnakeHydroNetwork(false, new Point(0, 0), new Point(100, 0), new Point(100, 200));


            var networkCoverage = new NetworkCoverage {
                Network = network
            };
            // test for defaultvalue

            // set values for only one t.
            INetworkLocation networkLocation1 = new NetworkLocation(network.Branches[0], 50.0);
            INetworkLocation networkLocation2 = new NetworkLocation(network.Branches[1], 50.0);

            networkCoverage[networkLocation1] = 0.1;
            networkCoverage[networkLocation2] = 0.2;


            //envelope is based on network locations now
            Assert.AreEqual(new GeometryCollection(new[] { networkLocation1.Geometry, networkLocation2.Geometry }), networkCoverage.Geometry);
        }
コード例 #25
0
        public void GetTimeSeriesForCoverageOnLocation()
        {
            var network = CreateNetwork();
            //set up  a coverage on one location for three moments
            INetworkCoverage networkCoverage = new NetworkCoverage {
                Network = network, IsTimeDependent = true
            };
            var networkLocation = new NetworkLocation(network.Branches[0], 0);

            for (var i = 1; i < 4; i++)
            {
                networkCoverage[new DateTime(2000, 1, i), networkLocation] = i;
            }

            //filter the function for the networkLocation
            IFunction filteredCoverage = networkCoverage.GetTimeSeries(networkLocation);

            Assert.AreEqual(3, filteredCoverage.Components[0].Values.Count);
            Assert.AreEqual(1, filteredCoverage.Arguments.Count);
            Assert.AreEqual(filteredCoverage.Arguments[0].Values, networkCoverage.Time.Values);
        }
コード例 #26
0
        private async void InitializeLocationManager()
        {
            this.locationManager = (LocationManager)GetSystemService(LocationService);
            Criteria criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Fine
            };

            IList <string> acceptableLocationProviders = this.locationManager.GetProviders(criteriaForLocationService, true);

            this.locationProvider = acceptableLocationProviders.Any() ? acceptableLocationProviders.First() : string.Empty;
            Log.Debug(Tag, "Location Provider: " + this.locationProvider + ".");

            // get last known location
            this.currentLocation = locationManager.GetLastKnownLocation(this.locationProvider);

            if (currentLocation == null)
            {
                Android.Widget.Toast.MakeText(this, "Unable to determine location", Android.Widget.ToastLength.Short).Show();
                return;
            }

            var objNetworkLocation = new NetworkLocation()
            {
                Provider  = this.currentLocation.Provider,
                Latitude  = this.currentLocation.Latitude,
                Longitude = this.currentLocation.Longitude,
                Altitude  = this.currentLocation.HasAltitude ? this.currentLocation.Altitude : 0,
                Accuracy  = this.currentLocation.HasAccuracy ? this.currentLocation.Accuracy : 0,
                Speed     = this.currentLocation.HasSpeed ? this.currentLocation.Speed : 0,
                Bearing   = this.currentLocation.HasBearing ? this.currentLocation.Bearing : 0,
                Time      = this.currentLocation.Time
            };

            wiFiLocation = objNetworkLocation;

            Address address = await ReverseGeocodeCurrentLocation();

            DisplayAddress(address);
        }
コード例 #27
0
        public void AllTimeValuesForFilteredCoverage()
        {
            var network         = RouteHelperTest.GetSnakeHydroNetwork(false, new Point(0, 0), new Point(100, 0), new Point(100, 200));
            var networkCoverage = new NetworkCoverage("test", true)
            {
                Network = network
            };
            // test for defaultvalue

            //set values for 2 times
            var times = new[] { 1, 2 }.Select(i => new DateTime(2000, 1, i)).ToList();

            foreach (var time in times)
            {
                INetworkLocation nl11 = new NetworkLocation(network.Branches[0], 0.0);
                networkCoverage[time, nl11] = 0.3;
            }

            var filteredCoverage = networkCoverage.FilterTime(times[0]);

            Assert.AreEqual(times, filteredCoverage.Time.AllValues);
        }
コード例 #28
0
        public void GetRouteChainageCustomLength()
        {
            var network = CreateThreeNodesNetwork();

            network.Branches[0].IsLengthCustom = true;
            network.Branches[0].Length        *= 2;
            network.Branches[1].IsLengthCustom = true;
            network.Branches[1].Length        *= 3;

            var networkLocation = new NetworkLocation(network.Branches[1], 30);

            NetworkHelper.AddBranchFeatureToBranch(networkLocation, network.Branches[1], 30);

            var route = new Route
            {
                Network = network,
            };

            //route going back to branch 0
            route.Locations.Values.Add(new NetworkLocation(network.Branches[0], 5.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 60.0));
            route.Locations.Values.Add(new NetworkLocation(network.Branches[1], 110.0));
            Assert.AreEqual(225.0, RouteHelper.GetRouteChainage(route, networkLocation));
        }
コード例 #29
0
ファイル: NetworkHelperTest.cs プロジェクト: cugkgq/Project
        public void GetShortestPathSingleBranchReversed()
        {
            var network = new Network();

            var node1 = new Node {
                Network = network, Geometry = new Point(new Coordinate(0, 0)), Name = "node1"
            };
            var node2 = new Node {
                Network = network, Geometry = new Point(new Coordinate(0, 100)), Name = "node2"
            };
            var node3 = new Node {
                Network = network, Geometry = new Point(new Coordinate(100, 0)), Name = "node3"
            };

            network.Nodes.Add(node1);
            network.Nodes.Add(node2);
            network.Nodes.Add(node3);

            var branch1 = new Branch
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 0 100)"),
                Source   = node1,
                Target   = node2,
                Name     = "branch1"
            };
            var branch2 = new Branch
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (0 100, 100 0)"),
                Source   = node2,
                Target   = node3,
                Name     = "branch2"
            };
            var branch3 = new Branch
            {
                Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 0 0)"),
                Source   = node3,
                Target   = node1,
                Name     = "branch3"
            };

            network.Branches.Add(branch1);
            network.Branches.Add(branch2);
            network.Branches.Add(branch3);

            var networkLocation1 = new NetworkLocation
            {
                Geometry = new Point(new Coordinate(90, 0)),
                Branch   = branch1,
                Chainage = 90,
                Name     = "source"
            };
            var networkLocation2 = new NetworkLocation
            {
                Geometry = new Point(new Coordinate(0, 40)),
                Branch   = branch1,
                Chainage = 40,
                Name     = "target"
            };

            var segments = NetworkHelper.GetShortestPathBetweenBranchFeaturesAsNetworkSegments(network, networkLocation1,
                                                                                               networkLocation2);

            Assert.AreEqual(1, segments.Count);
            Assert.IsFalse(segments[0].DirectionIsPositive);
            Assert.AreEqual(90, segments[0].Chainage);
            Assert.AreEqual(40, segments[0].EndChainage);
        }
コード例 #30
0
 public async Task <IHttpActionResult> UpdateNetworkLocation([FromBody] NetworkLocation NetworkLocation)
 {
     return(Ok(await _networkLocationRepository.UpdateNetworkLocation(NetworkLocation)));
 }
コード例 #31
0
 private static void SetParents(IEnumerable children, NetworkLocation parent)
 {
     if (children != null)
     {
         foreach(NetworkLocation net in children)
         {
             net.Parent = parent;
             SetParents(net.Children, net);
         }
     }
 }