Ejemplo n.º 1
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();
        }
        private void AssertTransformationResultFailure(
            CrsTransformationResult result,
            CrsCoordinate inputCoordinate,
            //CrsCoordinate expectedOutputCoordinate,
            ICrsTransformationAdapter crsTransformationAdapterSource
            )
        {
            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsSuccess);
            Assert.IsNotNull(result.Exception);

            InvalidOperationException e = Assert.Throws <InvalidOperationException>(
                () => {
                var coord = result.OutputCoordinate;
            },
                "Should not try to get output coordinate unless the result was a success"
                );

            Assert.AreEqual(inputCoordinate, result.InputCoordinate);
            IList <CrsTransformationResult> subresults = result.TransformationResultChildren;

            Assert.IsNotNull(subresults);
            Assert.AreEqual(0, subresults.Count); // Leaf should have no children
            Assert.AreEqual(this.crsTransformationAdapter, result.CrsTransformationAdapterResultSource);

            AssertStatisticsForLeaf(result);
        }
        public void TransformToCoordinate_ShouldReturnFirstResult_WhenUsingFirstSuccessCompositeAdapter()
        {
            CrsTransformationAdapterComposite firstSuccessCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(allLeafAdapters);
            CrsCoordinate resultCoordinate = firstSuccessCompositeAdapter.TransformToCoordinate(inputCoordinateSweref99, EpsgNumber.WORLD__WGS_84__4326);

            Assert.IsNotNull(resultCoordinate);

            // The assumption below (according to the setup code in the "before" method in this JUnit class)
            // is that the first adapter in the above list allLeafAdapters will return the result outputCoordinateWgs84ForImplementation_1
            Assert.AreEqual(
                outputCoordinateWgs84ForImplementation_1.YNorthingLatitude,
                resultCoordinate.YNorthingLatitude,
                SMALL_DELTA_VALUE_FOR_COMPARISONS
                );
            Assert.AreEqual(
                outputCoordinateWgs84ForImplementation_1.XEastingLongitude,
                resultCoordinate.XEastingLongitude,
                SMALL_DELTA_VALUE_FOR_COMPARISONS
                );

            AssertCompositeResultHasLeafSubResults(
                firstSuccessCompositeAdapter,
                1 // expectedNumberOfLeafResults
                );
        }
        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 Transform_ShouldReturnMedianResult_WhenUsingMedianCompositeAdapter()
        {
            CrsCoordinate expectedCoordinateWithMedianLatitudeAndLongitude = CalculateMedianCoordinate(base.allCoordinateResultsForTheDifferentImplementations);

            ICrsTransformationAdapter medianCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(
                allAdapters
                );
            CrsTransformationResult medianResult = medianCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

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

            CrsCoordinate coordinateReturnedByMedianAdapter = medianResult.OutputCoordinate;

            // The same transformation as above has been done in the base class for the individual adapters
            Assert.AreEqual(
                expectedCoordinateWithMedianLatitudeAndLongitude.XEastingLongitude,
                coordinateReturnedByMedianAdapter.XEastingLongitude,
                delta
                );
            Assert.AreEqual(
                expectedCoordinateWithMedianLatitudeAndLongitude.YNorthingLatitude,
                coordinateReturnedByMedianAdapter.YNorthingLatitude,
                delta
                );
        }
Ejemplo n.º 6
0
        // -------------------------------------------------------------------------------------


        private TestResult RunAllTransformationsOfTheCoordinatesInTheGeneratedCsvFile(
            ICrsTransformationAdapter crsTransformationAdapter,
            IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile
            )
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            IList <TestResultItem> testResultItems = new List <TestResultItem>();
            int counter = 0;

            foreach (EpsgCrsAndAreaCodeWithCoordinates item in coordinatesFromGeneratedCsvFile)
            {
                CrsCoordinate           inputCoordinateWGS84              = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(item.centroidX, item.centroidY, EpsgNumber.WORLD__WGS_84__4326);
                CrsTransformationResult resultOfTransformationFromWGS84   = crsTransformationAdapter.Transform(inputCoordinateWGS84, item.epsgCrsCode);
                CrsTransformationResult resultOfTransformationBackToWGS84 = null;
                if (resultOfTransformationFromWGS84.IsSuccess)
                {
                    resultOfTransformationBackToWGS84 = crsTransformationAdapter.Transform(resultOfTransformationFromWGS84.OutputCoordinate, EpsgNumber.WORLD__WGS_84__4326);
                }
                testResultItems.Add(new TestResultItem(item, inputCoordinateWGS84, resultOfTransformationFromWGS84, resultOfTransformationBackToWGS84));
                if (counter++ % 500 == 0)                                                                                                                                                                       // just to show some progress
                {
                    Console.WriteLine(this.GetType().Name + " , counter: " + counter + " (of the total " + coordinatesFromGeneratedCsvFile.Count + ") for adapter " + crsTransformationAdapter.GetType().Name); // to show some progress
                }
                // if(counter > 300) break;
            }
            long totalNumberOfSecondsForAllTransformations = (long)stopWatch.Elapsed.TotalSeconds;

            Console.WriteLine("Total number of seconds for method runAllTransformationsOfTheCoordinatesInTheGeneratedCsvFile: " + totalNumberOfSecondsForAllTransformations);
            return(new TestResult(crsTransformationAdapter, totalNumberOfSecondsForAllTransformations, testResultItems));
        }
