private void locations_ValuesChanging(object sender, FunctionValuesChangedEventArgs e)
        {
            if (!(sender is IVariable <INetworkLocation>))
            {
                return;
            }

            //don;t use 'locations'here it calls initialze and therefore very slow.

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                var location = (INetworkLocation)e.Item;

                if (location == null)
                {
                    location = new NetworkLocation(network.Branches[0], 0);
                    e.Item   = location;
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                break;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the NetworkLocations for segment in the source coverage. If the start and/or end location of the 
        /// segment are not in the source they are added.
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="source"></param>
        /// <param name="addNewLocations">Should the end and start of the segment be returned?</param>
        /// <returns></returns>
        public static IEnumerable<INetworkLocation> GetLocationsForSegment(INetworkSegment segment, INetworkCoverage source, bool addNewLocations)
        {
            double min = Math.Min(segment.EndChainage, segment.Chainage);
            double max = Math.Max(segment.EndChainage, segment.Chainage);

            IList<INetworkLocation> locations = new List<INetworkLocation>();
            
            if (addNewLocations)
            {
                var startChainage = segment.DirectionIsPositive ? segment.Chainage : segment.EndChainage;
                locations.Add(new NetworkLocation(segment.Branch, startChainage));
            }
            //need a cast here ..but we are sure since we just built it.
            foreach (var location in source.Locations.Values.Where(
                    nl =>
                    nl.Branch == segment.Branch && nl.Chainage >= min && nl.Chainage <= max))
            {
                if (!locations.Contains(location))
                {
                    locations.Add(location);
                }
            }

            if (addNewLocations)
            {
                var endChainage = segment.DirectionIsPositive ? segment.EndChainage : segment.Chainage;
                var location = new NetworkLocation(segment.Branch, endChainage);
                if (!locations.Contains(location))
                {
                    locations.Add(location);
                }
            }
            
            return !segment.DirectionIsPositive ? locations.Reverse() : locations;
        }
Beispiel #3
0
        /// <summary>
        /// Returns the NetworkLocations for segment in the source coverage. If the start and/or end location of the
        /// segment are not in the source they are added.
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="source"></param>
        /// <param name="addNewLocations">Should the end and start of the segment be returned?</param>
        /// <returns></returns>
        public static IEnumerable <INetworkLocation> GetLocationsForSegment(INetworkSegment segment, INetworkCoverage source, bool addNewLocations)
        {
            double min = Math.Min(segment.EndChainage, segment.Chainage);
            double max = Math.Max(segment.EndChainage, segment.Chainage);

            IList <INetworkLocation> locations = new List <INetworkLocation>();

            if (addNewLocations)
            {
                var startChainage = segment.DirectionIsPositive ? segment.Chainage : segment.EndChainage;
                locations.Add(new NetworkLocation(segment.Branch, startChainage));
            }
            //need a cast here ..but we are sure since we just built it.
            foreach (var location in source.Locations.Values.Where(
                         nl =>
                         nl.Branch == segment.Branch && nl.Chainage >= min && nl.Chainage <= max))
            {
                if (!locations.Contains(location))
                {
                    locations.Add(location);
                }
            }

            if (addNewLocations)
            {
                var endChainage = segment.DirectionIsPositive ? segment.EndChainage : segment.Chainage;
                var location    = new NetworkLocation(segment.Branch, endChainage);
                if (!locations.Contains(location))
                {
                    locations.Add(location);
                }
            }

            return(!segment.DirectionIsPositive ? locations.Reverse() : locations);
        }
        public override T Evaluate <T>(double x, double y)
        {
            // find location on nearest branch
            var point  = new Point(x, y);
            var branch = NetworkHelper.GetNearestBranch(network.Branches, point, EvaluateTolerance);

            var coordinateOnBranch = GeometryHelper.GetNearestPointAtLine((ILineString)branch.Geometry, point.Coordinate, EvaluateTolerance);

            INetworkLocation locationOnBranch = new NetworkLocation
            {
                Branch   = branch,
                Geometry = new Point(coordinateOnBranch)
            };

            NetworkHelper.UpdateBranchFeatureOffsetFromGeometry(locationOnBranch);

            return((T)(object)Evaluate(locationOnBranch));


/*
 *          var nearestLocation = GeometryHelper.GetNearestFeature(new Coordinate(x, y), Locations.Values.Cast<IFeature>(), EvaluateTolerance);
 *          if (nearestLocation == null)
 *          {
 *              return (T)(object)double.NaN; // use missing value
 *          }
 */
/*
 *
 *
 *          return (T)this[nearestLocation];
 */
        }
        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);
        }
