private void crsTransformationAdapterSubtypesCode()
        {
            // The below used code is implemented with F#
            // which normally uses explicit interfaces.
            // The F# code requires some additional coding
            // to make the implicit interfaces work as below
            // i.e. the methods can be invoked not only with
            // an interface typed object but also with
            // an object typed with some subtype (class)

            var c = new CrsTransformationAdapterDotSpatial();
            CrsTransformationAdapterBase     b = c;
            CrsTransformationAdapterBaseLeaf l = c;

            c.Transform(null, 123);
            c.TransformToCoordinate(null, 123);
            b.Transform(null, 123);
            b.TransformToCoordinate(null, 123);
            l.Transform(null, 123);
            l.TransformToCoordinate(null, 123);

            // Previously (before the git commit when this comment was added)
            // the above methods could not be compiled i.e.
            // the Transform methods were only available
            // when assigning the subtypes to the interface
            // i.e. the code below worked before but not
            // the transform method calls above before these lines with comments
            ICrsTransformationAdapter i = c;

            i.Transform(null, 123);
            i.TransformToCoordinate(null, 123);
        }
Ejemplo n.º 2
0
    public void SetUp() {
        weightFactory = CrsTransformationAdapterWeightFactory.Create();
        crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();

        var dotSpatial = new CrsTransformationAdapterDotSpatial();
        var ProjNet = new CrsTransformationAdapterProjNet();
        var mightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy();
        listOfAdaptersWithOneDuplicated = new List<ICrsTransformationAdapter>{
            dotSpatial,
            ProjNet,
            mightyLittleGeodesy,
            // Duplicate added below !
            new CrsTransformationAdapterDotSpatial()
        };

        listOfTwoAdaptersWithoutDotSpatial = new List<ICrsTransformationAdapter>{
            ProjNet,
            mightyLittleGeodesy
        };

        listOfWeightsWithOneDuplicated = new List<CrsTransformationAdapterWeight>{
            weightFactory.CreateFromInstance(dotSpatial, 1.0),
            weightFactory.CreateFromInstance(ProjNet, 2.0),
            weightFactory.CreateFromInstance(mightyLittleGeodesy, 3.0),
            // Duplicate added below !
            // (Duplicate regarding the class, the weight value is not relevant)
            weightFactory.CreateFromInstance(dotSpatial, 4.0)
        };

        CrsTransformationAdapterLeafFactory leafFactoryOnlyCreatingDotSpatialImplementationAsDefault = CrsTransformationAdapterLeafFactory.Create(new List<ICrsTransformationAdapter>{dotSpatial});
        compositeFactoryConfiguredWithLeafFactoryOnlyCreatingDotSpatialImplementationAsDefault = CrsTransformationAdapterCompositeFactory.Create(leafFactoryOnlyCreatingDotSpatialImplementationAsDefault);
    }
        private void crsTransformationAdapterCode()
        {
            // The three (currently) 'Leaf' adapters:
            crsTransformationAdapter = new CrsTransformationAdapterDotSpatial();
            crsTransformationAdapter = new CrsTransformationAdapterProjNet();
            crsTransformationAdapter = new CrsTransformationAdapterMightyLittleGeodesy();

            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            // Three factory methods for 'composite' adapters
            // (trying to create them all with reflection, and thus no parameter)
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess();

            // a list used as parameter for the below 'Composite' adapters:
            IList <ICrsTransformationAdapter> crsTransformationAdapters = new List <ICrsTransformationAdapter> {
                crsTransformationAdapter
            };

            // Three factory methods for 'composite' adapters
            // (with the specified leaf adapters in a list parameter)
            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(crsTransformationAdapters);
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess();

            // leaf adapters (used below for creating a composite with weighted average):
            var crsTransformationAdapterDotSpatial = new CrsTransformationAdapterDotSpatial();
            var crsTransformationAdapterProjNet    = new CrsTransformationAdapterProjNet();
            // One of the above are used below, with the instance,
            // and one of them is instead below using the class name created here:
            string fullClassNameForImplementation = crsTransformationAdapterDotSpatial.GetType().FullName;


            // Now creating the composite with weighted average, using the above two
            // leaf adapters, using two different create methods:
            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(new List <CrsTransformationAdapterWeight> {
                CrsTransformationAdapterWeightFactory.Create().CreateFromInstance(crsTransformationAdapterProjNet, 1.0),
                CrsTransformationAdapterWeightFactory.Create().CreateFromStringWithFullClassNameForImplementation(fullClassNameForImplementation, 2.0)
            });

            // public properties
            crsTransformationAdapteeType = crsTransformationAdapter.AdapteeType;
            isComposite = crsTransformationAdapter.IsComposite;
            longNameOfImplementation  = crsTransformationAdapter.LongNameOfImplementation;
            shortNameOfImplementation = crsTransformationAdapter.ShortNameOfImplementation;

            // public methods:
            transformationAdapterChildren = crsTransformationAdapter.TransformationAdapterChildren;

            crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, crsIdentifier);
            crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, epsgNumber);
            crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, crsCode);

            crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, crsIdentifier);
            crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, epsgNumber);
            crsCoordinate = crsTransformationAdapter.TransformToCoordinate(crsCoordinate, crsCode);
        }
