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); }
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 LeafAdapters_ShouldBeEqual_WhenTheSameTypeAndConfiguration() { var dotSpatial1 = new CrsTransformationAdapterDotSpatial(); var dotSpatial2 = new CrsTransformationAdapterDotSpatial(); Assert.AreEqual( dotSpatial1, dotSpatial2 ); Assert.AreEqual( dotSpatial1.GetHashCode(), dotSpatial2.GetHashCode() ); Assert.AreEqual( dotSpatial, // created in the Setup method dotSpatial1 ); Assert.AreEqual( dotSpatial.GetHashCode(), dotSpatial1.GetHashCode() ); var mightyLittleGeodesy2 = new CrsTransformationAdapterMightyLittleGeodesy(); Assert.AreEqual( mightyLittleGeodesy, // created in the Setup method mightyLittleGeodesy2 ); Assert.AreEqual( mightyLittleGeodesy.GetHashCode(), mightyLittleGeodesy2.GetHashCode() ); var ProjNet2 = new CrsTransformationAdapterProjNet(); Assert.AreEqual( projNet, // created in the Setup method ProjNet2 ); Assert.AreEqual( projNet.GetHashCode(), ProjNet2.GetHashCode() ); }
public void TestBehaviourWhenNoCachingIsChosen() { cacheTestTransformationAdapterProjNet = new CrsTransformationAdapterProjNet(CrsCachingStrategy.NO_CACHING); Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( cacheTestForOutputEpsgNumberNotExisting ) ); Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( EpsgNumber.SWEDEN__SWEREF99_TM__3006 ) ); // The transform method below may potentially trigger // the used epsg code (the second parameter) to become cached // (but that behaviour depends on the caching strategy) cacheTestTransformationAdapterProjNet.Transform( cacheTestInputCoordinateWgs84, cacheTestForOutputEpsgNumberNotExisting ); // The above output CRS was a non-existing EPSG number // but below is an existing EPSG number used. cacheTestTransformationAdapterProjNet.Transform( cacheTestInputCoordinateWgs84, EpsgNumber.SWEDEN__SWEREF99_TM__3006 ); // Neither of the above are still not cached since caching is disabled Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( cacheTestForOutputEpsgNumberNotExisting ) ); Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( EpsgNumber.SWEDEN__SWEREF99_TM__3006 ) ); }
public void SetUp() { crsTransformationAdapterProjNetwithNoConstructorParameters = new CrsTransformationAdapterProjNet(); base.SetUpbase( crsTransformationAdapterProjNetwithNoConstructorParameters, CrsTransformationAdapteeType.LEAF_PROJ_NET_2_0_0, // TODO: Obsolete comment maybe after upgrade to 2.0.0: // The implementation ProjNet // is currently (version 1.4.1) // producing bad results when transforming // to the Swedish CRS "RT90 2.5 gon V" // https://github.com/NetTopologySuite/ProjNet/issues/38 // However, the results for those CRS have been improved by // using other CRS definitions for those CRS. // See further comments in the file/type EmbeddedResourceFileWithCRSdefinitions // in the project Programmerare.CrsTransformations.Adapter.ProjNet 0.5, // maxMeterDifferenceForSuccessfulTest 0.00001 // maxLatLongDifferenceForSuccessfulTest ); // The implementation ProjNet // does not contain a lot of hardcoded definitions // of coordinate systems but instead it is shipped with a CSV file // with such definitions, and their website shows // example code of how to parse it, which indeed has // been implemented in the adapter project. // However, for performance reason you do not want to read // the CSV file every time an EPSG code is looked up. // For that reason, caching has been implemented // as an option, which is tested in this class // (plus all the other tests not related to caching which is inherited from the base test class) cacheTestForOutputEpsgNumberNotExisting = 123; // EPSG code 123 does NOT exist cacheTestInputCoordinateWgs84 = CrsCoordinateFactory.LatLon(60, 18); cacheTestTransformationAdapterProjNet = new CrsTransformationAdapterProjNet(); }
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) }); }
private void VerifyExpectedCachingBehaviour( CrsCachingStrategy crsCachingStrategy ) { cacheTestTransformationAdapterProjNet = new CrsTransformationAdapterProjNet(crsCachingStrategy); Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( cacheTestForOutputEpsgNumberNotExisting ) ); // The transform method below may potentially trigger // the used epsg code (the second parameter) to become cached // (but that behaviour depends on the caching strategy // i.e. it must not be NO_CACHING) cacheTestTransformationAdapterProjNet.Transform( cacheTestInputCoordinateWgs84, cacheTestForOutputEpsgNumberNotExisting ); // It should be true below. // Indeed the lookup is cached even though it is a non-existin // EPSG number (i.e. "null" is cached) // since you do likely not want to read the file // many times (if you have specified that you want caching) // just to get null again, so therefore the null value // is also cached as a kind of value in the semantic of the below method Assert.IsTrue( cacheTestTransformationAdapterProjNet.IsEpsgCached( cacheTestForOutputEpsgNumberNotExisting ) ); if (crsCachingStrategy == CrsCachingStrategy.CACHE_ALL_EPSG_CRS_CODES) { // The EPSG number below have not been directly used yet in this test method // (e.g. as the input coordinate or the output CRS for a transformation) // but since everything (according to the above if statement we are now within) // should have been cached it should be cached already anyway now Assert.IsTrue( cacheTestTransformationAdapterProjNet.IsEpsgCached( EpsgNumber.SWEDEN__SWEREF99_TM__3006 ) ); } else if (crsCachingStrategy == CrsCachingStrategy.CACHE_EPSG_CRS_CODE_WHEN_FIRST_USED) { Assert.IsFalse( cacheTestTransformationAdapterProjNet.IsEpsgCached( EpsgNumber.SWEDEN__SWEREF99_TM__3006 ) ); // but after a transformation below it should be cached cacheTestTransformationAdapterProjNet.Transform( cacheTestInputCoordinateWgs84, EpsgNumber.SWEDEN__SWEREF99_TM__3006 ); Assert.IsTrue( cacheTestTransformationAdapterProjNet.IsEpsgCached( EpsgNumber.SWEDEN__SWEREF99_TM__3006 ) ); } }
public void Test_ProjNet4GeoAPI_ProjNet_issue_38() { // the purpose of this test was to verify if the reported issue for ProjNet4GeoAPI 1.4 // has been fixed for ProjNet 2.0 or if it is still necessary to use an // additional CSV file (EmbeddedResourceFileWithCRSdefinitions) with RT90 definitions as in the test code below // https://github.com/NetTopologySuite/ProjNet4GeoAPI/issues/38 // tested transformation from WGS84 (EPSG 4326) to "RT90 2.5 gon V" (EPSG 3021) ... // input WGS84 coordinate: // Longitude / Latitude: 18.059196 , 59.330231 // The expected result should be the following: // X / Y: 1628294 , 6580994 const double inputLatitudeWgs84 = 59.330231; const double inputLongitudeWgs84 = 18.059196; const double expectedOutput_X_RT90 = 1628294; const double expectedOutput_Y_RT90 = 6580994; const int epsg_3021_RT9025gonv = EpsgNumber.SWEDEN__2_5_GON_W__RT90_2_5_GON_V__3021;// RT90 2.5 gon V const int epsg_4326_WGS84 = EpsgNumber.WORLD__WGS_84__4326; CrsCoordinate inputCoordinateWgs84 = CrsCoordinateFactory.LatLon( inputLatitudeWgs84, inputLongitudeWgs84, epsg_4326_WGS84 ); CrsCoordinate expectedCoordinateRT9025gonv = CrsCoordinateFactory.YX( expectedOutput_Y_RT90, expectedOutput_X_RT90, epsg_3021_RT9025gonv ); ICrsTransformationAdapter crsTransformationAdapter = new CrsTransformationAdapterProjNet( CrsCachingStrategy.CACHE_ALL_EPSG_CRS_CODES , new SridReader( new List <EmbeddedResourceFileWithCRSdefinitions> { //EmbeddedResourceFileWithCRSdefinitions.STANDARD_FILE_SHIPPED_WITH_ProjNet4GeoAPI_1_4_1, //// When using ProjNet4GeoAPI version 1.4 it is necessary with the below "patch" file //// for RT90 but hopefully will not be needed in the next version //EmbeddedResourceFileWithCRSdefinitions.SIX_SWEDISH_RT90_CRS_DEFINITIONS_COPIED_FROM_SharpMap_SpatialRefSys_xml, // Previously (with version 1.4) the above two files were needed but // with version 2 the test succeeds with the CRS/SRID file whipped with that version EmbeddedResourceFileWithCRSdefinitions.STANDARD_FILE_SHIPPED_WITH_ProjNet_2_0_0 } ) ); CrsCoordinate actualCoordinateRT9025gonv = crsTransformationAdapter.TransformToCoordinate( inputCoordinateWgs84, epsg_3021_RT9025gonv ); const double maxDeltaDifference = 0.2; Assert.AreEqual( expectedCoordinateRT9025gonv.Y, actualCoordinateRT9025gonv.Y, maxDeltaDifference ); Assert.AreEqual( expectedCoordinateRT9025gonv.X, actualCoordinateRT9025gonv.X, maxDeltaDifference ); }