public override object Evaluate(ICoordinate coordinate) { var featuresInRange = GeometryHelper.GetFeaturesInRange(coordinate, features.Cast <IFeature>(), EvaluateTolerance); return(featuresInRange.Select(feature => (!IsTimeDependent) ? this[feature] : this[Time.MinValue, feature])); }
public void BranchSegmentBoundaryAsFunctionArgument_TimeDependent() { // Test with 2 arguments. A FeatureVariable DateTime as timestep // Add values to the store and test the retieved values object defaultValue = default(float); FeatureCoverage waterLevelCoverage = new FeatureCoverage("WaterLevel"); Variable <DateTime> timeArgument = new Variable <DateTime>("time"); waterLevelCoverage.Arguments.Add(timeArgument); Variable <SimpleFeature> boundariesFunctionArgument = new Variable <SimpleFeature>("cell"); waterLevelCoverage.Arguments.Add(boundariesFunctionArgument); waterLevelCoverage.Components.Add(new Variable <float>("depth")); waterLevelCoverage.Features = new EventedList <IFeature>(boundaries.Cast <IFeature>()); waterLevelCoverage.FeatureVariable.SetValues(boundaries); // no data added; we expect 0 rows in the table IList <float> values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(0, values.Count); // Add 1 value for a boundary. The store will add rows with default values for all // boundaries in the network.BranchSegmentBoundaries collection and set // the value 1.0 to the explicit referenced boundary11. waterLevelCoverage[new DateTime(2000, 1, 1, 0, 0, 0), boundary11] = 1.0f; values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(6, values.Count); Assert.AreEqual(1.0, values[0]); Assert.AreEqual(defaultValue, values[1]); Assert.AreEqual(defaultValue, values[2]); Assert.AreEqual(defaultValue, values[3]); Assert.AreEqual(defaultValue, values[4]); Assert.AreEqual(defaultValue, values[5]); // Add a new timestep and set lavel for all boundaries for this step to 2.0 waterLevelCoverage.SetValues(new[] { 2.0f }, new VariableValueFilter <DateTime>(timeArgument, new DateTime(2000, 2, 1, 0, 0, 0))); values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(12, values.Count); // Overwrite the waterlevels of the first timestep to 1.0; there are no default values in the // internal table // content should be now: // t=2000, 1, 1 1.0 1.0 1.0 1.0 1.0 1.0 // t=2000, 2, 1 2.0 2.0 2.0 2.0 2.0 2.0 waterLevelCoverage.SetValues(new[] { 1.0f }, new VariableValueFilter <DateTime>(timeArgument, new DateTime(2000, 1, 1, 0, 0, 0))); values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(12, values.Count); // Overwrite the waterlevels of the 2nd timestep. // content should be now: // t=2000, 1, 1 1.0 1.0 1.0 1.0 1.0 1.0 // t=2000, 2, 1 1.0 2.0 3.0 4.0 5.0 6.0 waterLevelCoverage.SetValues(new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }, new VariableValueFilter <DateTime>(timeArgument, new DateTime(2000, 2, 1, 0, 0, 0))); values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(12, values.Count); // Add a 3rd timestep to the function. // content should be now: // t=2000, 1, 1 1.0 1.0 1.0 1.0 1.0 1.0 // t=2000, 2, 1 1.0 2.0 3.0 4.0 5.0 6.0 // t=2000, 3, 1 11.0 12.0 13.0 14.0 15.0 16.0 waterLevelCoverage.SetValues(new[] { 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f }, new VariableValueFilter <DateTime>(timeArgument, new DateTime(2000, 3, 1, 0, 0, 0))); values = waterLevelCoverage.GetValues <float>(); Assert.AreEqual(18, values.Count); // Ask all timesteps for boundary 21 values = waterLevelCoverage.GetValues <float>(new VariableValueFilter <SimpleFeature>(boundariesFunctionArgument, boundary21)); Assert.AreEqual(3, values.Count); Assert.AreEqual(1.0, values[0]); Assert.AreEqual(4.0, values[1]); Assert.AreEqual(14.0, values[2]); // Use 2 filters to get values; multiple filters work as a logical AND; only 1 values expected values = waterLevelCoverage.GetValues <float>(new VariableValueFilter <SimpleFeature>(boundariesFunctionArgument, boundary21), new VariableValueFilter <DateTime>(timeArgument, new DateTime(2000, 2, 1, 0, 0, 0))); Assert.AreEqual(1, values.Count); Assert.AreEqual(4.0, values[0]); }