Ejemplo n.º 4
0
        public void LeafAdapters_ShouldBeEqual_WhenTheSameTypeAndConfiguration()
        {
            var dotSpatial1 = new CrsTransformationAdapterDotSpatial();
            var dotSpatial2 = new CrsTransformationAdapterDotSpatial();

            Assert.AreEqual(
                dotSpatial1,
                dotSpatial2
                );
            Assert.AreEqual(
                dotSpatial1.GetHashCode(),
                dotSpatial2.GetHashCode()
                );

            Assert.AreEqual(
                dotSpatial, // created in the Setup method
                dotSpatial1
                );
            Assert.AreEqual(
                dotSpatial.GetHashCode(),
                dotSpatial1.GetHashCode()
                );

            var mightyLittleGeodesy2 = new CrsTransformationAdapterMightyLittleGeodesy();

            Assert.AreEqual(
                mightyLittleGeodesy, // created in the Setup method
                mightyLittleGeodesy2
                );
            Assert.AreEqual(
                mightyLittleGeodesy.GetHashCode(),
                mightyLittleGeodesy2.GetHashCode()
                );

            var ProjNet2 = new CrsTransformationAdapterProjNet();

            Assert.AreEqual(
                projNet, // created in the Setup method
                ProjNet2
                );
            Assert.AreEqual(
                projNet.GetHashCode(),
                ProjNet2.GetHashCode()
                );
        }
        public void CalculateAggregatedResult_ShouldThrowException_WhenResultIsBasedOnLeafsNotBeingPartOfTheWeightedAverageAdapter()
        {
            CrsCoordinate coordinate = CrsCoordinateFactory.LatLon(59, 18);
            List <CrsTransformationResult> emptyListOfTransformationResults = new List <CrsTransformationResult>();

            ICrsTransformationAdapter             leafMightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy();
            List <CrsTransformationAdapterWeight> leafWeightsForOnlyMightyLittleGeodesy = new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(
                    leafMightyLittleGeodesy,
                    1
                    )
            };
            // The below type ICompositeStrategy is "internal" in the F# project but still available from here
            //  because of "InternalsVisibleTo" configuration in the .fsproj file.
            ICompositeStrategy compositeStrategyWeightedAverageForOnlyMightyLittleGeodesy = CompositeStrategyWeightedAverage._CreateCompositeStrategyWeightedAverage(leafWeightsForOnlyMightyLittleGeodesy);
            // The above composite was created with only one leaf in the list

            ICrsTransformationAdapter leafDotSpatial = new CrsTransformationAdapterDotSpatial();
            CrsTransformationResult   crsTransformationResultProblem = new CrsTransformationResult(
                coordinate,     // inputCoordinate irrelevant in this test so okay to use the same as the output
                coordinate,     // outputCoordinate
                null,           // exception
                true,           // isSuccess
                leafDotSpatial, // crsTransformationAdapterResultSource,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(emptyListOfTransformationResults)
                );

            // The composite strategy used below was created with only MightyLittleGeodesy,
            // and therefore if the result (as below) would be based on "DotSpatial"
            // then there is a bug somewhere i.e. an exception is thrown
            // which is tested below
            InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() => {
                compositeStrategyWeightedAverageForOnlyMightyLittleGeodesy._CalculateAggregatedResult(
                    new List <CrsTransformationResult> {
                    crsTransformationResultProblem
                },                            // allResults
                    coordinate,
                    coordinate.CrsIdentifier, //  crsIdentifier for OutputCoordinateSystem
                    leafDotSpatial            // SHOULD CAUSE EXCEPTION !
                    );
            },
                                                                                            "The result adapter was not part of the weighted average composite adapter"
                                                                                            );
        }
