public void SetUpBase()
        {
            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();

            adapterDotSpatial          = new CrsTransformationAdapterDotSpatial();
            adapterProjNet             = new CrsTransformationAdapterProjNet();
            adapterMightyLittleGeodesy = new CrsTransformationAdapterMightyLittleGeodesy();

            allAdapters = new List <ICrsTransformationAdapter> {
                // Regarding the order of the items in the list below:
                // DotSpatial should be the first since it is assumed in the test by the subclass CompositeStrategyFirstSuccessTest
                adapterDotSpatial,
                adapterProjNet,
                adapterMightyLittleGeodesy
            };

            wgs84coordinate = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(wgs84Lat, wgs84Lon, EpsgNumber.WORLD__WGS_84__4326);

            resultCoordinateDotSpatial          = adapterDotSpatial.TransformToCoordinate(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);
            resultCoordinateProjNet             = adapterProjNet.TransformToCoordinate(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);
            resultCoordinateMightyLittleGeodesy = adapterMightyLittleGeodesy.TransformToCoordinate(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);
            allCoordinateResultsForTheDifferentImplementations = new List <CrsCoordinate> {
                resultCoordinateDotSpatial,
                resultCoordinateMightyLittleGeodesy,
                resultCoordinateProjNet
            };
        }
    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);
    }
Exemple #3
0
        public void method()
        {
            Console.WriteLine("SmallCSharpeExample starts");
            int epsgWgs84  = 4326;
            int epsgSweRef = 3006;
            // alternative to the above two hardcodings: use the library "Programmerare.CrsTransformations.Constants"
            // and constants EpsgNumber.WORLD__WGS_84__4326 and EpsgNumber.SWEDEN__SWEREF99_TM__3006
            // from the class Programmerare.CrsConstants.ConstantsByAreaNameNumber.v9_7.EpsgNumber

            CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory.LatLon(59.330231, 18.059196, epsgWgs84);

            ICrsTransformationAdapter crsTransformationAdapter = CrsTransformationAdapterCompositeFactory.Create().CreateCrsTransformationMedian();
            // If the NuGet configuration includes all (currently three) adapter implementations, then the
            // above created 'Composite' implementation will below use all three 'leaf' implementations
            // and return a coordinate with a median longitude and a median latitude
            CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter.Transform(centralStockholmWgs84, epsgSweRef);

            if (centralStockholmResultSweRef.IsSuccess)
            {
                Console.WriteLine(centralStockholmResultSweRef.OutputCoordinate);
                // Console output from the above code row:
                // CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
            }
            Console.WriteLine("SmallCSharpeExample ends");
            Console.ReadLine();
        }
Exemple #4
0
        public void CompositeAdapters_ShouldNotBeEqual_WhenDifferentNumberOfLeafs()
        {
            // Composite adapter factory with only two leafs:
            var crsTransformationAdapterCompositeFactoryWithTwoLeafs = CrsTransformationAdapterCompositeFactory.Create(
                new List <ICrsTransformationAdapter> {
                dotSpatial, projNet
            }
                );

            var crsTransformationAdapterCompositeFactoryWithThreeLeafs = crsTransformationAdapterCompositeFactory;

            // Average created with two differenf factories,
            // one with three leafs and one with two leafs
            Assert.AreNotEqual(
                crsTransformationAdapterCompositeFactoryWithThreeLeafs.CreateCrsTransformationAverage(),
                crsTransformationAdapterCompositeFactoryWithTwoLeafs.CreateCrsTransformationAverage()
                );

            // Median created with two differenf factories,
            // one with three leafs and one with two leafs
            Assert.AreNotEqual(
                crsTransformationAdapterCompositeFactoryWithThreeLeafs.CreateCrsTransformationMedian(),
                crsTransformationAdapterCompositeFactoryWithTwoLeafs.CreateCrsTransformationMedian()
                );

            // FirstSuccess created with two differenf factories,
            // one with three leafs and one with two leafs
            Assert.AreNotEqual(
                crsTransformationAdapterCompositeFactoryWithThreeLeafs.CreateCrsTransformationFirstSuccess(),
                crsTransformationAdapterCompositeFactoryWithTwoLeafs.CreateCrsTransformationFirstSuccess()
                );
        }