Beispiel #6
0
        public override object this[int columnIndex]
        {
            get
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                var networkLocation = base[baseIndex] as INetworkLocation;
                if (networkLocation != null)
                {
                    if (ColumnIsBranchColumn(columnIndex))
                    {
                        return(networkLocation.Branch);
                    }
                    if (ColumnIsChainageColumn(columnIndex))
                    {
                        return(networkLocation.Chainage);
                    }
                    if (ColumnIsLocationNameColumn(columnIndex))
                    {
                        return(networkLocation.Name);
                    }
                }
                return(base[baseIndex]);
            }
            set
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                var oldLocation = (base[baseIndex] as INetworkLocation) ?? new NetworkLocation(null, 0);

                if (ColumnIsBranchColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation((IBranch)value, oldLocation.Chainage);
                    base[baseIndex] = newLocation;
                }
                else if (ColumnIsChainageColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation(oldLocation.Branch, Convert.ToDouble(value));
                    base[baseIndex] = newLocation;
                }
                else if (ColumnIsLocationNameColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation(oldLocation.Branch, oldLocation.Chainage)
                    {
                        Name = Convert.ToString(value)
                    };
                    base[baseIndex] = newLocation;
                }
                else
                {
                    base[baseIndex] = value;
                }
            }
        }
        public override INetworkLocation ConvertFromStore(object source)
        {
            var sourceTuple = (object[])source;

            var branchIdx = Convert.ToInt32(sourceTuple[0]);
            var offset    = Convert.ToDouble(sourceTuple[1]);
            var branch    = Network.Branches[branchIdx];// First(b => b.Id == branchId);

            var location = new NetworkLocation(branch, offset);

            return(location);
        }
        public override object this[int columnIndex]
        {
            get
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                var networkLocation = base[baseIndex] as INetworkLocation;
                if (networkLocation != null)
                {
                    if (ColumnIsBranchColumn(columnIndex))
                    {
                        return networkLocation.Branch;
                    }
                    if (ColumnIsChainageColumn(columnIndex))
                    {
                        return networkLocation.Chainage;
                    }
                    if (ColumnIsLocationNameColumn(columnIndex))
                    {
                        return networkLocation.Name;
                    }
                }
                return base[baseIndex];
            }
            set
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                var oldLocation = (base[baseIndex] as INetworkLocation) ?? new NetworkLocation(null, 0);

                if (ColumnIsBranchColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation((IBranch)value, oldLocation.Chainage);
                    base[baseIndex] = newLocation;
                }
                else if (ColumnIsChainageColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation(oldLocation.Branch, Convert.ToDouble(value));
                    base[baseIndex] = newLocation;
                }
                else if (ColumnIsLocationNameColumn(columnIndex))
                {
                    var newLocation = new NetworkLocation(oldLocation.Branch, oldLocation.Chainage) { Name = Convert.ToString(value) };
                    base[baseIndex] = newLocation;
                }
                else
                {
                    base[baseIndex] = value;
                }
            }
        }
        public override INetworkLocation ConvertFromStore(object source)
        {
            var sourceTuple = (object[])source;

            var branchId = Convert.ToInt32(sourceTuple[0]);
            var offset   = Convert.ToDouble(sourceTuple[1]);
            var branch   = Network.Branches.First(b => b.Id == branchId);

            var location = new NetworkLocation(branch, offset);

            //location.Attributes = new NetworkLocationAttributeAccessor(location, Coverage);

            return(location);
        }
        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]);
        }
        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]);
        }
        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
        }
        public override object this[int columnIndex]
        {
            get
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                if (ColumnIsBranchColumn(columnIndex))
                {
                    return(((INetworkLocation) base[baseIndex]).Branch);
                }
                else if (ColumnIsOffsetColumn(columnIndex))
                {
                    return(((INetworkLocation) base[baseIndex]).Offset);
                }
                return(base[baseIndex]);
            }
            set
            {
                int baseIndex = ColumnIndexToBaseIndex(columnIndex);

                if (ColumnIsBranchColumn(columnIndex))
                {
                    var oldLocation = (INetworkLocation) base[baseIndex];

                    var newLocation = new NetworkLocation((IBranch)value, oldLocation.Offset);
                    base[baseIndex] = newLocation;
                }
                else if (ColumnIsOffsetColumn(columnIndex))
                {
                    var oldLocation = (INetworkLocation) base[baseIndex];
                    var newLocation = new NetworkLocation(oldLocation.Branch, Convert.ToDouble(value));
                    base[baseIndex] = newLocation;
                }
                else
                {
                    base[baseIndex] = value;
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// This method can be override for custom logic in moving values / locations
        /// </summary>
        /// <param name="currentEditAction"></param>
        protected virtual void UpdateValuesForBranchSplit(BranchSplitAction currentEditAction)
        {
            double splitAtOffset = currentEditAction.SplittedBranch.Length;
            var    splitLocation = new NetworkLocation(currentEditAction.SplittedBranch, splitAtOffset);
            var    value         = Evaluate(splitLocation);

            IEnumerable <INetworkLocation> networkLocationsToMove =
                Locations.Values.Where(
                    nl => nl.Branch == currentEditAction.SplittedBranch && nl.Offset >= splitAtOffset)
                .ToList();

            foreach (var location in networkLocationsToMove)
            {
                location.Branch = currentEditAction.NewBranch;
                location.Offset = location.Offset - splitAtOffset;
            }

            //add a point at the end of the orignal branch
            var startLocation = new NetworkLocation(currentEditAction.NewBranch, 0);

            this[splitLocation] = value;
            this[startLocation] = value;
        }
Beispiel #15
0
        public override T Evaluate <T>(double x, double y)
        {
            // find location on nearest branch
            var point  = new Point(x, y);
            var branch = NetworkHelper.GetNearestBranch(Network.Branches, point, EvaluateTolerance);

            if (branch != null)
            {
                var coordinateOnBranch = GeometryHelper.GetNearestPointAtLine((ILineString)branch.Geometry,
                                                                              point.Coordinate, EvaluateTolerance);

                INetworkLocation locationOnBranch = new NetworkLocation
                {
                    Branch   = branch,
                    Geometry = new Point(coordinateOnBranch)
                };

                NetworkHelper.UpdateBranchFeatureOffsetFromGeometry(locationOnBranch);

                return((T)(object)Evaluate(locationOnBranch));
            }
            return(default(T));
        }
        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]);
        }