Ejemplo n.º 7
0
        public void Transform_ShouldReturnAverageResult_WhenUsingAverageCompositeAdapter()
        {
            CrsCoordinate coordinateWithAverageLatitudeAndLongitude = CalculateAverageCoordinate(
                base.allCoordinateResultsForTheDifferentImplementations
                );

            ICrsTransformationAdapter averageCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationAverage(
                allAdapters
                );
            CrsTransformationResult averageResult = averageCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

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

            CrsCoordinate coordinateReturnedByCompositeAdapter = averageResult.OutputCoordinate;

            Assert.AreEqual(
                coordinateWithAverageLatitudeAndLongitude.XEastingLongitude,
                coordinateReturnedByCompositeAdapter.XEastingLongitude,
                delta
                );
            Assert.AreEqual(
                coordinateWithAverageLatitudeAndLongitude.YNorthingLatitude,
                coordinateReturnedByCompositeAdapter.YNorthingLatitude,
                delta
                );
            // assertEquals(coordinateWithAverageLatitudeAndLongitude, coordinateReturnedByCompositeAdapter);
            // Expected :Coordinate(xEastingLongitude=674032.3572074446, yNorthingLatitude=6580821.991903967, crsIdentifier=CrsIdentifier(crsCode=EPSG:3006, isEpsgCode=true, epsgNumber=3006))
            // Actual   :Coordinate(xEastingLongitude=674032.3572074447, yNorthingLatitude=6580821.991903967, crsIdentifier=CrsIdentifier(crsCode=EPSG:3006, isEpsgCode=true, epsgNumber=3006))
        }
        public void Transform_FromSweref99_ToWgs84()
        {
            resultWgs84 = crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, epsgWGS84);
            AssertCoordinateResult(
                resultWgs84,
                coordinateWgs84,
                maxLatLongDifferenceForSuccessfulTest
                );

            // testing the same transform as above but with the overloaded
            // method taking a string as last parameter instead of integer
            AssertCoordinateResult(
                crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, crsCodeWGS84),
                coordinateWgs84,
                maxLatLongDifferenceForSuccessfulTest
                );

            // testing the same transform as above but with the overloaded
            // method taking a string as last parameter instead of string or integer
            AssertCoordinateResult(
                crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, CrsIdentifierFactory.CreateFromEpsgNumber(epsgWGS84)),
                coordinateWgs84,
                maxLatLongDifferenceForSuccessfulTest
                );
        }
    private void TransformToCoordinate_ShouldThrowException_WhenCoordinateIsNotValid(
        CrsCoordinate unvalidInputCoordinate
    ) {
        foreach (ICrsTransformationAdapter crsTransformationAdapter in crsTransformationAdapterImplementations) {
            //Exception exception = Assert.Throws<Exception>( () => {
            //    crsTransformationAdapter.TransformToCoordinate(unvalidInputCoordinate, base.epsgNumberForSweref99TM);
            //}
            //,
            //"Exception was not thrown but SHOULD have been thrown for implementation " + crsTransformationAdapter.AdapteeType + " and coordinate " + unvalidInputCoordinate 
            //);
                
            // The above 'Assert.Throws' test for a specific exception type 
            // while the code below (with 'Assert.That' and then Assert.That' works for any exception

            Assert.That(
                () => crsTransformationAdapter.TransformToCoordinate(
                    unvalidInputCoordinate, 
                    base.epsgNumberForSweref99TM
                ),
                Throws.Exception
                    // testing that the thrown exception type is one of the following:
                    .TypeOf<ArgumentOutOfRangeException>().Or
                    .TypeOf<NotSupportedException>().Or
                    .TypeOf<ArgumentException>().Or
                    .TypeOf<Exception>()
            );
        }
    }
 private void AssertEqualCoordinate(
     CrsCoordinate c1,
     CrsCoordinate c2
     )
 {
     Assert.AreEqual(c1.YNorthingLatitude, c2.YNorthingLatitude, SMALL_DELTA_VALUE_FOR_COMPARISONS);
     Assert.AreEqual(c1.XEastingLongitude, c2.XEastingLongitude, SMALL_DELTA_VALUE_FOR_COMPARISONS);
 }
 public void SetUpCrsTransformationAdapterTest() {
     unvalidCrsCode = "This string is NOT a correct crs/EPSG code";
     validInputCoordinate = CrsCoordinateFactory.LatLon(
         60.0, // ok wgs84 latitude
         20.0, // ok wgs84 longitude
         epsgNumberForWgs84 // OK
     );
 }
 public void TransformToCoordinate_ShouldThrowException_WhenCrsCodeIsNotValid() {
     CrsCoordinate unvalidInputCoordinate = CrsCoordinateFactory.LatLon(
         60.0, // ok wgs84 latitude
         20.0, // ok wgs84 longitude
         unvalidCrsCode
     );
     TransformToCoordinate_ShouldThrowException_WhenCoordinateIsNotValid(unvalidInputCoordinate);
 }
 public void Transform_ShouldReturnSuccessFalseButNotThrowException_WhenLatitudeIsNotValid() {
     CrsCoordinate unvalidInputCoordinate = CrsCoordinateFactory.LatLon(
         -9999999999.0, // NOT ok wgs84 latitude
         20.0, // ok wgs84 longitude
         epsgNumberForWgs84
     );
     Transform_ShouldReturnSuccessFalseButNotThrowException_WhenCoordinateIsNotValid(unvalidInputCoordinate);
 }
