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 ); }
public void Transform_FromSweref99_ToWgs84() { resultWgs84 = crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, epsgWGS84); AssertCoordinateResult( resultWgs84, coordinateWgs84, maxLatLongDifferenceForSuccessfulTest ); // testing the same transform as above but with the overloaded // method taking a string as last parameter instead of integer AssertCoordinateResult( crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, crsCodeWGS84), coordinateWgs84, maxLatLongDifferenceForSuccessfulTest ); // testing the same transform as above but with the overloaded // method taking a string as last parameter instead of string or integer AssertCoordinateResult( crsTransformationAdapter.TransformToCoordinate(coordinateSweref99, CrsIdentifierFactory.CreateFromEpsgNumber(epsgWGS84)), coordinateWgs84, maxLatLongDifferenceForSuccessfulTest ); }
public void CrsIdentifierFactory_ShouldThrowException_WhenEpsgNumberIsNegative() { ArgumentException exception = Assert.Throws<ArgumentException>( () => { CrsIdentifierFactory.CreateFromEpsgNumber(-1); // should fail } , "EPSG must not be negative" ); AssertExceptionMessageWhenArgumentWasNullOrEmptyString(exception, "non-positive"); }
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 crsIdentifierCode() { // public factory methods: crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(4326); crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode("EPSG:4326"); // public properties: crsCode = crsIdentifier.CrsCode; epsgNumber = crsIdentifier.EpsgNumber; isEpsgCode = crsIdentifier.IsEpsgCode; }
public void CrsIdentifier_ShouldReturnEpsgNumberAndEpsgPrefixedCrsCodeAndBeConsideredAsEpsg_WhenCreatedFromEpsgNumber() { int inputEpsgNumber = 3006; // No validation that the number is actually an existing EPSG but any positive integer // is assumed to be a EPSG number CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(inputEpsgNumber); Assert.AreEqual( inputEpsgNumber, // expected crsIdentifier.EpsgNumber ); Assert.AreEqual(GetCrsCodeIncludingUppercasedEpsgPrefix(inputEpsgNumber), crsIdentifier.CrsCode); Assert.AreEqual(true, crsIdentifier.IsEpsgCode); }
public void CrsIdentifier_ShouldNotBeEqual_WhenDifferentEpsgNumber() { Assert.AreNotEqual( CrsIdentifierFactory.CreateFromEpsgNumber(123), CrsIdentifierFactory.CreateFromEpsgNumber(124) ); }
public void CrsIdentifiers_ShouldBeEqual_WhenCreatedFromEpsgNumberAndCorrespondingCrsCode() { CrsIdentifier fromEpsgNumber = CrsIdentifierFactory.CreateFromEpsgNumber(3006); CrsIdentifier fromCrsCode = CrsIdentifierFactory.CreateFromCrsCode(" epsg:3006 "); Assert.AreEqual(fromEpsgNumber, fromCrsCode); Assert.AreEqual(fromEpsgNumber.GetHashCode(), fromCrsCode.GetHashCode()); }
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 Coordinates_ShouldBeEqual_WhenUsingCrsIdentifierAndDifferentFactoryMethodsWithParametersInDifferentOrder() { CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(3006); CrsCoordinate coordinate1 = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, crsIdentifier); CrsCoordinate coordinate2 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, crsIdentifier); AssertEqualCoordinates(coordinate1, coordinate2); }
public void Coordinates_ShouldBeEqual_WhenCreatedWithTheSameValuesButDifferentFactoryMethods() { CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(epsgNumberSweref99); string epsgCode = EpsgPrefix + epsgNumberSweref99; CrsCoordinate expectedCoordinate = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, epsgNumberSweref99); // all should be equal to each other, so one of them was chosen above // as the "expected" and then the others are compared with it in the below assertions // ----------------------------------------------------------------------- // the last parameter (epsgNumber) is an integer in the first below assertions: AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LonLat(xLongitude, yLatitude, epsgNumberSweref99) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.XY(xLongitude, yLatitude, epsgNumberSweref99) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, epsgNumberSweref99) ); // the below four assertions are using x/y values in the opposite order // compared to the above three assertions AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, epsgNumberSweref99) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LatLon(yLatitude, xLongitude, epsgNumberSweref99) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.YX(yLatitude, xLongitude, epsgNumberSweref99) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, epsgNumberSweref99) ); // ----------------------------------------------------------------------- // epsg code (string parameter) is the last parameter below AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LonLat(xLongitude, yLatitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.XY(xLongitude, yLatitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, epsgCode) ); // the below four assertions are using x/y values in the opposite order // compared to the above four assertions AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LatLon(yLatitude, xLongitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.YX(yLatitude, xLongitude, epsgCode) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, epsgCode) ); // ----------------------------------------------------------------------- // crsIdentifier obkect is the last parameter below AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LonLat(xLongitude, yLatitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.XY(xLongitude, yLatitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, crsIdentifier) ); // the below four assertions are using x/y values in the opposite order // compared to the above four assertions AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.LatLon(yLatitude, xLongitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.YX(yLatitude, xLongitude, crsIdentifier) ); AssertEqualCoordinates(expectedCoordinate, CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, crsIdentifier) ); }
public void FindPotentialBuggyImplementationsHelper( int minEpsgCrsCode, int maxEpsgCrsCode, double?optionalDelta = null ) { int numberIfEpsgCodesToConsiderInIteration = maxEpsgCrsCode - minEpsgCrsCode; bool manyWillBeIterated = numberIfEpsgCodesToConsiderInIteration > 100; double deltaDiffToUse = manyWillBeIterated ? deltaDiff : double.MinValue; if (optionalDelta.HasValue) { deltaDiffToUse = optionalDelta.Value; } var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create(); CrsTransformationAdapterComposite crsTransformationComposite = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian(); verifyThreeImplementations(crsTransformationComposite); // to make sure that the above factory really creates an object which will use three implementations IList <CrsTransformationResult> transformResultsWithLargeDifferences = new List <CrsTransformationResult>(); CrsIdentifier wgs84 = CrsIdentifierFactory.CreateFromEpsgNumber(EpsgNumber.WORLD__WGS_84__4326); var stopWatch = new Stopwatch(); stopWatch.Start(); IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile(); int seconds = (int)stopWatch.Elapsed.TotalSeconds; WriteLine("Time for reading the content of the input file: " + seconds); stopWatch.Restart(); int totalNumberOfSeconds; WriteLine("number of rows to iterate: " + coordinatesFromGeneratedCsvFile.Count); for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++) { if (manyWillBeIterated && (i % 100 == 0)) { //WriteLine("number of rows iterated so far: " + i); totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds; //WriteLine("Number of seconds so far: " + totalNumberOfSeconds); // if (i > 50) break; } EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i]; if ( epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode < minEpsgCrsCode || epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode > maxEpsgCrsCode ) { continue; } if (!manyWillBeIterated) { //Console.WriteLine("iterated epsgCrsCode: " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode); } CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(epsgCrsAndAreaCodeWithCoordinates.centroidY, epsgCrsAndAreaCodeWithCoordinates.centroidX, wgs84); CrsTransformationResult resultOutputFromWgs4 = crsTransformationComposite.Transform(coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode); if (!resultOutputFromWgs4.IsSuccess) { continue; } CrsTransformationResult resultWhenTransformedBackToWgs84 = crsTransformationComposite.Transform(resultOutputFromWgs4.OutputCoordinate, wgs84); if (!resultWhenTransformedBackToWgs84.IsSuccess) { continue; } CrsTransformationResultStatistic crsTransformationResultStatistic = resultWhenTransformedBackToWgs84.CrsTransformationResultStatistic; Assert.IsNotNull(crsTransformationResultStatistic); Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable); if ( crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude > deltaDiffToUse || crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude > deltaDiffToUse ) { transformResultsWithLargeDifferences.Add(resultWhenTransformedBackToWgs84); } else { if (!manyWillBeIterated) { //Console.WriteLine("NOT 'big' difference for EPSG " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode); int count = crsTransformationComposite.TransformationAdapterChildren.Count; //Console.WriteLine("Number of implementations not having big difference: " + count); } } } WriteLine("Number of iterated rows/coordinates: " + coordinatesFromGeneratedCsvFile.Count); WriteLine("Number of results with 'large' differences: " + transformResultsWithLargeDifferences.Count); for (int i = 0; i < transformResultsWithLargeDifferences.Count; i++) { CrsTransformationResult transformResult = transformResultsWithLargeDifferences[i]; WriteLine("----------------------------------------"); WriteLine("epsg " + transformResult.InputCoordinate.CrsIdentifier.CrsCode); WriteLine("MaxDiffYLatitude : " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude); WriteLine("MaxDiffYLongitude: " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForXEastingLongitude); IList <CrsTransformationResult> subResults = transformResult.TransformationResultChildren; for (int j = 0; j < subResults.Count; j++) { CrsTransformationResult subTransformResult = subResults[j]; if (subTransformResult.IsSuccess) { WriteLine(subTransformResult.OutputCoordinate + " , " + subTransformResult.CrsTransformationAdapterResultSource.AdapteeType); } } } }