Beispiel #17
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));
        }
Beispiel #18
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);
        }
Beispiel #19
0
        public void GetTimeSeriesForCoverageOnCoordinate()
        {
            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 (int i = 1; i < 4; i++)
            {
                networkCoverage[new DateTime(2000, 1, i), networkLocation] = (double)i;
            }

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

            Assert.AreEqual(3, filteredCoverage.Components[0].Values.Count);
            Assert.AreEqual(1, filteredCoverage.Arguments.Count);
            Assert.AreEqual(filteredCoverage.Arguments[0].Values, networkCoverage.Time.Values);
        }
Beispiel #20
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));
        }
Beispiel #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)));
        }
Beispiel #22
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));
        }
Beispiel #23
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 = ExtrapolationType.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));
        }
Beispiel #24
0
        public void SplittingABranchShouldPreserveSetLocationValuePairsAndAdhereToInterpolationExtrapolationType()
        {
            var network = RouteHelperTest.GetSnakeNetwork(false, new Point(0, 0), new Point(0, 100));
                                                           
            var networkCoverage = new NetworkCoverage { Network = network };
            networkCoverage.Components[0].InterpolationType = InterpolationType.Linear;
            networkCoverage.Components[0].ExtrapolationType = ExtrapolationType.Constant;

            //add locations
            var networkLocation1 = new NetworkLocation(network.Branches[0], 20);
            var networkLocation2 = new NetworkLocation(network.Branches[0], 40);
            var networkLocation3 = new NetworkLocation(network.Branches[0], 60);
            var networkLocation4 = new NetworkLocation(network.Branches[0], 80);

            networkCoverage[networkLocation1] = 1.0d;
            networkCoverage[networkLocation2] = 11.0d;
            networkCoverage[networkLocation3] = 20.0d;
            networkCoverage[networkLocation4] = 40.0d;

            //merge the branches/remove the node
            NetworkHelper.SplitBranchAtNode(network.Branches[0], 50);

            // scenario post-split:
            //  1.0  11.0  20   40.0
            //   |    |     |   |
            // O-x----x->O--x---x->O
            // N1       N3         N2

            Assert.AreEqual(1.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 10))); // Extrapolate constant: 1.0
            Assert.AreEqual(6.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 30))); // interpolate linear: (11+1)/2 = 6.0
            Assert.AreEqual(11.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[0], 45)));// Extrapolate constant: 11.0
            Assert.AreEqual(20.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 5)));// Extrapolate constant: 20.0
            Assert.AreEqual(30.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 20)));// interpolate linear: (60+40)/2 = 30
            Assert.AreEqual(40.0, networkCoverage.Evaluate(new NetworkLocation(network.Branches[1], 40)));// Extrapolate constant: 40.0
        }
