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); }
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); }
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 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 SetUp() { weightFactory = CrsTransformationAdapterWeightFactory.Create(); crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); }
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 }; }
public void Setup() { weightFactory = CrsTransformationAdapterWeightFactory.Create(); crsTransformationAdapterInstanceNotNull = new CrsTransformationAdapterMightyLittleGeodesy(); }
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() { coordinateWithExpectedWeightedValues = CreateWeightedValue(); weightFactory = CrsTransformationAdapterWeightFactory.Create(); }
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); }