Ejemplo n.º 14
0
    private void AssertEqualCoordinates(CrsCoordinate coordinate1, CrsCoordinate coordinate2) {
        Assert.AreEqual(coordinate1.XEastingLongitude, coordinate2.XEastingLongitude, deltaTolerance);
        Assert.AreEqual(coordinate1.YNorthingLatitude, coordinate2.YNorthingLatitude, deltaTolerance);
        Assert.AreEqual(coordinate1.CrsIdentifier, coordinate2.CrsIdentifier); // data class
        Assert.AreEqual(coordinate1.CrsIdentifier.EpsgNumber, coordinate2.CrsIdentifier.EpsgNumber);

        Assert.AreEqual(coordinate1.GetHashCode(), coordinate2.GetHashCode());
        Assert.AreEqual(coordinate1, coordinate2);
    }
 public void Transform_FromRT90_ToWgs84()
 {
     resultWgs84 = crsTransformationAdapter.TransformToCoordinate(coordinateRT90, epsgWGS84);
     AssertCoordinateResult(
         resultWgs84,
         coordinateWgs84,
         maxLatLongDifferenceForSuccessfulTest
         );
 }
 private void AssertCoordinateResult(
     CrsCoordinate actual,
     CrsCoordinate expected,
     double maxDeltaDifference
     )
 {
     Assert.IsNotNull(coordinateSweref99);
     Assert.AreEqual(expected.Y, actual.Y, maxDeltaDifference);
     Assert.AreEqual(expected.X, actual.X, maxDeltaDifference);
 }
Ejemplo n.º 17
0
 public void CoordinateWithNineDecimals_ShouldBeEqualToCoordinateConstructedWithTheSameValues_WhenTheOnlyDifferenceIsSomeAdditionalZeroes() {
     CrsCoordinate c1 = CrsCoordinateFactory.CreateFromLatitudeLongitude(59.123456789, 18.123456789000);
     CrsCoordinate c2 = CrsCoordinateFactory.CreateFromLatitudeLongitude(59.123456789000, 18.123456789);
     Assert.AreEqual(
         c1, c2
     );
     Assert.AreEqual(
         c1.GetHashCode(), c2.GetHashCode()
     );
 }