Ejemplo n.º 6
0
    public void SetUpBase() {
        // The setup code below creates four coordinates 
        // representing results from four implementations.
        double lat1 = 59.330231;
        double lat2 = 59.330232;
        double lat3 = 59.330233;
        double lat4 = 59.330239;
        double latMean = (lat2 + lat3 ) / 2;
        double latAverage = (lat1 + lat2 + lat3 + lat4) / 4;
        expectedLatDiffMax = lat4-lat1;
        double lon1 = 18.059192;
        double lon2 = 18.059193;
        double lon3 = 18.059194;
        double lon4 = 18.059198;
        double lonMean = (lon2 + lon3 ) / 2;
        double lonAverage = (lon1 + lon2 + lon3 + lon4) / 4;
        expectedLonDiffMax = lon4-lon1;
        expectedCoordinateMean = CrsCoordinateFactory.LatLon(latMean, lonMean);
        expectedCoordinateAverage = CrsCoordinateFactory.LatLon(latAverage, lonAverage);

        CrsCoordinate outputCoordinate1 = CrsCoordinateFactory.LatLon(lat1, lon1);
        CrsCoordinate outputCoordinate2 = CrsCoordinateFactory.LatLon(lat2, lon2);
        CrsCoordinate outputCoordinate3 = CrsCoordinateFactory.LatLon(lat3, lon3);
        CrsCoordinate outputCoordinate4 = CrsCoordinateFactory.LatLon(lat4, lon4);

        var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
        compositeAdapterForResultTest = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();
        inputCoordinateNotUsedInStatisticsTest = CrsCoordinateFactory.LatLon(0.0, 0.0); // input, not used here in this test
        outputCoordinateNotUsedInStatisticsTest = inputCoordinateNotUsedInStatisticsTest;

        ICrsTransformationAdapter leafAdapterForResultTest = new CrsTransformationAdapterDotSpatial();
        // Can use the same above adapter for all parts below. Not used much except that the object must be some leaf
        
        listOfSubresultsForStatisticsTest = new List<CrsTransformationResult>{
            CreateCrsTransformationResult(outputCoordinate1, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest),
            CreateCrsTransformationResult(outputCoordinate2, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest),
            CreateCrsTransformationResult(outputCoordinate3, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest),
            CreateCrsTransformationResult(outputCoordinate4, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest)
        };
    }
        public void TransformToCoordinateWithComposite_ShouldAggregateAsExpected_WhenTheLeafsAreAlsoCompositesAndNestedAtManyLevels()
        {
            // The method first creates two composites (average and success)
            // and then uses those two composites as leafs for a
            // weighted average composite, which in
            // turn is then used as a leaf within
            // the final median composite (together with a "normal leaf" i.e. DotSpatial implementation)
            var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            var compositeAverage         = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();
            var compositeFirstSuccess    = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess();
            var weightsForCompositeLeafs = new List <CrsTransformationAdapterWeight> {
                CrsTransformationAdapterWeightFactory.Create().CreateFromInstance(
                    compositeAverage,
                    1.0 // weight
                    ),
                CrsTransformationAdapterWeightFactory.Create().CreateFromInstance(
                    compositeFirstSuccess,
                    2.0 // weight
                    )
            };
            CrsTransformationAdapterComposite weightedCompositeAdapterWithOtherCompositesAsLeafs = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(
                weightsForCompositeLeafs
                );
            var normalLeafDotSpatialAdapter = new CrsTransformationAdapterDotSpatial();
            var adaptersForMedian           = new List <ICrsTransformationAdapter> {
                weightedCompositeAdapterWithOtherCompositesAsLeafs,
                normalLeafDotSpatialAdapter
            };
            var compositeMedian = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(
                adaptersForMedian
                );
            // Now the "complex" composite (nested at two lelvels, with composites as leafs)
            // has been conctructed.
            // Now create a coordinate:
            var inputCoordinate = CrsCoordinateFactory.LatLon(60.0, 20.0);
            // Now use the above "complex" composite to transform the coordinate:
            var resultMedianWithNestedComposite = compositeMedian.Transform(
                inputCoordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006
                );

            Assert.IsTrue(resultMedianWithNestedComposite.isSuccess);
            var coordinateResultMedianWithNestedComposite = resultMedianWithNestedComposite.OutputCoordinate;

            // Now use some leaf (not using DotSpatial as above)
            // to also make the same Transform, to use it
            // in the result comparison
            var mightyLittleGeodesyAdapter = new CrsTransformationAdapterMightyLittleGeodesy();
            var coordinateResultMightyLittleGeodesyAdapter = mightyLittleGeodesyAdapter.TransformToCoordinate(
                inputCoordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006
                );
            // The difference should not be very large, and the delta
            // value below is one decimeter
            const double deltaValueForAssertions = 0.1;

            Assert.AreEqual(
                coordinateResultMightyLittleGeodesyAdapter.X,
                coordinateResultMedianWithNestedComposite.X,
                deltaValueForAssertions
                );
            Assert.AreEqual(
                coordinateResultMightyLittleGeodesyAdapter.Y,
                coordinateResultMedianWithNestedComposite.Y,
                deltaValueForAssertions
                );

            var children = resultMedianWithNestedComposite.TransformationResultChildren;

            // one child is the weightedComposite and the other dotSpatial
            Assert.AreEqual(2, children.Count);
            // the assumed order in the two rows below is a little bit fragile
            CrsTransformationResult resultWeightedComposite = children[0];
            CrsTransformationResult resultDotSpatial        = children[1];

            Assert.AreEqual(weightedCompositeAdapterWithOtherCompositesAsLeafs, resultWeightedComposite.CrsTransformationAdapterResultSource);
            Assert.AreEqual(normalLeafDotSpatialAdapter, resultDotSpatial.CrsTransformationAdapterResultSource);
            // the weighted composite has two children (average and firstSuccess)
            var childrenForWeightedComposite = resultWeightedComposite.TransformationResultChildren;

            Assert.AreEqual(2, childrenForWeightedComposite.Count);
            // the leaf should not have any child results
            Assert.AreEqual(0, resultDotSpatial.TransformationResultChildren.Count);

            // the assumed order in the two rows below is a little bit fragile
            CrsTransformationResult resultAverage      = childrenForWeightedComposite[0];
            CrsTransformationResult resultFirstSuccess = childrenForWeightedComposite[1];

            // Average should use all normal leafs
            Assert.AreEqual(EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS, resultAverage.TransformationResultChildren.Count);
            // First success should only have one child result i.e. the first should have succeeded
            Assert.AreEqual(1, resultFirstSuccess.TransformationResultChildren.Count);
        }