Exemple #5
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);
        }
        public void AdapterCompositeFactory_ShouldNotFail_WhenNotAllAdaptersAreAvailable()
        {
            var factory = CrsTransformationAdapterCompositeFactory.Create();
            var median  = factory.CreateCrsTransformationMedian();
            var coord   = CrsCoordinateFactory.LatLon(60.0, 20.0);
            var result  = median.Transform(coord, 3006);

            Assert.IsTrue(result.IsSuccess);
            IList <CrsTransformationResult> childrenResults = result.TransformationResultChildren;

            Assert.AreEqual(
                NUMBER_OF_ADAPTERS_WHICH_ARE_DEPENDENCIES_FROM_THIS_PROJECT,
                childrenResults.Count
                );
            var outputCoord = result.OutputCoordinate;
        }
Exemple #8
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)
        };
    }
Exemple #9
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)
            });
        }
        public void IsReliableTest()
        {
            var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            CrsTransformationAdapterComposite crsTransformationComposite = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();
            var children = crsTransformationComposite.TransformationAdapterChildren;

            Assert.AreEqual(3, children.Count);

            CrsCoordinate           wgs84coordinateInSweden            = CrsCoordinateFactory.LatLon(59.31, 18.04);
            CrsTransformationResult resultWhenTransformingToSwedishCRS = crsTransformationComposite.Transform(wgs84coordinateInSweden, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.IsNotNull(resultWhenTransformingToSwedishCRS);
            Assert.IsTrue(resultWhenTransformingToSwedishCRS.IsSuccess);
            CrsTransformationResultStatistic crsTransformationResultStatistic = resultWhenTransformingToSwedishCRS.CrsTransformationResultStatistic;

            Assert.IsNotNull(crsTransformationResultStatistic);
            Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable);

            int actualNumberOfResults = crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults;

            Assert.AreEqual(
                EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS,
                actualNumberOfResults
                );
            double actualMaxDiffXLongitude = crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude;
            double actualMaxDiffYLatitude  = crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude;
            double actualMaxDiffXorY       = Math.Max(actualMaxDiffXLongitude, actualMaxDiffYLatitude);

            Assert.That(actualMaxDiffXorY, Is.LessThan(0.01));

            Assert.IsTrue(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults, actualMaxDiffXorY));

            // assertFalse below since trying to require one more result than available
            Assert.IsFalse(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults + 1, actualMaxDiffXorY));

            // assertFalse below since trying to require too small maxdiff
            Assert.IsFalse(resultWhenTransformingToSwedishCRS.IsReliable(actualNumberOfResults, actualMaxDiffXorY - 0.00000000001));
        }
        public void SetUp()
        {
            weightFactory = CrsTransformationAdapterWeightFactory.Create();

            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            double[] outputLatitudes =
            {
                59.1,
                59.2,
                59.3,
                59.4,
                59.6,
            };
            expectedMedianLatitude  = 59.3;
            expectedAverageLatitude = 59.32;

            double[] outputLongitudes =
            {
                18.2,
                18.3,
                18.4,
                18.8,
                18.9
            };
            expectedMedianLongitude  = 18.4;
            expectedAverageLongitude = 18.52;

            outputCoordinateWgs84ForImplementation_1 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[0], outputLongitudes[3]);
            outputCoordinateWgs84ForImplementation_2 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[2], outputLongitudes[1]);
            outputCoordinateWgs84ForImplementation_3 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[4], outputLongitudes[4]);
            outputCoordinateWgs84ForImplementation_4 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[1], outputLongitudes[0]);
            outputCoordinateWgs84ForImplementation_5 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[3], outputLongitudes[2]);
            outputCoordinates = new List <CrsCoordinate> {
                outputCoordinateWgs84ForImplementation_1,
                outputCoordinateWgs84ForImplementation_2,
                outputCoordinateWgs84ForImplementation_3,
                outputCoordinateWgs84ForImplementation_4,
                outputCoordinateWgs84ForImplementation_5
            };

            mock1 = new Mock <ICrsTransformationAdapter>();
            mock2 = new Mock <ICrsTransformationAdapter>();
            mock3 = new Mock <ICrsTransformationAdapter>();
            mock4 = new Mock <ICrsTransformationAdapter>();
            mock5 = new Mock <ICrsTransformationAdapter>();

            leafAdapterImplementation_1 = mock1.Object;
            leafAdapterImplementation_2 = mock2.Object;
            leafAdapterImplementation_3 = mock3.Object;
            leafAdapterImplementation_4 = mock4.Object;
            leafAdapterImplementation_5 = mock5.Object;

            inputCoordinateSweref99 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(6580822.0, 674032.0, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            CrsTransformationResult leafResult1 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_1,
                null,
                true,
                leafAdapterImplementation_1,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult2 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_2,
                null,
                true,
                leafAdapterImplementation_2,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult3 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_3,
                null,
                true,
                leafAdapterImplementation_3,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult4 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_4,
                null,
                true,
                leafAdapterImplementation_4,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult5 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_5,
                null,
                true,
                leafAdapterImplementation_5,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );

            crsIdentifierWGS84 = CrsIdentifierFactory.CreateFromEpsgNumber(EpsgNumber.WORLD__WGS_84__4326);

            mock1.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult1);
            mock2.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult2);
            mock3.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult3);
            mock4.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult4);
            mock5.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult5);

            //mock1.Setup(leaf => leaf.LongNameOfImplementation).Returns("1");
            //mock2.Setup(leaf => leaf.LongNameOfImplementation).Returns("2");
            //mock3.Setup(leaf => leaf.LongNameOfImplementation).Returns("3");
            //mock4.Setup(leaf => leaf.LongNameOfImplementation).Returns("4");
            //mock5.Setup(leaf => leaf.LongNameOfImplementation).Returns("5");
            mock1.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_DOT_SPATIAL_2_0_0_RC1);
            mock2.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_PROJ_NET_2_0_0);
            mock3.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_MIGHTY_LITTLE_GEODESY_1_0_2);
            // The type must be different but there are only three concrete types as above to use
            // but then instead can use the ones below (and the purpose of this enum is to use it as key in a dictionary/hashtable)
            mock4.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.UNSPECIFIED_LEAF);
            mock5.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.UNSPECIFIED);

            allLeafAdapters = new List <ICrsTransformationAdapter> {
                leafAdapterImplementation_1,
                leafAdapterImplementation_2,
                leafAdapterImplementation_3,
                leafAdapterImplementation_4,
                leafAdapterImplementation_5
            };
        }