Ejemplo n.º 18
0
        /**
         * Iterates the test results and counts the number of successes and failures
         * including considering a maximum delta difference between the coordinates
         * when having transformed back and forth.
         * While iterating, lines of strings are also created, with the resulting coordinates.
         * Depennding on a bool parameter, those string lines are either written to
         * a file, or compared with a previous created file.
         *
         * @param testResult
         * @param deltaLimitForSuccess
         * @param createNewRegressionFileInfo if false, then instead compare with previous regression file
         */
        private void HandleTestResults(
            TestResult testResult,
            double deltaLimitForSuccess,
            bool shouldCreateNewRegressionFile,
            string fileNameSuffixExcludingExtension
            )
        {
            Console.WriteLine("-------------------------------");
            Console.WriteLine("testResults for " + testResult.Adapter.GetType().Name);
            Console.WriteLine("seconds: " + testResult.TotalNumberOfSecondsForAllTransformations);
            IList <TestResultItem> testResultItems = testResult.TestResultItems;
            int            countOfFailures         = 0;
            int            countOfSuccess          = 0;
            bool           isSuccess;
            IList <string> linesWithCurrentResults = new List <string>();

            foreach (TestResultItem testResultItem in testResultItems)
            {
                string resultString = testResultItem.GetResultStringForRegressionFile();
                linesWithCurrentResults.Add(resultString);
                isSuccess = testResultItem.IsSuccessfulTransformationFromWGS84();
                if (isSuccess)
                {
                    isSuccess = testResultItem.IsSuccessfulTransformationBackToWGS84();
                    if (isSuccess)
                    {
                        CrsCoordinate inputCoordinateWGS84 = testResultItem.GetInputCoordinateWGS84();
                        CrsCoordinate wgs84Again           = testResultItem.GetCoordinateOutputTransformationBackToWGS84();
                        double        deltaLong            = Math.Abs(inputCoordinateWGS84.XEastingLongitude - wgs84Again.XEastingLongitude);
                        double        deltaLat             = Math.Abs(inputCoordinateWGS84.YNorthingLatitude - wgs84Again.YNorthingLatitude);
                        isSuccess = deltaLong < deltaLimitForSuccess && deltaLat < deltaLimitForSuccess;
                    }
                }
                if (isSuccess)
                {
                    countOfSuccess++;
                }
                else
                {
                    countOfFailures++;
                }
            }
            Console.WriteLine("countOfSuccess: " + countOfSuccess);
            Console.WriteLine("countOfFailures: " + countOfFailures);
            Console.WriteLine("-------------------------------");

            FileInfo file = GetFileForRegressionResults(testResult.Adapter, fileNameSuffixExcludingExtension);

            if (shouldCreateNewRegressionFile)
            {
                CreateNewRegressionFile(file, linesWithCurrentResults);
            }
        }
        private void VerifyThatTheCreatedAdapterIsRealObject(
            ICrsTransformationAdapter crsTransformationAdapter
            )
        {
            Assert.IsNotNull(crsTransformationAdapter);
            // below trying to use the created object to really make sure it works
            CrsCoordinate           coordinateWgs84 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(59.330231, 18.059196, EpsgNumber.WORLD__WGS_84__4326);
            CrsTransformationResult resultSweref99  = crsTransformationAdapter.Transform(coordinateWgs84, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.IsNotNull(resultSweref99);
            Assert.IsTrue(resultSweref99.IsSuccess);
        }
        public void TransformToCoordinate_WhenInputCoordinateIsNull()
        {
            CrsIdentifier crsWgs84 = coordinateWgs84.CrsIdentifier;

            Assert.IsNotNull(crsWgs84);
            CrsCoordinate nullCordinate = null;
            // TransformToCoordinate SHOULD (unlike the transform method)
            // throw exception
            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => {
                crsTransformationAdapter.TransformToCoordinate(nullCordinate, crsWgs84);
            });
        }
Ejemplo n.º 21
0
 public void TransformResultConstruction_ShouldThrowException_WhenParametersSuccessTrueAndOutputCoordinateNull() {
     CrsCoordinate outputCoordinateNull = null;
     ArgumentException exception = Assert.Throws<ArgumentException>(
         () => {
             CreateCrsTransformationResult(
                 outputCoordinateNull, // outputCoordinate = null, then success should be false !
                 null,
                 true
             );
         }
         ,
         "unvalid TransformResult object construction should throw exception when success true is combined with null as output coordinate"
     );
 }
