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 ); }
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 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(); }
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 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 } }
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); }
// ------------------------------------------------------------------------------------- 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)); }
public TestResult( ICrsTransformationAdapter adapter, long totalNumberOfSecondsForAllTransformations, IList <TestResultItem> testResultItems ) { this.Adapter = adapter; this.TotalNumberOfSecondsForAllTransformations = totalNumberOfSecondsForAllTransformations; this.TestResultItems = testResultItems; }
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); }
private FileInfo GetFileForRegressionResults( ICrsTransformationAdapter adapter, string fileNameSuffixExcludingExtension ) { DirectoryInfo directoryForRegressionsResults = GetDirectoryForRegressionsResults(); FileInfo file = new FileInfo( Path.Combine( directoryForRegressionsResults.FullName, adapter.ShortNameOfImplementation + fileNameSuffixExcludingExtension + ".csv") ); return(file); }
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); }
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); }
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>()) ); }
public void ListOfHardcodedClassnames_ShouldBeCreateableAsNonNullCrsTransformationAdapters() { IList <String> hardcodedClassNamesForAllKnownImplementations = crsTransformationAdapterLeafFactory.GetClassNamesForAllImplementations(); foreach (string hardcodedClassNameForKnownImplementation in hardcodedClassNamesForAllKnownImplementations) { ICrsTransformationAdapter crsTransformationAdapter = crsTransformationAdapterLeafFactory.GetCrsTransformationAdapter( hardcodedClassNameForKnownImplementation ); VerifyThatTheCreatedAdapterIsRealObject(crsTransformationAdapter); Assert.That( actualClassNamesForAllKnownImplementations, Contains.Item( crsTransformationAdapter.LongNameOfImplementation ) ); } }
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_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 SetUpBase() { // The setup code below creates four coordinates // representing results from four implementations. double lat1 = 59.330231; double lat2 = 59.330232; double lat3 = 59.330233; double lat4 = 59.330239; double latMean = (lat2 + lat3 ) / 2; double latAverage = (lat1 + lat2 + lat3 + lat4) / 4; expectedLatDiffMax = lat4-lat1; double lon1 = 18.059192; double lon2 = 18.059193; double lon3 = 18.059194; double lon4 = 18.059198; double lonMean = (lon2 + lon3 ) / 2; double lonAverage = (lon1 + lon2 + lon3 + lon4) / 4; expectedLonDiffMax = lon4-lon1; expectedCoordinateMean = CrsCoordinateFactory.LatLon(latMean, lonMean); expectedCoordinateAverage = CrsCoordinateFactory.LatLon(latAverage, lonAverage); CrsCoordinate outputCoordinate1 = CrsCoordinateFactory.LatLon(lat1, lon1); CrsCoordinate outputCoordinate2 = CrsCoordinateFactory.LatLon(lat2, lon2); CrsCoordinate outputCoordinate3 = CrsCoordinateFactory.LatLon(lat3, lon3); CrsCoordinate outputCoordinate4 = CrsCoordinateFactory.LatLon(lat4, lon4); var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); compositeAdapterForResultTest = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(); inputCoordinateNotUsedInStatisticsTest = CrsCoordinateFactory.LatLon(0.0, 0.0); // input, not used here in this test outputCoordinateNotUsedInStatisticsTest = inputCoordinateNotUsedInStatisticsTest; ICrsTransformationAdapter leafAdapterForResultTest = new CrsTransformationAdapterDotSpatial(); // Can use the same above adapter for all parts below. Not used much except that the object must be some leaf listOfSubresultsForStatisticsTest = new List<CrsTransformationResult>{ CreateCrsTransformationResult(outputCoordinate1, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest), CreateCrsTransformationResult(outputCoordinate2, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest), CreateCrsTransformationResult(outputCoordinate3, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest), CreateCrsTransformationResult(outputCoordinate4, leafAdapterForResultTest, inputCoordinateNotUsedInStatisticsTest) }; }
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 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 AssertTransformationResultSuccess( CrsTransformationResult result, CrsCoordinate inputCoordinate, CrsCoordinate expectedOutputCoordinate, ICrsTransformationAdapter crsTransformationAdapterSource, double maxDeltaDifference ) { Assert.IsNotNull(result); Assert.IsTrue(result.IsSuccess); Assert.IsNull(result.Exception); AssertCoordinateResult( result.OutputCoordinate, expectedOutputCoordinate, maxDeltaDifference ); 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 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 ); }
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)); }
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() { Console.WriteLine("LargerCSharpeExample starts"); // Some terminology regarding the names used in the below code example: // "CRS" = Coordinate Reference System // "WGS84" is the most frequently used coordinate system (e.g. the coordinates usually used in a GPS) // "SWEREF99TM" is the official coordinate system used by authorities in Sweden // "EPSG" = "European Petroleum Survey Group" was (but the EPSG name is still often used) // an organization defining CRS with integer numbers e.g. 4326 for WGS84 or 3006 for SWEREF99TM int epsgWgs84 = EpsgNumber.WORLD__WGS_84__4326; int epsgSweRef = EpsgNumber.SWEDEN__SWEREF99_TM__3006; // The above "EpsgNumber" class with LOTS OF constants (and more constants classes) have been generated, // using "FreeMarker" and database downloaded from EPSG ( http://www.epsg.org or http://www.epsg-registry.org ) // from "crs-transformation-code-generation" in the project https://github.com/TomasJohansson/crsTransformations CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory.LatLon(59.330231, 18.059196, epsgWgs84); // https://kartor.eniro.se/m/03Yxp // SWEREF99TM coordinates (for WGS84 59.330231, 18.059196) // according to Eniro (above URL): 6580822, 674032 (northing, easting) ICrsTransformationAdapter crsTransformationAdapter; // interface with concrete "leaf" implementation or "composite" implementations // This code example is using a "composite" which will use multiple libraries to do the same transformation and then // return a coordinate with the median values (median of the northing values and median of the easting values) crsTransformationAdapter = CrsTransformationAdapterCompositeFactory.Create().CreateCrsTransformationMedian(); // The above factory will try to use those known objects which implements the interface i.e. the number // of "leaf" objects will depend on how many you included as for example NuGet dependencies (three in the above NuGet example) Console.WriteLine("Number of 'leafs' : " + crsTransformationAdapter.TransformationAdapterChildren.Count); // Console output from the above row: // Number of 'leafs' : 3 // Transform the WGS84 coordinate to a SWEREF99TM coordinate: CrsCoordinate centralStockholmSweRef = crsTransformationAdapter.TransformToCoordinate(centralStockholmWgs84, epsgSweRef); Console.WriteLine("Median Composite Northing: " + centralStockholmSweRef.Northing); Console.WriteLine("Median Composite Easting: " + centralStockholmSweRef.Easting); // Console output from the above two rows: // Median Composite Northing: 6580821.99121561 // Median Composite Easting: 674032.357177155 // (and these can be compared with the 'Eniro' values above i.e. '6580822, 674032 (northing, easting)' ) // The coordinate class provides four properties with different names for the same east-west value and // four properties for the same name each north-south value, as below: // Four EQUIVALENT properties: Easting , X , Longitude , XEastingLongitude // Four EQUIVALENT properties: Northing , Y , Latitude , YNorthingLatitude // Regarding the above alternative methods, depending on the desired semantic in your context, you may want to use: // X/Y for a geocentric or cartesian system // Longitude/Latitude for a geodetic or geographic system // Easting/Northing for a cartographic or projected system // xEastingLongitude/yNorthingLatitude for general code handling different types of system // If you want more details for the result you can use the following 'Transform' method: // (instead of the method 'TransformToCoordinate' used above) CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter.Transform(centralStockholmWgs84, epsgSweRef); if(!centralStockholmResultSweRef.IsSuccess) { Console.WriteLine("No coordinate result"); } else { if(centralStockholmResultSweRef.IsReliable( 2, // minimumNumberOfSuccesfulResults 0.01 // maxDeltaValueForXLongitudeAndYLatitude )) { // at least 2 succesful results and the maximal difference in northing or easting is less than 0.01 // (and if you want to know the exact difference you can find it in this code example further down the page) Console.WriteLine("Reliable result"); // according to your chosen parameters to the method 'isReliable' } else { Console.WriteLine("Not reliable result"); } 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)) // When your code is in a context where you only have the result (but not the adapter object) // (e.g. in a method receiving the result as a parameter) // you can get back the object which created the result as below: ICrsTransformationAdapter crsTransformationAdapterResultSource = centralStockholmResultSweRef.CrsTransformationAdapterResultSource; CrsTransformationAdapteeType adapteeType = crsTransformationAdapterResultSource.AdapteeType; Console.WriteLine("adapteeType: " + adapteeType); // console output: COMPOSITE_MEDIAN // The above code row returned an enum which is not really a true adaptee just like the 'composite' is not a true adapter. // However, when iterating (as below) the "leaf" results, // it might be more interesting to keep track of from where the different values originated IList<CrsTransformationResult> transformationResultChildren = centralStockholmResultSweRef.TransformationResultChildren; foreach (CrsTransformationResult crsTransformationResultLeaf in transformationResultChildren) { if(!crsTransformationResultLeaf.IsSuccess) continue; // continue with the next 'leaf' ICrsTransformationAdapter resultAdapter = crsTransformationResultLeaf.CrsTransformationAdapterResultSource; Console.WriteLine(resultAdapter.AdapteeType); // The above code row will output rows like this: // "LEAF_PROJ_NET_4_GEO_API_1_4_1" or "LEAF_MIGHTY_LITTLE_GEODESY_1_0_1" and so on if(!crsTransformationResultLeaf.IsReliable( 2, // minimumNumberOfSuccesfulResults 1000 // maxDeltaValueForXLongitudeAndYLatitude )) { // The above constraint "at least 2 implementations" will always fail because now we are dealing with "leafs" // The above delta value constraint has very high tolerance but it does not matter since // the constraint about the number of implementations will fail Console.WriteLine("Only 'composites' can have more than one result and this is a 'leaf' and thus does not have at least two results"); } Console.WriteLine("Adapter long name: " + resultAdapter.LongNameOfImplementation); // full class name including package Console.WriteLine("Adapter short name: " + resultAdapter.ShortNameOfImplementation); // class name suffix i.e. the unique part // The above "long" names will be for example: // Programmerare.CrsTransformations.Adapter.DotSpatial.CrsTransformationAdapterDotSpatial // Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy.CrsTransformationAdapterMightyLittleGeodesy // The above "short" names will be for example: // DotSpatial // MightyLittleGeodesy Console.WriteLine("adaptee: " + resultAdapter.AdapteeType); // The above row will output for example: // LEAF_DOT_SPATIAL_2_0_0_RC1 // LEAF_MIGHTY_LITTLE_GEODESY_1_0_1 // (note that the version number is included for the adaptees) Console.WriteLine("isComposite: " + resultAdapter.IsComposite); // "False" since we are iterating "leaf" results Console.WriteLine("Coordinate result for " + resultAdapter.AdapteeType + " : " + crsTransformationResultLeaf.OutputCoordinate); // The above row will output these rows when doing the iteration: // Coordinate result for LEAF_DOT_SPATIAL_2_0_0_RC1 : CrsCoordinate(xEastingLongitude=674032.357322213, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) // Coordinate result for LEAF_PROJ_NET_4_GEO_API_1_4_1 : CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99437121, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) // Coordinate result for LEAF_MIGHTY_LITTLE_GEODESY_1_0_1 : CrsCoordinate(xEastingLongitude=674032.357, yNorthingLatitude=6580821.991, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) // Note that the median value for "x" is 674032.357177155 for the above // three values 674032.357 , 674032.357177155 , 674032.357322213 . // That is the same value as was displayed before the iteration of the children/leafs for the median composite. // The same applies for the above "y" i.e. the median is 6580821.99121561 // for the three y values 6580821.991 , 6580821.99121561 , 6580821.99437121 } // The result object also provides convenience methods for the results (which you of course otherwise might calculate by iterating the above results) CrsTransformationResultStatistic crsTransformationResultStatistic = centralStockholmResultSweRef.CrsTransformationResultStatistic; // Note that the initially created composite was a "median composite" returning the median as the main value, // but you can also create an average composite and regardless you can access both the median and the average with the aggregated statistics object: Console.WriteLine("average coordinate: " + crsTransformationResultStatistic.CoordinateAverage); Console.WriteLine("median coordinate: " + crsTransformationResultStatistic.CoordinateMedian); // Console output from the above two rows: // average coordinate: CrsCoordinate(xEastingLongitude=674032.357166456, yNorthingLatitude=6580821.99219561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) // median coordinate: CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006)) Console.WriteLine("MaxDifferenceForXEastingLongitude: " + crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude); Console.WriteLine("MaxDifferenceForYNorthingLatitude: " + crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude); // Output from the above two rows: // MaxDifferenceForXEastingLongitude: 0.000322213280014694 // MaxDifferenceForYNorthingLatitude: 0.00337121076881886 // As you can see in the above iteration, the min and max x values are 674032.357 and 674032.357322213 (and the difference is 0.000322213). // Similarly the min and max y values are 6580821.991 and 6580821.99437121 (and the difference is 0.00337121). // The above two "MaxDifference" methods are used within the implementation of the convenience method 'isReliable' // (also illustrated in this example further above) } // else statement ends Console.WriteLine("LargerCSharpeExample ends"); Console.ReadLine(); } // method ends
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. }