Exemple #12
0
public void method() {
    Console.WriteLine("LargerCSharpeExample starts");

    // Some terminology regarding the names used in the below code example:
    // "CRS" = Coordinate Reference System
    // "WGS84" is the most frequently used coordinate system (e.g. the coordinates usually used in a GPS)    
    // "SWEREF99TM" is the official coordinate system used by authorities in Sweden
    // "EPSG" = "European Petroleum Survey Group" was (but the EPSG name is still often used) 
    //           an organization defining CRS with integer numbers e.g.  4326 for WGS84 or 3006 for SWEREF99TM
    int epsgWgs84  = EpsgNumber.WORLD__WGS_84__4326;
    int epsgSweRef = EpsgNumber.SWEDEN__SWEREF99_TM__3006;
    // The above "EpsgNumber" class with LOTS OF constants (and more constants classes) have been generated, 
    // using "FreeMarker" and database downloaded from EPSG ( http://www.epsg.org or http://www.epsg-registry.org ) 
    // from "crs-transformation-code-generation" in the project https://github.com/TomasJohansson/crsTransformations

    CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory.LatLon(59.330231, 18.059196, epsgWgs84);
    // https://kartor.eniro.se/m/03Yxp
    // SWEREF99TM coordinates (for WGS84 59.330231, 18.059196) 
    // according to Eniro (above URL): 6580822, 674032 (northing, easting)
    
    ICrsTransformationAdapter crsTransformationAdapter; // interface with concrete "leaf" implementation or "composite" implementations
    // This code example is using a "composite" which will use multiple libraries to do the same transformation and then 
    // return a coordinate with the median values (median of the northing values and median of the easting values)  
    crsTransformationAdapter = CrsTransformationAdapterCompositeFactory.Create().CreateCrsTransformationMedian();
    // The above factory will try to use those known objects which implements the interface i.e. the number 
    // of "leaf" objects will depend on how many you included as for example NuGet dependencies (three in the above NuGet example)
    Console.WriteLine("Number of 'leafs' : " + crsTransformationAdapter.TransformationAdapterChildren.Count);
    // Console output from the above row:
    // Number of 'leafs' : 3

    // Transform the WGS84 coordinate to a SWEREF99TM coordinate:
    CrsCoordinate centralStockholmSweRef = crsTransformationAdapter.TransformToCoordinate(centralStockholmWgs84, epsgSweRef);
    Console.WriteLine("Median Composite Northing: " + centralStockholmSweRef.Northing);
    Console.WriteLine("Median Composite Easting: " + centralStockholmSweRef.Easting);
    // Console output from the above two rows:
    //      Median Composite Northing: 6580821.99121561
    //      Median Composite Easting: 674032.357177155
    // (and these can be compared with the 'Eniro' values above i.e. '6580822, 674032 (northing, easting)' )
    
    // The coordinate class provides four properties with different names for the same east-west value and 
    // four properties for the same name each north-south value, as below:
    //      Four EQUIVALENT properties:  Easting  , X , Longitude , XEastingLongitude
    //      Four EQUIVALENT properties:  Northing , Y , Latitude  , YNorthingLatitude
    // Regarding the above alternative methods, depending on the desired semantic in your context, you may want to use:
    //      X/Y for a geocentric or cartesian system
    //      Longitude/Latitude for a geodetic or geographic system
    //      Easting/Northing for a cartographic or projected system
    //      xEastingLongitude/yNorthingLatitude for general code handling different types of system
    
    // If you want more details for the result you can use the following 'Transform' method: 
    //  (instead of the method 'TransformToCoordinate' used above)
    CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter.Transform(centralStockholmWgs84, epsgSweRef);
    if(!centralStockholmResultSweRef.IsSuccess) {
        Console.WriteLine("No coordinate result");
    }
    else {
        if(centralStockholmResultSweRef.IsReliable(
            2,      // minimumNumberOfSuccesfulResults
            0.01    // maxDeltaValueForXLongitudeAndYLatitude
        )) {
            // at least 2 succesful results and the maximal difference in northing or easting is less than 0.01
            // (and if you want to know the exact difference you can find it in this code example further down the page)
            Console.WriteLine("Reliable result"); // according to your chosen parameters to the method 'isReliable'    
        }
        else {
            Console.WriteLine("Not reliable result");
        }
        Console.WriteLine(centralStockholmResultSweRef.OutputCoordinate);
        // Console output from the above code row:
        // CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
        
        // When your code is in a context where you only have the result (but not the adapter object) 
        // (e.g. in a method receiving the result as a parameter)
        // you can get back the object which created the result as below:
        ICrsTransformationAdapter crsTransformationAdapterResultSource = centralStockholmResultSweRef.CrsTransformationAdapterResultSource;
        CrsTransformationAdapteeType adapteeType = crsTransformationAdapterResultSource.AdapteeType;
        Console.WriteLine("adapteeType: " + adapteeType); // console output: COMPOSITE_MEDIAN
        // The above code row returned an enum which is not really a true adaptee just like the 'composite' is not a true adapter.
        // However, when iterating (as below) the "leaf" results, 
        // it might be more interesting to keep track of from where the different values originated
        IList<CrsTransformationResult> transformationResultChildren = centralStockholmResultSweRef.TransformationResultChildren;
        foreach (CrsTransformationResult crsTransformationResultLeaf in transformationResultChildren) {
            if(!crsTransformationResultLeaf.IsSuccess) continue; // continue with the next 'leaf'
            
            ICrsTransformationAdapter resultAdapter = crsTransformationResultLeaf.CrsTransformationAdapterResultSource;
            Console.WriteLine(resultAdapter.AdapteeType);
            // The above code row will output rows like this: 
            // "LEAF_PROJ_NET_4_GEO_API_1_4_1" or "LEAF_MIGHTY_LITTLE_GEODESY_1_0_1" and so on
            if(!crsTransformationResultLeaf.IsReliable(
                    2,      // minimumNumberOfSuccesfulResults
                    1000    // maxDeltaValueForXLongitudeAndYLatitude
            )) {
                // The above constraint "at least 2 implementations" will always fail because now we are dealing with "leafs"
                // The above delta value constraint has very high tolerance but it does not matter since 
                // the constraint about the number of implementations will fail
                Console.WriteLine("Only 'composites' can have more than one result and this is a 'leaf' and thus does not have at least two results");
            }
            Console.WriteLine("Adapter long name: " + resultAdapter.LongNameOfImplementation); // full class name including package
            Console.WriteLine("Adapter short name: " + resultAdapter.ShortNameOfImplementation); // class name suffix i.e. the unique part
            // The above "long" names will be for example:
            //      Programmerare.CrsTransformations.Adapter.DotSpatial.CrsTransformationAdapterDotSpatial
            //      Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy.CrsTransformationAdapterMightyLittleGeodesy
            // The above "short" names will be for example:
            //      DotSpatial
            //      MightyLittleGeodesy
            Console.WriteLine("adaptee: " + resultAdapter.AdapteeType);
            // The above row will output for example:
            //      LEAF_DOT_SPATIAL_2_0_0_RC1
            //      LEAF_MIGHTY_LITTLE_GEODESY_1_0_1
            // (note that the version number is included for the adaptees)
            Console.WriteLine("isComposite: " + resultAdapter.IsComposite); // "False" since we are iterating "leaf" results
            Console.WriteLine("Coordinate result for " + resultAdapter.AdapteeType + " : " + crsTransformationResultLeaf.OutputCoordinate);
            // The above row will output these rows when doing the iteration:
            //      Coordinate result for LEAF_DOT_SPATIAL_2_0_0_RC1 : CrsCoordinate(xEastingLongitude=674032.357322213, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
            //      Coordinate result for LEAF_PROJ_NET_4_GEO_API_1_4_1 : CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99437121, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
            //      Coordinate result for LEAF_MIGHTY_LITTLE_GEODESY_1_0_1 : CrsCoordinate(xEastingLongitude=674032.357, yNorthingLatitude=6580821.991, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
            // Note that the median value for "x" is 674032.357177155 for the above 
            // three values 674032.357 , 674032.357177155 , 674032.357322213 . 
            // That is the same value as was displayed before the iteration of the children/leafs for the median composite.
            // The same applies for the above "y" i.e. the median is 6580821.99121561
            // for the three y values 6580821.991 , 6580821.99121561 , 6580821.99437121
        }
        // The result object also provides convenience methods for the results (which you of course otherwise might calculate by iterating the above results)
        CrsTransformationResultStatistic crsTransformationResultStatistic = centralStockholmResultSweRef.CrsTransformationResultStatistic;
        // Note that the initially created composite was a "median composite" returning the median as the main value, 
        // but you can also create an average composite and regardless you can access both the median and the average with the aggregated statistics object:
        Console.WriteLine("average coordinate: " + crsTransformationResultStatistic.CoordinateAverage);
        Console.WriteLine("median coordinate: " + crsTransformationResultStatistic.CoordinateMedian);
        // Console output from the above two rows:
        // average coordinate: CrsCoordinate(xEastingLongitude=674032.357166456, yNorthingLatitude=6580821.99219561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
        // median coordinate: CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))

        Console.WriteLine("MaxDifferenceForXEastingLongitude: " + crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude);
        Console.WriteLine("MaxDifferenceForYNorthingLatitude: " + crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude);
        // Output from the above two rows:
        // MaxDifferenceForXEastingLongitude: 0.000322213280014694
        // MaxDifferenceForYNorthingLatitude: 0.00337121076881886
        // As you can see in the above iteration, the min and max x values are 674032.357 and 674032.357322213 (and the difference is 0.000322213).
        // Similarly the min and max y values are 6580821.991 and 6580821.99437121 (and the difference is 0.00337121).
        // The above two "MaxDifference" methods are used within the implementation of the convenience method 'isReliable' 
        // (also illustrated in this example further above)
    
    } // else statement ends

    Console.WriteLine("LargerCSharpeExample ends");
    Console.ReadLine();
} // method ends
        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);
        }