Ejemplo n.º 22
0
    public void Coordinate_ShouldBeCreatedWithWGS84asDefaultCrs_WhenNotSpecifyingCrs() {
        CrsCoordinate coordinate = CrsCoordinateFactory.CreateFromLongitudeLatitude(xLongitude, yLatitude);
        Assert.AreEqual(
            epsgNumberWgs84, // EpsgNumber.WORLD__WGS_84__4326,
            coordinate.CrsIdentifier.EpsgNumber
        );

        // The tets below is the same as above except that the factory method use the reversed order for lat/lon parameters
        coordinate = CrsCoordinateFactory.CreateFromLatitudeLongitude(yLatitude, xLongitude);
        Assert.AreEqual(
            epsgNumberWgs84, // EpsgNumber.WORLD__WGS_84__4326,
            coordinate.CrsIdentifier.EpsgNumber
        );        
    }
    private void TransformToCoordinate_ShouldReturnTheOriginalCoordinate_WhenTransformingBackAgainFromTheResult(
        ICrsTransformationAdapter crsTransformationAdapter,
        CrsCoordinate inputCoordinateOriginalCRS,
        int epsgNumberForTransformTargetCRS
    ) {
        double delta = GetDeltaValueForComparisons(inputCoordinateOriginalCRS.CrsIdentifier);

        CrsCoordinate outputCoordinateForTransformTargetCRS = crsTransformationAdapter.TransformToCoordinate(inputCoordinateOriginalCRS, epsgNumberForTransformTargetCRS);
        CrsCoordinate outputCoordinateOriginalCRS = crsTransformationAdapter.TransformToCoordinate(outputCoordinateForTransformTargetCRS, inputCoordinateOriginalCRS.CrsIdentifier.EpsgNumber);

        Assert.AreEqual(inputCoordinateOriginalCRS.XEastingLongitude, outputCoordinateOriginalCRS.XEastingLongitude, delta);
        Assert.AreEqual(inputCoordinateOriginalCRS.YNorthingLatitude, outputCoordinateOriginalCRS.YNorthingLatitude, delta);
        Assert.AreEqual(inputCoordinateOriginalCRS.CrsIdentifier.EpsgNumber, outputCoordinateOriginalCRS.CrsIdentifier.EpsgNumber);
    }
        public void TransformResult_WhenInputCoordinateIsNull()
        {
            CrsIdentifier crsWgs84 = coordinateWgs84.CrsIdentifier;

            Assert.IsNotNull(crsWgs84);
            CrsCoordinate           nullCordinate = null;
            CrsTransformationResult result        = crsTransformationAdapter.Transform(nullCordinate, crsWgs84);

            AssertTransformationResultFailure(
                result,
                nullCordinate,
                crsTransformationAdapter
                );
        }
