Beispiel #1
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));
        }
        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
            }
        }
Beispiel #3
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_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
                );
        }
Beispiel #5
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 crsTransformationAdapterSubtypesCode()
        {
            // The below used code is implemented with F#
            // which normally uses explicit interfaces.
            // The F# code requires some additional coding
            // to make the implicit interfaces work as below
            // i.e. the methods can be invoked not only with
            // an interface typed object but also with
            // an object typed with some subtype (class)

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

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

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

            i.Transform(null, 123);
            i.TransformToCoordinate(null, 123);
        }
        public void TransformResult_FromRT90_ToSweref99()
        {
            CrsTransformationResult result = crsTransformationAdapter.Transform(coordinateRT90, epsgSweref99);

            AssertTransformationResultSuccess(
                result,
                coordinateRT90,
                coordinateSweref99,
                crsTransformationAdapter,
                maxMeterDifferenceForSuccessfulTest
                );

            // testing the same transform as above but with the overloaded
            // method taking a string as last parameter instead of integer
            AssertTransformationResultSuccess(
                crsTransformationAdapter.Transform(coordinateRT90, crsCodeSweref99),
                coordinateRT90,
                coordinateSweref99,
                crsTransformationAdapter,
                maxMeterDifferenceForSuccessfulTest
                );

            // testing the same transform as above but with the overloaded
            // method taking a string as last parameter instead of string or integer
            AssertTransformationResultSuccess(
                crsTransformationAdapter.Transform(coordinateRT90, CrsIdentifierFactory.CreateFromEpsgNumber(epsgSweref99)),
                coordinateRT90,
                coordinateSweref99,
                crsTransformationAdapter,
                maxMeterDifferenceForSuccessfulTest
                );
        }
Beispiel #8
0
        public void method2()
        {
            int           epsgNumber = 4326;
            string        crsCode    = "EPSG:" + epsgNumber;
            CrsIdentifier crsIdentifier; // namespace Programmerare.CrsTransformations.Identifier

            crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(epsgNumber);
            // Alternative:
            crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode(crsCode);

            double latitude  = 59.330231;
            double longitude = 18.059196;

            CrsCoordinate crsCoordinate; // namespace Programmerare.CrsTransformations.Coordinate

            // All the below methods are alternatives for creating the same coordinate
            // with the above latitude/longitude and coordinate reference system.
            // No class or object is used for the methods below because of the following static import:
            // using static Programmerare.CrsTransformations.Coordinate.CrsCoordinateFactory;
            crsCoordinate = LatLon(latitude, longitude, epsgNumber);
            crsCoordinate = LatLon(latitude, longitude, crsCode);
            crsCoordinate = LatLon(latitude, longitude, crsIdentifier);

            crsCoordinate = LonLat(longitude, latitude, epsgNumber);
            crsCoordinate = LonLat(longitude, latitude, crsCode);
            crsCoordinate = LonLat(longitude, latitude, crsIdentifier);

            crsCoordinate = YX(latitude, longitude, epsgNumber);
            crsCoordinate = YX(latitude, longitude, crsCode);
            crsCoordinate = YX(latitude, longitude, crsIdentifier);

            crsCoordinate = XY(longitude, latitude, epsgNumber);
            crsCoordinate = XY(longitude, latitude, crsCode);
            crsCoordinate = XY(longitude, latitude, crsIdentifier);

            crsCoordinate = NorthingEasting(latitude, longitude, epsgNumber);
            crsCoordinate = NorthingEasting(latitude, longitude, crsCode);
            crsCoordinate = NorthingEasting(latitude, longitude, crsIdentifier);

            crsCoordinate = EastingNorthing(longitude, latitude, epsgNumber);
            crsCoordinate = EastingNorthing(longitude, latitude, crsCode);
            crsCoordinate = EastingNorthing(longitude, latitude, crsIdentifier);

            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, epsgNumber);
            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsCode);
            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsIdentifier);

            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, epsgNumber);
            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsCode);
            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsIdentifier);

            CrsIdentifier           targetCrs = CrsIdentifierFactory.CreateFromEpsgNumber(3006);
            CrsTransformationResult crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, targetCrs);
            // see more example code further down in this webpage
        }
        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 Transform_ShouldReturnFirstResult_WhenUsingFirstSuccessCompositeAdapter()
        {
            ICrsTransformationAdapter firstSuccessCompositeAdapter = crsTransformationAdapterCompositeFactory.CreateCrsTransformationFirstSuccess(
                // note that DotSpatial should be the first item in the below list defined in the baseclass,
                // and therefore DotSpatial should be the implementation providing the result
                base.allAdapters
                );
            CrsTransformationResult firstSuccessResult = firstSuccessCompositeAdapter.Transform(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.IsNotNull(firstSuccessResult);
            Assert.IsTrue(firstSuccessResult.IsSuccess);
            Assert.AreEqual(1, firstSuccessResult.TransformationResultChildren.Count);

            CrsCoordinate coordinateReturnedByCompositeAdapterFirstSuccess = firstSuccessResult.OutputCoordinate;
            // The above result of the composite should be equal to the result of DotSpatial since it
            // is first in the list of parameters to the constructor and it should produce a result for
            // the input coordinates ... so therefore below assert against the direct result of DotSpatial
            CrsCoordinate coordinateResultWhenUsingDotSpatial = adapterDotSpatial.TransformToCoordinate(wgs84coordinate, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            Assert.AreEqual(
                coordinateResultWhenUsingDotSpatial,
                coordinateReturnedByCompositeAdapterFirstSuccess
                );
        }
Beispiel #11
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));
        }