Exemple #14
0
        public void CSharpeExampleCode()
        {
            int epsgWgs84  = EpsgNumber.WORLD__WGS_84__4326;
            int epsgSweRef = EpsgNumber.SWEDEN__SWEREF99_TM__3006;

            Assert.AreEqual(4326, epsgWgs84);
            Assert.AreEqual(3006, epsgSweRef);

            CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory.LatLon(59.330231, 18.059196, epsgWgs84);

            ICrsTransformationAdapter crsTransformationAdapter     = CrsTransformationAdapterCompositeFactory.Create().CreateCrsTransformationMedian();
            CrsTransformationResult   centralStockholmResultSweRef = crsTransformationAdapter.Transform(centralStockholmWgs84, epsgSweRef);

            Assert.IsNotNull(centralStockholmResultSweRef);
            Assert.IsTrue(centralStockholmResultSweRef.IsSuccess);
            IList <CrsTransformationResult> transformationResultChildren = centralStockholmResultSweRef.TransformationResultChildren;

            // Reason for the below assertion with value 3 :
            // If the NuGet configuration includes all (currently three) adapter implementations, then the
            // above created 'Composite' implementation will below use all three 'leaf' implementations
            // and return a coordinate with a median longitude and a median latitude
            Assert.AreEqual(3, transformationResultChildren.Count);

            // Console.WriteLine(centralStockholmResultSweRef.OutputCoordinate);
            // Console output from the above code row:
            // CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
            var outputCoordinate = centralStockholmResultSweRef.OutputCoordinate;

            Assert.IsNotNull(outputCoordinate);
            Assert.AreEqual(674032.357177155, outputCoordinate.XEastingLongitude, SmallDeltaValue);
            Assert.AreEqual(6580821.99121561, outputCoordinate.YNorthingLatitude, SmallDeltaValue);

            CrsTransformationResultStatistic crsTransformationResultStatistic = centralStockholmResultSweRef.CrsTransformationResultStatistic;
            var medianCoordinate = crsTransformationResultStatistic.CoordinateMedian;
            // the median values have already been tested above since we used 'CreateCrsTransformationMedian'
            // for creating the main result.
            var averageCoordinate = crsTransformationResultStatistic.CoordinateAverage;

            Assert.AreEqual(674032.35716645606, averageCoordinate.XEastingLongitude, SmallDeltaValue);
            Assert.AreEqual(6580821.9921956062, averageCoordinate.YNorthingLatitude, SmallDeltaValue);

            Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable);
            Assert.AreEqual(3, crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults);
            Assert.That(crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude, Is.LessThan(0.01));
            Assert.That(crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude, Is.LessThan(0.01));

            // "Reliable True" below since there should be three sucesful results
            // and the absolute value for the difference between longitudes and longitudes
            // should be less than 0.01
            Assert.IsTrue(
                centralStockholmResultSweRef.IsReliable(
                    3,   // minimumNumberOfSuccesfulResults
                    0.01 // maxDeltaValueForXLongitudeAndYLatitude
                    )
                );

            // "Reliable False" below because too extreme requirements of equal values for all the results
            // i.e. very small tolerance for differences
            Assert.IsFalse(
                centralStockholmResultSweRef.IsReliable(
                    3,                      // minimumNumberOfSuccesfulResults
                    0.000000000000000000001 // maxDeltaValueForXLongitudeAndYLatitude
                    )
                );

            // "Reliable False" below because can not require 4 succesful values
            // when there are only 3 implementations
            Assert.IsFalse(
                centralStockholmResultSweRef.IsReliable(
                    4,   // minimumNumberOfSuccesfulResults
                    0.01 // maxDeltaValueForXLongitudeAndYLatitude
                    )
                );

            ICrsTransformationAdapter    crsTransformationAdapterResultSource = centralStockholmResultSweRef.CrsTransformationAdapterResultSource;
            CrsTransformationAdapteeType adapteeType = crsTransformationAdapterResultSource.AdapteeType;

            Assert.AreEqual(CrsTransformationAdapteeType.COMPOSITE_MEDIAN, adapteeType);
            var dict = new Dictionary <CrsTransformationAdapteeType, bool>();

            foreach (CrsTransformationResult crsTransformationResultLeaf in transformationResultChildren)
            {
                Assert.IsTrue(crsTransformationResultLeaf.IsSuccess);
                dict.Add(crsTransformationResultLeaf.CrsTransformationAdapterResultSource.AdapteeType, true);

                // Leafs always only have one result and thus there are zero difference between max and min result.
                // Therefore the below assertion should succeed
                Assert.IsTrue(
                    crsTransformationResultLeaf.IsReliable(
                        1,                                // minimumNumberOfSuccesfulResults
                        0.0000000000000000000000000000001 // maxDeltaValueForXLongitudeAndYLatitude
                        )
                    );

                // Leafs always only have one result and thus the below tested method should return False
                Assert.IsFalse(
                    crsTransformationResultLeaf.IsReliable(
                        2,  // minimumNumberOfSuccesfulResults
                        0.1 // maxDeltaValueForXLongitudeAndYLatitude
                        )
                    );

                CrsTransformationResultStatistic leafResultStatistic = crsTransformationResultLeaf.CrsTransformationResultStatistic;
                Assert.IsTrue(leafResultStatistic.IsStatisticsAvailable);
                Assert.AreEqual(1, leafResultStatistic.NumberOfPotentiallySuccesfulResults);
                Assert.That(leafResultStatistic.MaxDifferenceForXEastingLongitude, Is.LessThan(0.01));
                Assert.That(leafResultStatistic.MaxDifferenceForYNorthingLatitude, Is.LessThan(0.01));
            }
            Assert.AreEqual(3, dict.Count);
            Assert.IsTrue(dict.ContainsKey(CrsTransformationAdapteeType.LEAF_MIGHTY_LITTLE_GEODESY_1_0_1));
            Assert.IsTrue(dict.ContainsKey(CrsTransformationAdapteeType.LEAF_DOT_SPATIAL_2_0_0_RC1));
            Assert.IsTrue(dict.ContainsKey(CrsTransformationAdapteeType.LEAF_PROJ_NET_4_GEO_API_1_4_1));
        }