Beispiel #25
0
        public void ShouldNotBeAbleToAddTheSameLocationTwice()
        {
            var network = CreateNetwork();
            var networkCoverage = new NetworkCoverage("test", false) { Network = network };
            var l1 = new NetworkLocation(network.Branches[0], 10.0d);
            var l2 = new NetworkLocation(network.Branches[0], 10.0d);
            networkCoverage.Components[0][l1] = 1.0d;
            networkCoverage.Components[0][l2] = 3.0d;
            Assert.AreEqual(1, networkCoverage.Locations.Values.Count);


        }
Beispiel #26
0
        public void EvaluateWithNonExistingTimeValueTakesPreviousTimeValue()
        {
            // network 1 branch
            var network = RouteHelperTest.GetSnakeNetwork(false, 1);

            var networkCoverage = new NetworkCoverage("", true) {Network = network};
            
            var firstBranch = network.Branches[0];
            var loc1 = new NetworkLocation(firstBranch, 10);
            var loc2 = new NetworkLocation(firstBranch, 15);
            var loc3 = new NetworkLocation(firstBranch, 20);

            var time1 = new DateTime(2000, 1, 1);
            var time2 = new DateTime(2000, 1, 3);

            networkCoverage[time1, loc1] = 10.0;
            networkCoverage[time1, loc3] = 20.0;
            networkCoverage[time2, loc1] = 30.0;
            networkCoverage[time2, loc3] = 40.0;

            // evaluate for time takes the previous value
            // evaluate for location by linear interpolation
            Assert.AreEqual(15.0, networkCoverage.Evaluate(new DateTime(2000, 1, 2), loc2));
        }
Beispiel #27
0
        public void MergingABranchesRemovesDataOnAffectedBranches()
        {
            //L-shaped network
            var network = RouteHelperTest.GetSnakeNetwork(false,new Point(0, 0), new Point(0, 100),
                                                                  new Point(100, 100));
            var networkCoverage = new NetworkCoverage { Network = network };

            //add locations on both branches
            var networkLocation = new NetworkLocation(network.Branches[0], 50);
            var networkLocation2 = new NetworkLocation(network.Branches[1], 50);
            networkCoverage[networkLocation] = 1.0d;
            networkCoverage[networkLocation2] = 21.0d;

            //merge the branches/remove the node
            NetworkHelper.MergeNodeBranches(network.Nodes[1], network);

            //check the values got removed
            Assert.AreEqual(0, networkCoverage.Components[0].Values.Count);
        }
        public void SubstractComplexCoverages()
        {
            var network = 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 = network };
            
            var branchA = network.Branches[0];
            var branchB = network.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);

            //add a uniform coverage B to a 
            bedLevel.DefaultValue = 100.0;
            bedLevel[locationB1] = 100.0;
            bedLevel[locationB2] = 120.0;
            bedLevel[locationB3] = 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(10.0, waterDepth[locationB2]);
            Assert.AreEqual(60.0, waterDepth[locationB3]);
        }
Beispiel #29
0
 public bool Equals(NetworkLocation other)
 {
     return !ReferenceEquals(null, other);
 }
