예제 #1
0
        [Test] // testing the Initialise method
        public void MapValues()
        {
            ElementSet gridElementSet       = new ElementSet("RegularGrid", "RegularGrid", ElementType.Polygon);
            ElementSet fourPointsElementSet = new ElementSet("4 points", "4P", ElementType.Point);

            Coordinate v_0_20  = new Coordinate(0, 20, 0);
            Coordinate v_0_10  = new Coordinate(0, 10, 0);
            Coordinate v_0_0   = new Coordinate(0, 0, 0);
            Coordinate v_5_15  = new Coordinate(5, 15, 0);
            Coordinate v_10_20 = new Coordinate(10, 20, 0);
            Coordinate v_10_15 = new Coordinate(10, 15, 0);
            Coordinate v_10_10 = new Coordinate(10, 10, 0);
            Coordinate v_10_0  = new Coordinate(10, 0, 0);
            Coordinate v_15_15 = new Coordinate(15, 15, 0);
            Coordinate v_15_5  = new Coordinate(15, 5, 0);
            Coordinate v_20_20 = new Coordinate(20, 20, 0);
            Coordinate v_20_10 = new Coordinate(20, 10, 0);

            Element square1 = new Element("square1");
            Element square2 = new Element("square2");
            Element square3 = new Element("square3");

            square1.AddVertex(v_0_20);
            square1.AddVertex(v_0_10);
            square1.AddVertex(v_10_10);
            square1.AddVertex(v_10_20);

            square2.AddVertex(v_10_20);
            square2.AddVertex(v_10_10);
            square2.AddVertex(v_20_10);
            square2.AddVertex(v_20_20);

            square3.AddVertex(v_0_10);
            square3.AddVertex(v_0_0);
            square3.AddVertex(v_10_0);
            square3.AddVertex(v_10_10);

            gridElementSet.AddElement(square1);
            gridElementSet.AddElement(square2);
            gridElementSet.AddElement(square3);

            Element point_5_15  = new Element("point 5, 15");
            Element point_10_15 = new Element("point 10, 15");
            Element point_15_15 = new Element("point 15, 15");
            Element point_15_5  = new Element("point 15, 5");

            point_5_15.AddVertex(v_5_15);
            point_10_15.AddVertex(v_10_15);
            point_15_15.AddVertex(v_15_15);
            point_15_5.AddVertex(v_15_5);

            fourPointsElementSet.AddElement(point_5_15);
            fourPointsElementSet.AddElement(point_10_15);
            fourPointsElementSet.AddElement(point_15_15);
            fourPointsElementSet.AddElement(point_15_5);

            ElementMapper elementMapper = new ElementMapper();

            // point to polygon

            IIdentifiable[] methods = SpatialAdaptedOutputFactory.GetAvailableMethods(fourPointsElementSet.ElementType, gridElementSet.ElementType);
            elementMapper.Initialise(methods[0], fourPointsElementSet, gridElementSet);
            IList values = new List <double>();

            values.Add(0d);
            values.Add(10d);
            values.Add(20d);
            values.Add(30d);
            ITimeSpaceValueSet fourPointsScalarSet = new ValueSet(new List <IList> {
                values
            });

            ITimeSpaceValueSet gridScalarSet = elementMapper.MapValues(fourPointsScalarSet);
            IList elementValuesForTime       = gridScalarSet.GetElementValuesForTime(0);

            Assert.AreEqual(5, elementValuesForTime[0]);
            Assert.AreEqual(20, elementValuesForTime[1]);
            Assert.AreEqual(0, elementValuesForTime[2]);

            // polygon to point
            methods = SpatialAdaptedOutputFactory.GetAvailableMethods(gridElementSet.ElementType, fourPointsElementSet.ElementType);
            elementMapper.Initialise(methods[0], gridElementSet, fourPointsElementSet);
            fourPointsScalarSet  = elementMapper.MapValues(gridScalarSet);
            elementValuesForTime = fourPointsScalarSet.GetElementValuesForTime(0);
            Assert.AreEqual(5, elementValuesForTime[0]);
            Assert.AreEqual(5, elementValuesForTime[1]);
            Assert.AreEqual(20, elementValuesForTime[2]);
            Assert.AreEqual(0, elementValuesForTime[3]);
        }