Exemple #15
0
        public void method()
        {
            // ...

            // The interface with seven implementations as illustrated below
            ICrsTransformationAdapter crsTransformationAdapter;

            // The interface is defined in the library "Programmerare.CrsTransformations.Core" with this full name:
            // Programmerare.CrsTransformations.ICrsTransformationAdapter

            // The three 'Leaf' implementations:

            // Library "Programmerare.CrsTransformations.Adapter.DotSpatial", class:
            // Programmerare.CrsTransformations.Adapter.DotSpatial.CrsTransformationAdapterDotSpatial
            crsTransformationAdapter = new CrsTransformationAdapterDotSpatial();

            // Library "Programmerare.CrsTransformations.Adapter.ProjNet", class:
            // Programmerare.CrsTransformations.Adapter.ProjNet.CrsTransformationAdapterProjNet
            crsTransformationAdapter = new CrsTransformationAdapterProjNet();

            // Library "Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy", class:
            // Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy.CrsTransformationAdapterMightyLittleGeodesy
            crsTransformationAdapter = new CrsTransformationAdapterMightyLittleGeodesy();

            // - - - - - - - - - - - -

            // The four 'Composite' implementations below are all located in the library
            // "Programmerare.CrsTransformations.Core" and the factory class is:
            // Programmerare.CrsTransformations.CompositeTransformations.CrsTransformationAdapterCompositeFactory
            var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();

            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();

            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage();

            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess();

            // All of the above three factory methods without any parameter will try to use as many of
            // the three (currently) 'leaf' implementations as are available in runtime
            // (e.g. are included as NuGet dependencies).
            // If you want to specify explicitly which ones to be used, you can provide
            // a parameter 'IList<ICrsTransformationAdapter>' to the Create method like this:
            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(
                new List <ICrsTransformationAdapter> {
                new CrsTransformationAdapterDotSpatial(),
                new CrsTransformationAdapterProjNet(),
                new CrsTransformationAdapterMightyLittleGeodesy(),
            }
                );

            // The fourth 'Composite' below does not use any implicit implementations
            // but if you want to use a result created as a weighted average then the weights need
            // to be specified explicitly per leaf implementation as in the example below.
            var weightFactory = CrsTransformationAdapterWeightFactory.Create();

            crsTransformationAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationWeightedAverage(
                new List <CrsTransformationAdapterWeight> {
                weightFactory.CreateFromInstance(new CrsTransformationAdapterDotSpatial(), 1.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterProjNet(), 1.0),
                weightFactory.CreateFromInstance(new CrsTransformationAdapterMightyLittleGeodesy(), 2.0),
            }
                );
            // The weight values above illustrates a situation where you (for some reason) want to consider
            // the transformation results from 'MightyLittleGeodesy' as being 'two times better' than the others.
        }
 public void SetUp()
 {
     weightFactory = CrsTransformationAdapterWeightFactory.Create();
     crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
 }