Beispiel #30
0
        public void GenerateSegmentPerLocationOrderModified()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage
            {
                Network = network,
                SegmentGenerationMethod = SegmentGenerationMethod.SegmentPerLocation
            };
            var valueAt10 = new NetworkLocation(network.Branches[0], 1.0);
            var valueAt90 = new NetworkLocation(network.Branches[0], 2.0);
            var valueAt50 = new NetworkLocation(network.Branches[0], 3.0);
            networkCoverage[valueAt10] = 0.1;
            networkCoverage[valueAt90] = 0.9;
            networkCoverage[valueAt50] = 0.5;

            // change offset and check result are identical to above test GenerateSegmentPerLocation
            valueAt50.Chainage = 50;
            valueAt90.Chainage = 90;
            valueAt10.Chainage = 10;

            Assert.AreEqual(3, networkCoverage.Segments.Values.Count);
            // [--10--------------50-------------------------------90---]
            // [----------][-----------------------][-------------------]
            // 0          30                       70                  100
            Assert.AreEqual(0, networkCoverage.Segments.Values[0].Chainage, 1.0e-6);
            Assert.AreEqual(30, networkCoverage.Segments.Values[0].EndChainage, 1.0e-6);
            Assert.AreEqual(30, networkCoverage.Segments.Values[1].Chainage, 1.0e-6);
            Assert.AreEqual(70, networkCoverage.Segments.Values[1].EndChainage, 1.0e-6);
            Assert.AreEqual(70, networkCoverage.Segments.Values[2].Chainage, 1.0e-6);
            Assert.AreEqual(100, networkCoverage.Segments.Values[2].EndChainage, 1.0e-6);
        }
Beispiel #31
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));
        }
Beispiel #32
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 };
     //IFeatureEditor featureEditor = new NetworkLocationEditor(new CoordinateConverter(mapControl.Map),
     //                                               networkCoverageLayer.LocationLayer, feature,
     //                                               new VectorStyle());
     //featureEditor.Start();
     //featureEditor.Stop(mapControl.SnapTool.SnapResult); // hack
     provider.Features.Add(feature);
     return feature;
 }
Beispiel #33
0
        public void ChangeChainageOfNeworkLocationShouldChangeNetworkLocationOrder()
        {
            var network = CreateNetwork();

            var networkCoverage = new NetworkCoverage
            {
                Network = network,
                SegmentGenerationMethod = SegmentGenerationMethod.SegmentPerLocation
            };
            var valueAt10 = new NetworkLocation(network.Branches[0], 10.0);
            var valueAt20 = new NetworkLocation(network.Branches[0], 20.0);
            var valueAt30 = new NetworkLocation(network.Branches[0], 30.0);
            var valueAt40 = new NetworkLocation(network.Branches[0], 40.0);
            networkCoverage[valueAt10] = 0.1;
            networkCoverage[valueAt20] = 0.2;
            networkCoverage[valueAt30] = 0.3;
            networkCoverage[valueAt40] = 0.4;
            valueAt20.Chainage = 35;
            Assert.AreEqual(valueAt10, networkCoverage.Locations.Values[0]);
            Assert.AreEqual(valueAt30, networkCoverage.Locations.Values[1]);
            Assert.AreEqual(valueAt20, networkCoverage.Locations.Values[2]);
            Assert.AreEqual(valueAt40, networkCoverage.Locations.Values[3]);
        }
Beispiel #34
0
        public void AllTimeValuesForFilteredCoverage()
        {
            var network = RouteHelperTest.GetSnakeNetwork(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);
        }
Beispiel #35
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);
        }
 public bool Equals(NetworkLocation other)
 {
     return(!ReferenceEquals(null, other));
 }
Beispiel #37
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));
        }
Beispiel #38
0
        public void GeometryForCoverage()
        {
            var network = RouteHelperTest.GetSnakeNetwork(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 }).ToString(), networkCoverage.Geometry.ToString());
        }
Beispiel #39
0
        public void GeometryForTimeFilteredCoverage()
        {
            var network = RouteHelperTest.GetSnakeNetwork(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);
        }
Beispiel #40
0
        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,
                Offset = 90,
                Name = "source"
            };
            var networkLocation2 = new NetworkLocation
            {
                Geometry = new Point(new Coordinate(0, 40)),
                Branch = branch1,
                Offset = 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].Offset);
            Assert.AreEqual(40, segments[0].EndOffset);
        }