Ejemplo n.º 25
0
        public void FindTheNumberOfEpsgCodesPotentiallySupported()
        {
            IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile();

            int totalNumberOfSeconds;

            foreach (ICrsTransformationAdapter leafAdapter in base.crsTransformationAdapterLeafImplementations)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                int numberOfFailures  = 0;
                int numberOfSuccesses = 0;
                for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++)
                {
                    EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i];
                    CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.LatLon(
                        epsgCrsAndAreaCodeWithCoordinates.centroidY,
                        epsgCrsAndAreaCodeWithCoordinates.centroidX
                        );
                    CrsTransformationResult resultOutputFromWgs4 = leafAdapter.Transform(
                        coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode
                        );
                    if (resultOutputFromWgs4.IsSuccess)
                    {
                        numberOfSuccesses++;
                        //WriteLine("Success " + DateTime.Now + " " + leafAdapter.AdapteeType + " " + resultOutputFromWgs4.OutputCoordinate);
                    }
                    else
                    {
                        //WriteLine("Failure " + DateTime.Now + " " + leafAdapter.AdapteeType);
                        numberOfFailures++;
                    }
                    if (i % 500 == 0)
                    {
                        //WriteLine("number of rows iterated so far: " + i + " (for leafAdapter " + leafAdapter.AdapteeType + " )");
                        totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                        //WriteLine("Number of seconds so far (for the above adapter) : " + totalNumberOfSeconds);
                        //if(i > 500) break;
                    }
                }
                totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                WriteLine("---------------------");
                WriteLine("Result for adapter: " + leafAdapter.AdapteeType);
                WriteLine("numberOfSuccesses: " + numberOfSuccesses);
                WriteLine("numberOfFailures: " + numberOfFailures);
                WriteLine("Number of seconds: " + totalNumberOfSeconds);
                WriteLine("---------------------");
            }
        }
        private void AssertDiffsAreGreaterThanSmallDelta(
            CrsCoordinate resultCoordinateIndividualImplementation,
            CrsCoordinate coordinateWithExpectedWeightedValues
            )
        {
            double diffLatIndividualImplementation = Math.Abs(
                coordinateWithExpectedWeightedValues.YNorthingLatitude - resultCoordinateIndividualImplementation.YNorthingLatitude
                );
            double diffLonIndividualImplementation = Math.Abs(
                coordinateWithExpectedWeightedValues.XEastingLongitude - resultCoordinateIndividualImplementation.XEastingLongitude
                );

            Assert.That(diffLatIndividualImplementation, Is.GreaterThan(SMALL_DELTA_VALUE));
            Assert.That(diffLonIndividualImplementation, Is.GreaterThan(SMALL_DELTA_VALUE));
        }
    private void TransformToCoordinate_ShouldReturnCorrectWgs84coordinate_WhenTransformingFromRT90(
        ICrsTransformationAdapter crsTransformationAdapter
    ) {
        double rt90_Y = 6580994;
        double rt90_X = 1628294;

        double wgs84Lat_expected = 59.330231;
        double wgs84Lon_expected = 18.059196;

        CrsCoordinate inputCoordinate = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(rt90_X, rt90_Y, base.epsgNumberForRT90);

        CrsCoordinate outputCoordinate = crsTransformationAdapter.TransformToCoordinate(inputCoordinate, base.epsgNumberForWgs84);
        Assert.AreEqual(wgs84Lat_expected, outputCoordinate.YNorthingLatitude, 0.1);
        Assert.AreEqual(wgs84Lon_expected, outputCoordinate.XEastingLongitude, 0.1);
    }
        protected void SetUpbase(
            ICrsTransformationAdapter crsTransformationAdapter,
            CrsTransformationAdapteeType expectedCrsTransformationAdapteeType,
            double maxMeterDifferenceForSuccessfulTest,
            double maxLatLongDifferenceForSuccessfulTest
            )
        {
            this.crsTransformationAdapter              = crsTransformationAdapter;
            this.expectedCrsTransformationAdapteeType  = expectedCrsTransformationAdapteeType;
            this.maxMeterDifferenceForSuccessfulTest   = maxMeterDifferenceForSuccessfulTest;
            this.maxLatLongDifferenceForSuccessfulTest = maxLatLongDifferenceForSuccessfulTest;

            coordinateWgs84    = CrsCoordinateFactory.LatLon(wgs84Lat, wgs84Lon, epsgWGS84);
            coordinateSweref99 = CrsCoordinateFactory.LatLon(sweref99Y, sweref99X, epsgSweref99);
            coordinateRT90     = CrsCoordinateFactory.LatLon(rt90Y, rt90X, epsgRT9025gonv);
        }
Ejemplo n.º 29
0
 public void TransformResultConstruction_ShouldThrowException_WhenParametersExceptionIsNotNullAndSuccessIsTrue() {
     Exception someException = new Exception("this is an exception");
     CrsCoordinate outputCoordinateNull = null;
     ArgumentException exception = Assert.Throws<ArgumentException>(
         () => {
             CreateCrsTransformationResult(
                 outputCoordinateNull,
                 someException,
                 // when there is an exception as above then the below success SHOULD BE false !
                 true
             );
         }
         ,
         "unvalid TransformResult object construction should throw exception when an exception parameter is combined with success true"
     );
 }
Ejemplo n.º 30
0
 private CrsTransformationResult CreateCrsTransformationResult(
     CrsCoordinate outputCoordinate,
     ICrsTransformationAdapter adapter,
     CrsCoordinate inputCoordinateNotUsedInThisTest
 ) {
     Exception exceptionNull = null;
     bool isSuccessTrue = true;
     return CrsTransformationResult._CreateCrsTransformationResult(
         inputCoordinateNotUsedInThisTest,
         outputCoordinate,
         exceptionNull,
         isSuccessTrue,
         adapter,
         CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List<CrsTransformationResult>())
     );
 }