Exemple #17
0
        public void FindPotentialBuggyImplementationsHelper(
            int minEpsgCrsCode,
            int maxEpsgCrsCode,
            double?optionalDelta = null
            )
        {
            int    numberIfEpsgCodesToConsiderInIteration = maxEpsgCrsCode - minEpsgCrsCode;
            bool   manyWillBeIterated = numberIfEpsgCodesToConsiderInIteration > 100;
            double deltaDiffToUse     = manyWillBeIterated ? deltaDiff : double.MinValue;

            if (optionalDelta.HasValue)
            {
                deltaDiffToUse = optionalDelta.Value;
            }

            var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            CrsTransformationAdapterComposite crsTransformationComposite = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();

            verifyThreeImplementations(crsTransformationComposite); // to make sure that the above factory really creates an object which will use three implementations

            IList <CrsTransformationResult> transformResultsWithLargeDifferences = new List <CrsTransformationResult>();

            CrsIdentifier wgs84 = CrsIdentifierFactory.CreateFromEpsgNumber(EpsgNumber.WORLD__WGS_84__4326);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile();
            int seconds = (int)stopWatch.Elapsed.TotalSeconds;

            WriteLine("Time for reading the content of the input file: " + seconds);
            stopWatch.Restart();
            int totalNumberOfSeconds;

            WriteLine("number of rows to iterate: " + coordinatesFromGeneratedCsvFile.Count);
            for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++)
            {
                if (manyWillBeIterated && (i % 100 == 0))
                {
                    //WriteLine("number of rows iterated so far: " + i);
                    totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                    //WriteLine("Number of seconds so far: " + totalNumberOfSeconds);
                    // if (i > 50) break;
                }
                EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i];
                if (
                    epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode < minEpsgCrsCode
                    ||
                    epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode > maxEpsgCrsCode
                    )
                {
                    continue;
                }
                if (!manyWillBeIterated)
                {
                    //Console.WriteLine("iterated epsgCrsCode: " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                }


                CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(epsgCrsAndAreaCodeWithCoordinates.centroidY, epsgCrsAndAreaCodeWithCoordinates.centroidX, wgs84);

                CrsTransformationResult resultOutputFromWgs4 = crsTransformationComposite.Transform(coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                if (!resultOutputFromWgs4.IsSuccess)
                {
                    continue;
                }

                CrsTransformationResult resultWhenTransformedBackToWgs84 = crsTransformationComposite.Transform(resultOutputFromWgs4.OutputCoordinate, wgs84);
                if (!resultWhenTransformedBackToWgs84.IsSuccess)
                {
                    continue;
                }

                CrsTransformationResultStatistic crsTransformationResultStatistic = resultWhenTransformedBackToWgs84.CrsTransformationResultStatistic;
                Assert.IsNotNull(crsTransformationResultStatistic);
                Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable);
                if (
                    crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude > deltaDiffToUse
                    ||
                    crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude > deltaDiffToUse
                    )
                {
                    transformResultsWithLargeDifferences.Add(resultWhenTransformedBackToWgs84);
                }
                else
                {
                    if (!manyWillBeIterated)
                    {
                        //Console.WriteLine("NOT 'big' difference for EPSG " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                        int count = crsTransformationComposite.TransformationAdapterChildren.Count;
                        //Console.WriteLine("Number of implementations not having big difference: " + count);
                    }
                }
            }
            WriteLine("Number of iterated rows/coordinates: " + coordinatesFromGeneratedCsvFile.Count);

            WriteLine("Number of results with 'large' differences: " + transformResultsWithLargeDifferences.Count);
            for (int i = 0; i < transformResultsWithLargeDifferences.Count; i++)
            {
                CrsTransformationResult transformResult = transformResultsWithLargeDifferences[i];
                WriteLine("----------------------------------------");
                WriteLine("epsg " + transformResult.InputCoordinate.CrsIdentifier.CrsCode);
                WriteLine("MaxDiffYLatitude : " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude);
                WriteLine("MaxDiffYLongitude: " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForXEastingLongitude);
                IList <CrsTransformationResult> subResults = transformResult.TransformationResultChildren;
                for (int j = 0; j < subResults.Count; j++)
                {
                    CrsTransformationResult subTransformResult = subResults[j];
                    if (subTransformResult.IsSuccess)
                    {
                        WriteLine(subTransformResult.OutputCoordinate + " , " + subTransformResult.CrsTransformationAdapterResultSource.AdapteeType);
                    }
                }
            }
        }