private void AssertCompositeResultHasLeafSubResults(
            CrsTransformationAdapterComposite compositeAdapter,
            int expectedNumberOfLeafResults
            )
        {
            CrsTransformationResult compositeTransformResult = compositeAdapter.Transform(inputCoordinateSweref99, crsIdentifierWGS84);

            Assert.IsNotNull(compositeTransformResult);
            Assert.IsTrue(compositeTransformResult.IsSuccess);
            //assertEquals(expectedNumberOfLeafResults, allLeafAdapters.size()); // five "leafs" were used to calculate the composite
            Assert.AreEqual(expectedNumberOfLeafResults, compositeTransformResult.TransformationResultChildren.Count);

            IList <CrsTransformationResult> subResults = compositeTransformResult.TransformationResultChildren;

            for (int i = 0; i < subResults.Count; i++)
            {
                CrsTransformationResult   transformResult        = subResults[i];
                ICrsTransformationAdapter leafAdapter            = allLeafAdapters[i];
                CrsTransformationResult   transformResultForLeaf = leafAdapter.Transform(inputCoordinateSweref99, crsIdentifierWGS84);
                Assert.IsNotNull(transformResultForLeaf);
                Assert.IsTrue(transformResultForLeaf.IsSuccess);
                AssertEqualCoordinate(transformResult.OutputCoordinate, transformResultForLeaf.OutputCoordinate);
                Assert.AreEqual(0, transformResultForLeaf.TransformationResultChildren.Count); // no subresults for a leaf
            }
        }
コード例 #2
0
        private void verifyThreeImplementations(
            CrsTransformationAdapterComposite crsTransformationAdapterComposite
            )
        {
            CrsCoordinate           input  = CrsCoordinateFactory.LatLon(59.0, 18.0);
            CrsTransformationResult result = crsTransformationAdapterComposite.Transform(input, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsSuccess);
            const int numberOfImplementations = CrsTransformationAdapterTest.EXPECTED_NUMBER_OF_ADAPTER_LEAF_IMPLEMENTATIONS;

            Assert.AreEqual(numberOfImplementations, result.TransformationResultChildren.Count);
            CrsTransformationResultStatistic crsTransformationResultStatistic = result.CrsTransformationResultStatistic;

            Assert.IsNotNull(crsTransformationResultStatistic);
            Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable);
            Assert.AreEqual(numberOfImplementations, crsTransformationResultStatistic.NumberOfPotentiallySuccesfulResults);
            Assert.That(crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude, Is.LessThan(0.001));
        }
        private void AssertWeightedAverageResult(
            CrsTransformationAdapterComposite weightedAverageCompositeAdapter
            )
        {
            CrsTransformationResult weightedAverageResult = weightedAverageCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.IsNotNull(weightedAverageResult);
            Assert.IsTrue(weightedAverageResult.IsSuccess);
            Assert.AreEqual(base.allCoordinateResultsForTheDifferentImplementations.Count, weightedAverageResult.TransformationResultChildren.Count);

            CrsCoordinate weightedAverageCoordinate = weightedAverageResult.OutputCoordinate;

            Assert.AreEqual(coordinateWithExpectedWeightedValues.YNorthingLatitude, weightedAverageCoordinate.YNorthingLatitude, SMALL_DELTA_VALUE);
            Assert.AreEqual(coordinateWithExpectedWeightedValues.XEastingLongitude, weightedAverageCoordinate.XEastingLongitude, SMALL_DELTA_VALUE);

            // The logic for the tests below:
            // The tested result should of course be very close to the expected result,
            // i.e. the differences (longitude and latitude differences)
            // // should be less than a very small SMALL_DELTA_VALUE value
            double diffLatTestedAdapter = Math.Abs(coordinateWithExpectedWeightedValues.YNorthingLatitude - weightedAverageCoordinate.YNorthingLatitude);
            double diffLonTestedAdapter = Math.Abs(coordinateWithExpectedWeightedValues.XEastingLongitude - weightedAverageCoordinate.XEastingLongitude);

            Assert.That(diffLatTestedAdapter, Is.LessThan(SMALL_DELTA_VALUE));// assertTrue(diffLatTestedAdapter < SMALL_DELTA_VALUE);
            Assert.That(diffLonTestedAdapter, Is.LessThan(SMALL_DELTA_VALUE));

            // Now in the rest of the assertions below,
            // the difference between the individual results which were weighted
            // should not be quite as close to that same small SMALL_DELTA_VALUE value,
            // and thus the assertions below are that the difference should be greater
            // than the SMALL_DELTA_VALUE value.
            // Of course, in theory some of the individual values below might
            // come very very close to the weighted result, and then some assertion might fail.
            // However, it turned out to not be like that with the chosen test values,
            // and thus they are asserted here as part of regression testing.
            // If this test would break, it needs to be investigated since these values
            // have been working fine to assert like below.
            AssertDiffsAreGreaterThanSmallDelta(resultCoordinateDotSpatial, coordinateWithExpectedWeightedValues);
            AssertDiffsAreGreaterThanSmallDelta(resultCoordinateMightyLittleGeodesy, coordinateWithExpectedWeightedValues);
            AssertDiffsAreGreaterThanSmallDelta(resultCoordinateProjNet, coordinateWithExpectedWeightedValues);
        }
        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));
        }
コード例 #5
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);
                    }
                }
            }
        }