Пример #1
0
        public void CompositeAdapterWeightedAverage_ShouldBeEqual_WhenTheSameWeights()
        {
            // Two instances are created below but in different order
            // but with the same weights
            var weightedAverage1 = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0)
            });
            // below the order is switched between the above first and second,
            // though their weights are the same
            var weightedAverage2 = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0)
            });

            Assert.AreEqual(
                weightedAverage1
                ,
                weightedAverage2
                );
            Assert.AreEqual(
                weightedAverage1.GetHashCode()
                ,
                weightedAverage2.GetHashCode()
                );
        }
    public void SetUp() {
        weightFactory = CrsTransformationAdapterWeightFactory.Create();

        crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();

        crsTransformationAdapterLeafImplementations = new List<ICrsTransformationAdapter>{
            new CrsTransformationAdapterDotSpatial(),
            new CrsTransformationAdapterProjNet(),
            new CrsTransformationAdapterMightyLittleGeodesy()
        };

        crsTransformationAdapterCompositeImplementations = new List<ICrsTransformationAdapter>{
            crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(),
            crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(),
            crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(),
            crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List<CrsTransformationAdapterWeight>{
                weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 51.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 52.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 53.0)
            })
        };
        crsTransformationAdapterImplementations = new List<ICrsTransformationAdapter>();
        crsTransformationAdapterImplementations.AddRange(crsTransformationAdapterLeafImplementations);
        crsTransformationAdapterImplementations.AddRange(crsTransformationAdapterCompositeImplementations);
    }
 public void TestCompositeWeightedAverage()
 {
     VerifyExpectedEnumWhenNotRepresentingThirdPartLibrary(
         crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> {
         weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0),
         weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 2.0),
         weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 3.0)
     }),
         CrsTransformationAdapteeType.COMPOSITE_WEIGHTED_AVERAGE
         );
 }
        public void TransformToCoordinate_ShouldReturnWeightedAverageResult_WhenUsingWeightedAverageCompositeAdapter()
        {
            double[] weights    = { 1, 2, 4, 5, 9 };
            double   totWeights = 0;
            double   totLats    = 0;
            double   totLons    = 0;

            for (int i = 0; i < weights.Length; i++)
            {
                double weight = weights[i];
                totWeights += weight;
                CrsCoordinate coordinate = outputCoordinates[i];
                totLats += weight * coordinate.YNorthingLatitude;
                totLons += weight * coordinate.XEastingLongitude;
            }
            double        weightedLat             = totLats / totWeights;
            double        weightedLon             = totLons / totWeights;
            CrsCoordinate expectedWeightedAverage = CrsCoordinateFactory.CreateFromLatitudeLongitude(weightedLat, weightedLon);

            List <CrsTransformationAdapterWeight> weightedAdapters = new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(leafAdapterImplementation_1, weights[0]),
                weightFactory.CreateFromInstance(leafAdapterImplementation_2, weights[1]),
                weightFactory.CreateFromInstance(leafAdapterImplementation_3, weights[2]),
                weightFactory.CreateFromInstance(leafAdapterImplementation_4, weights[3]),
                weightFactory.CreateFromInstance(leafAdapterImplementation_5, weights[4])
            };

            CrsTransformationAdapterComposite weightedAverageCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(weightedAdapters);
            CrsCoordinate result = weightedAverageCompositeAdapter.TransformToCoordinate(inputCoordinateSweref99, EpsgNumber.WORLD__WGS_84__4326);

            Assert.IsNotNull(result);

            Assert.AreEqual(expectedWeightedAverage.YNorthingLatitude, result.YNorthingLatitude, SMALL_DELTA_VALUE_FOR_COMPARISONS);
            Assert.AreEqual(expectedWeightedAverage.XEastingLongitude, result.XEastingLongitude, SMALL_DELTA_VALUE_FOR_COMPARISONS);

            AssertCompositeResultHasLeafSubResults(
                weightedAverageCompositeAdapter,
                allLeafAdapters.Count
                );
        }
Пример #5
0
        public void SetUp()
        {
            weightFactory = CrsTransformationAdapterWeightFactory.Create();

            // Leaf adapters:
            dotSpatial          = new CrsTransformationAdapterDotSpatial();
            mightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy();
            // currently there are no configurations possibilities for the above two leafs
            // but for the below leaf it is possible to create instances with
            // different configurations
            projNet = new CrsTransformationAdapterProjNet();
            ProjNetWithDifferentConfiguration = new CrsTransformationAdapterProjNet(new SridReader("somepath.csv"));

            // Composite adapters:
            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(
                new List <ICrsTransformationAdapter> {
                dotSpatial, mightyLittleGeodesy, projNet
            }
                );
            // Note that below list parameter is the same as the above but with the list items in reversed order
            crsTransformationAdapterCompositeFactoryWithLeafsInReversedOrder = CrsTransformationAdapterCompositeFactory.Create(
                new List <ICrsTransformationAdapter> {
                projNet, mightyLittleGeodesy, dotSpatial
            }
                );
            crsTransformationAdapterCompositeFactoryWithOneLeafDifferentlyConfigured = CrsTransformationAdapterCompositeFactory.Create(
                new List <ICrsTransformationAdapter> {
                dotSpatial, mightyLittleGeodesy, ProjNetWithDifferentConfiguration
            }
                );

            average         = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();
            median          = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();
            firstSuccess    = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess();
            weightedAverage = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(dotSpatial, 1.0),
                weightFactory.CreateFromInstance(projNet, 2.0),
                weightFactory.CreateFromInstance(mightyLittleGeodesy, 3.0)
            });
        }
Пример #6
0
 public void CompositeFactory_ShouldThrowException_WhenDuplicateInListAndCreatingCompositeWeightedAverage() {
     ArgumentException exception = Assert.Throws<ArgumentException>(() => {
         crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(listOfWeightsWithOneDuplicated);
     });        
 }