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 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
            };
        }
        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);
        }
    private void TransformToCoordinate_ShouldReturnEqualCoordinates_WhenTransformingBetweenTwoKnownCoordinatesToAndFromEachOther(
        ICrsTransformationAdapter crsTransformationAdapter,
        int epsgNumber1, int epsgNumber2,
        double yLat1, double xLon1,
        double yLat2, double xLon2,
        string descriptionPlace
    ) {
        string description = descriptionPlace + " , implementation: " + crsTransformationAdapter.AdapteeType;
        CrsCoordinate coordinate1 = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLon1, yLat1, epsgNumber1);
        CrsCoordinate coordinate2 = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLon2, yLat2, epsgNumber2);
        CrsCoordinate outputForCoordinate1 = crsTransformationAdapter.TransformToCoordinate(coordinate1, epsgNumber2);
        CrsCoordinate outputForCoordinate2 = crsTransformationAdapter.TransformToCoordinate(coordinate2, epsgNumber1);

        double delta = GetDeltaValueForComparisons(epsgNumber2);
        Assert.AreEqual(coordinate2.XEastingLongitude, outputForCoordinate1.XEastingLongitude, delta, description);
        Assert.AreEqual(coordinate2.YNorthingLatitude, outputForCoordinate1.YNorthingLatitude, delta, description);

        delta = GetDeltaValueForComparisons(epsgNumber1);
        Assert.AreEqual(coordinate1.XEastingLongitude, outputForCoordinate2.XEastingLongitude, delta, description);
        Assert.AreEqual(coordinate1.YNorthingLatitude, outputForCoordinate2.YNorthingLatitude, delta, description);
    }
    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);
    }
    private void TransformToCoordinate_ShouldReturnCorrectSweref99TMcoordinate_WhenTransformingFromWgs84(
        ICrsTransformationAdapter crsTransformationAdapter
    ) {
        // This test is using the coordinates of Stockholm Centralstation (Sweden)
        // https://kartor.eniro.se/m/03Yxp
        // WGS84 decimal (lat, lon)
        // 59.330231, 18.059196
        // SWEREF99 TM (nord, öst)
        // 6580822, 674032

        double wgs84Lat = 59.330231;
        double wgs84Lon = 18.059196;

        double sweref99_Y_expected = 6580822;
        double sweref99_X_expected = 674032;

        CrsCoordinate inputCoordinate = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(wgs84Lon, wgs84Lat, base.epsgNumberForWgs84);
        CrsCoordinate outputCoordinate = crsTransformationAdapter.TransformToCoordinate(inputCoordinate, base.epsgNumberForSweref99TM);
        Assert.AreEqual(sweref99_Y_expected, outputCoordinate.YNorthingLatitude, 0.5);
        Assert.AreEqual(sweref99_X_expected, outputCoordinate.XEastingLongitude, 0.5);
    }
 public void TransformToCoordinate_ShouldBePossibleToInvokeAndProduceTheSameResult_WhenTheInstanceIsTypedWithTheClassOrTheInterfaceSubTypes() {
     // Before the git commit when this test method 
     // and this comment was added, only the below a4 object
     // could invoke the method 'TransformToCoordinate'.
     // (because of F# explicit interfaces)
     // The other objects a1, a2 and a3 now also can invoke
     // the same method because of the "implicit interfaces"
     // implementation which was added in the same git commit as 
     // this comment and test method
     CrsTransformationAdapterMightyLittleGeodesy a1 = new CrsTransformationAdapterMightyLittleGeodesy();
     CrsTransformationAdapterBaseLeaf a2 = a1;
     CrsTransformationAdapterBase a3     = a1;
     ICrsTransformationAdapter a4        = a1;
     CrsCoordinate c1, c2, c3, c4;
     c1 = a1.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM);
     c2 = a2.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM);
     c3 = a3.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM);
     c4 = a4.TransformToCoordinate(validInputCoordinate, epsgNumberForSweref99TM);
     Assert.AreEqual(c1, c2);
     Assert.AreEqual(c1, c3);
     Assert.AreEqual(c1, c4);
 }
    private void TransformToCoordinate_ShouldReturnTheSameCoordinate_WhenTransformingWithTwoDifferentImplementations(
        ICrsTransformationAdapter crsTransformationAdapter1,
        ICrsTransformationAdapter crsTransformationAdapter2,
        CrsCoordinate inputCoordinate,
        int epsgNumberForOutputCoordinate
    ) {
        double delta = GetDeltaValueForComparisons(epsgNumberForOutputCoordinate);

        CrsCoordinate outputCoordinate1 = crsTransformationAdapter1.TransformToCoordinate(inputCoordinate, epsgNumberForOutputCoordinate);
        CrsCoordinate outputCoordinate2 = crsTransformationAdapter2.TransformToCoordinate(inputCoordinate, epsgNumberForOutputCoordinate);

        //Supplier<String> errorMessageLongitude = () -> "delta used: " + delta + " and the diff was " + Math.Abs(outputCoordinate1.XEastingLongitude - outputCoordinate2.XEastingLongitude);
        //Supplier<String> errorMessageLatitude = () -> "delta used: " + delta + " and the diff was " + Math.Abs(outputCoordinate1.YNorthingLatitude - outputCoordinate2.YNorthingLatitude);
        //Assert.AreEqual(outputCoordinate1.XEastingLongitude(), outputCoordinate2.getXEastingLongitude(), delta, errorMessageLongitude);
        //Assert.AreEqual(outputCoordinate1.YNorthingLatitude(), outputCoordinate2.getYNorthingLatitude(), delta, errorMessageLatitude);
        //Assert.AreEqual(outputCoordinate1.CrsIdentifier().getEpsgNumber(), outputCoordinate2.getCrsIdentifier().getEpsgNumber());
        string errorMessageLongitude = "delta used: " + delta + " and the diff was " + Math.Abs(outputCoordinate1.XEastingLongitude - outputCoordinate2.XEastingLongitude);
        string  errorMessageLatitude = "delta used: " + delta + " and the diff was " + Math.Abs(outputCoordinate1.YNorthingLatitude - outputCoordinate2.YNorthingLatitude);
        Assert.AreEqual(outputCoordinate1.XEastingLongitude, outputCoordinate2.XEastingLongitude, delta, errorMessageLongitude);
        Assert.AreEqual(outputCoordinate1.YNorthingLatitude, outputCoordinate2.YNorthingLatitude, delta, errorMessageLatitude);
        Assert.AreEqual(outputCoordinate1.CrsIdentifier.EpsgNumber, outputCoordinate2.CrsIdentifier.EpsgNumber);
    }
        public void Transform_FromWgs84_ToSweref99()
        {
            resultSweref99 = crsTransformationAdapter.TransformToCoordinate(coordinateWgs84, epsgSweref99);
            AssertCoordinateResult(
                resultSweref99,
                coordinateSweref99,
                maxMeterDifferenceForSuccessfulTest
                );

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

            // 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(coordinateWgs84, CrsIdentifierFactory.CreateFromEpsgNumber(epsgSweref99)),
                coordinateSweref99,
                maxMeterDifferenceForSuccessfulTest
                );
        }