From 9689243b940e6b908db377dee357f422a00129e8 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 16 Feb 2019 19:19:43 +0100 Subject: Make sure that the PJ object returned by proj_create_crs_to_crs() is a proper CoordinateOperation so that we can call proj_get_source_crs() on it for example --- test/unit/gie_self_tests.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 7f9f436b..91a3069c 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -258,6 +258,12 @@ TEST_F(gieTest, proj_create_crs_to_crs) { a = proj_trans(P, PJ_FWD, a); EXPECT_NEAR(a.xy.x, b.xy.x, 1e-9); EXPECT_NEAR(a.xy.y, b.xy.y, 1e-9); + + auto src = proj_get_source_crs(PJ_DEFAULT_CTX, P); + ASSERT_TRUE(src != nullptr); + EXPECT_EQ(proj_get_name(src), std::string("ETRS89 / UTM zone 32N")); + proj_destroy(src); + proj_destroy(P); /* we can also allow PROJ strings as a usable PJ */ -- cgit v1.2.3 From 4c61b3c882c8c47d40c3950f95c640710804835f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 16 Feb 2019 23:06:34 +0100 Subject: Make sure proj_get_source_crs() and proj_get_target_crs() work on 'pseudo' PJ object returned by proj_create_crs_to_crs() when there are several alternatives --- test/unit/gie_self_tests.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 91a3069c..5936791e 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -680,6 +680,18 @@ TEST(gie, proj_create_crs_to_crs_PULKOVO42_ETRS89) { EXPECT_EQ(P->fwd3d, nullptr); EXPECT_EQ(P->fwd4d, nullptr); + // get source CRS even if the P object is in a dummy state + auto src_crs = proj_get_source_crs(PJ_DEFAULT_CTX, P); + EXPECT_TRUE(src_crs != nullptr); + EXPECT_EQ(proj_get_name(src_crs), std::string("Pulkovo 1942(58)")); + proj_destroy(src_crs); + + // get target CRS even if the P object is in a dummy state + auto target_crs = proj_get_target_crs(PJ_DEFAULT_CTX, P); + EXPECT_TRUE(target_crs != nullptr); + EXPECT_EQ(proj_get_name(target_crs), std::string("ETRS89")); + proj_destroy(target_crs); + // Romania c.xyz.x = 45; // Lat c.xyz.y = 25; // Long -- cgit v1.2.3 From a8cbe0c66974871f5a7bd7ef94001ebf461ac7ea Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Sun, 17 Feb 2019 08:42:48 +0100 Subject: Slack tolerance in deg->rad unitconvert test --- test/gie/unitconvert.gie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/gie/unitconvert.gie b/test/gie/unitconvert.gie index 2a56ba59..2e06fe72 100644 --- a/test/gie/unitconvert.gie +++ b/test/gie/unitconvert.gie @@ -26,7 +26,7 @@ accept 1 1 1 1 expect 0.5 0.5 1 1 operation proj=unitconvert xy_in=deg xy_out=rad -tolerance 0.000000000001 +tolerance 0.0000001 accept 1 1 1 1 expect 1 1 1 1 # gie does a rad->deg conversion behind the scenes -- cgit v1.2.3 From e8b2e2a36324006146406fb1fc89ce6ed863807f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Feb 2019 19:40:38 +0100 Subject: Modify the default strategy of researching intermediate CRS to do it only if there is no direct transformation --- test/unit/test_c_api.cpp | 4 ++- test/unit/test_crs.cpp | 66 ++++++++++++++++++++++++++++++-------------- test/unit/test_factory.cpp | 3 +- test/unit/test_operation.cpp | 14 ++++++++-- 4 files changed, 62 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp index 273a04e6..6205a9b8 100644 --- a/test/unit/test_c_api.cpp +++ b/test/unit/test_c_api.cpp @@ -1389,7 +1389,7 @@ TEST_F(CApi, proj_create_operations_with_pivot) { ASSERT_NE(ctxt, nullptr); ContextKeeper keeper_ctxt(ctxt); proj_operation_factory_context_set_allow_use_intermediate_crs( - m_ctxt, ctxt, false); + m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_NEVER); auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); ASSERT_NE(res, nullptr); @@ -1444,6 +1444,8 @@ TEST_F(CApi, proj_create_operations_with_pivot) { m_ctxt, ctxt, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION); proj_operation_factory_context_set_grid_availability_use( m_ctxt, ctxt, PROJ_GRID_AVAILABILITY_IGNORED); + proj_operation_factory_context_set_allow_use_intermediate_crs( + m_ctxt, ctxt, PROJ_INTERMEDIATE_CRS_USE_ALWAYS); auto res = proj_create_operations(m_ctxt, source_crs, target_crs, ctxt); ASSERT_NE(res, nullptr); diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp index 26bcf621..4953529c 100644 --- a/test/unit/test_crs.cpp +++ b/test/unit/test_crs.cpp @@ -3436,8 +3436,12 @@ TEST(crs, boundCRS_crs_link) { EXPECT_TRUE(baseCRS->isEquivalentTo(GeographicCRS::EPSG_4267.get())); EXPECT_TRUE(baseCRS->canonicalBoundCRS() != nullptr); - EXPECT_TRUE(baseCRS->createBoundCRSToWGS84IfPossible(nullptr, false) - ->isEquivalentTo(baseCRS->canonicalBoundCRS().get())); + EXPECT_TRUE( + baseCRS + ->createBoundCRSToWGS84IfPossible( + nullptr, + CoordinateOperationContext::IntermediateCRSUse::NEVER) + ->isEquivalentTo(baseCRS->canonicalBoundCRS().get())); } { @@ -4725,27 +4729,35 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { auto factory = AuthorityFactory::create(dbContext, "EPSG"); { auto crs_4326 = factory->createCoordinateReferenceSystem("4326"); - EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_4326->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_4326); } { auto crs_32631 = factory->createCoordinateReferenceSystem("32631"); - EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_32631->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_32631); } { // Pulkovo 42 East Germany auto crs_5670 = factory->createCoordinateReferenceSystem("5670"); - EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(crs_5670->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), crs_5670); } { // Pulkovo 42 Romania auto crs_3844 = factory->createCoordinateReferenceSystem("3844"); - auto bound = - crs_3844->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_3844->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_3844); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4759,10 +4771,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // Pulkovo 42 Poland auto crs_2171 = factory->createCoordinateReferenceSystem("2171"); - auto bound = - crs_2171->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_2171->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_2171); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4776,10 +4790,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // NTF (Paris) auto crs_4807 = factory->createCoordinateReferenceSystem("4807"); - auto bound = - crs_4807->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_4807->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_4807); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4791,10 +4807,12 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { { // NTF (Paris) / Lambert zone II + NGF-IGN69 height auto crs_7421 = factory->createCoordinateReferenceSystem("7421"); - auto bound = - crs_7421->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs_7421->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs_7421); - EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible(dbContext, false), + EXPECT_EQ(bound->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), bound); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4807,13 +4825,17 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { } { auto crs = createVerticalCRS(); - EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible(dbContext, false), crs); + EXPECT_EQ(crs->createBoundCRSToWGS84IfPossible( + dbContext, + CoordinateOperationContext::IntermediateCRSUse::NEVER), + crs); } { auto factoryIGNF = AuthorityFactory::create(DatabaseContext::create(), "IGNF"); auto crs = factoryIGNF->createCoordinateReferenceSystem("TERA50STEREO"); - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4827,7 +4849,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { auto factoryIGNF = AuthorityFactory::create(DatabaseContext::create(), "IGNF"); auto crs = factoryIGNF->createCoordinateReferenceSystem("PGP50"); - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_NE(bound, crs); auto boundCRS = nn_dynamic_pointer_cast(bound); ASSERT_TRUE(boundCRS != nullptr); @@ -4838,7 +4861,8 @@ TEST(crs, crs_createBoundCRSToWGS84IfPossible) { } { auto crs = factory->createCoordinateReferenceSystem("4269"); // NAD83 - auto bound = crs->createBoundCRSToWGS84IfPossible(dbContext, false); + auto bound = crs->createBoundCRSToWGS84IfPossible( + dbContext, CoordinateOperationContext::IntermediateCRSUse::NEVER); EXPECT_EQ(bound, crs); } } diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index 40728f96..ec59dcbc 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -1612,7 +1612,8 @@ class FactoryWithTmpDatabase : public ::testing::Test { { auto ctxt = CoordinateOperationContext::create(factory, nullptr, 0); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); res = CoordinateOperationFactory::create()->createOperations( srcCRS, targetCRS, ctxt); EXPECT_EQ(res.size(), 1U); diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 103b856c..c7f9cb7d 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -4181,7 +4181,8 @@ TEST(operation, geogCRS_to_geogCRS_context_default) { auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0); ctxt->setSpatialCriterion( CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); // Directly found in database { @@ -4237,7 +4238,8 @@ TEST(operation, geogCRS_to_geogCRS_context_match_by_name) { auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0); ctxt->setSpatialCriterion( CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); - ctxt->setAllowUseIntermediateCRS(false); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::NEVER); auto NAD27 = GeographicCRS::create( PropertyMap().set(IdentifiedObject::NAME_KEY, GeographicCRS::EPSG_4267->nameStr()), @@ -4577,6 +4579,8 @@ TEST(operation, geogCRS_to_geogCRS_context_concatenated_operation) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris) authFactory->createCoordinateReferenceSystem("4171"), // RGF93 @@ -4640,6 +4644,8 @@ TEST(operation, geogCRS_to_geogCRS_CH1903_to_CH1903plus_context) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4149"), // CH1903 authFactory->createCoordinateReferenceSystem("4150"), // CH1903+ @@ -5113,6 +5119,8 @@ TEST(operation, auto authFactory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( authFactory->createCoordinateReferenceSystem("4807"), // NTF(Paris) authFactory->createCoordinateReferenceSystem("32631"), // UTM31 WGS84 @@ -6191,6 +6199,8 @@ TEST(operation, IGNF_LAMB1_TO_EPSG_4326) { auto authFactory = AuthorityFactory::create(DatabaseContext::create(), std::string()); auto ctxt = CoordinateOperationContext::create(authFactory, nullptr, 0.0); + ctxt->setAllowUseIntermediateCRS( + CoordinateOperationContext::IntermediateCRSUse::ALWAYS); auto list = CoordinateOperationFactory::create()->createOperations( AuthorityFactory::create(DatabaseContext::create(), "IGNF") ->createCoordinateReferenceSystem("LAMB1"), -- cgit v1.2.3 From 1b272fc9ee5d25a0cb07d6d12df13c6a77eeb7f0 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 17 Feb 2019 20:52:46 +0100 Subject: tests: implement fuzzy proj string comparison in a few problematic test cases on non-x86 arch (fixes #1275) --- test/unit/Makefile.am | 2 +- test/unit/test_factory.cpp | 12 +++-- test/unit/test_operation.cpp | 100 ++++++++++++++++++++++++------------------ test/unit/test_primitives.hpp | 99 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 48 deletions(-) create mode 100644 test/unit/test_primitives.hpp (limited to 'test') diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 210bdc90..57a03ca8 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = subdir-objects EXTRA_DIST = CMakeLists.txt -noinst_HEADERS = gtest_include.h +noinst_HEADERS = gtest_include.h test_primitives.hpp AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include -I$(top_srcdir)/test @GTEST_CFLAGS@ @SQLITE3_CFLAGS@ AM_CXXFLAGS = @CXX_WFLAGS@ @NO_ZERO_AS_NULL_POINTER_CONSTANT_FLAG@ diff --git a/test/unit/test_factory.cpp b/test/unit/test_factory.cpp index 40728f96..d5c82afb 100644 --- a/test/unit/test_factory.cpp +++ b/test/unit/test_factory.cpp @@ -28,6 +28,8 @@ #include "gtest_include.h" +#include "test_primitives.hpp" + #include "proj/common.hpp" #include "proj/coordinateoperation.hpp" #include "proj/coordinatesystem.hpp" @@ -991,10 +993,12 @@ TEST(factory, AuthorityFactory_test_uom_9110) { auto factory = AuthorityFactory::create(DatabaseContext::create(), "EPSG"); // This tests conversion from unit of measure EPSG:9110 DDD.MMSSsss auto crs = factory->createProjectedCRS("2172"); - EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=sterea +lat_0=53.0019444444444 +lon_0=21.5027777777778 " - "+k=0.9998 +x_0=4603000 +y_0=5806000 +ellps=krass +units=m " - "+no_defs +type=crs"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + crs->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=sterea +lat_0=53.0019444444444 +lon_0=21.5027777777778 " + "+k=0.9998 +x_0=4603000 +y_0=5806000 +ellps=krass +units=m " + "+no_defs +type=crs"); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_operation.cpp b/test/unit/test_operation.cpp index 103b856c..344f79b7 100644 --- a/test/unit/test_operation.cpp +++ b/test/unit/test_operation.cpp @@ -28,8 +28,12 @@ #include "gtest_include.h" +#include "test_primitives.hpp" + // to be able to use internal::replaceAll +#ifndef FROM_PROJ_CPP #define FROM_PROJ_CPP +#endif #include "proj/common.hpp" #include "proj/coordinateoperation.hpp" @@ -4861,11 +4865,13 @@ TEST(operation, geocentricCRS_to_geocentricCRS_different_datum_context) { authFactory->createCoordinateReferenceSystem("4896"), ctxt); ASSERT_EQ(list.size(), 1U); EXPECT_EQ(list[0]->nameStr(), "ITRF2000 to ITRF2005 (1)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector"); } // --------------------------------------------------------------------------- @@ -4904,15 +4910,17 @@ TEST(operation, "Conversion from ITRF2000 (geog3D) to ITRF2000 (geocentric) + " "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=axisswap +order=2,1 +step " - "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " - "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv " - "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " - "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=axisswap +order=2,1 +step " + "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " + "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv " + "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " + "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- @@ -4930,13 +4938,15 @@ TEST(operation, geogCRS_to_geocentricCRS_different_datum_context) { EXPECT_EQ(list[0]->nameStr(), "Conversion from ITRF2000 (geog3D) to ITRF2000 (geocentric) + " "ITRF2000 to ITRF2005 (1)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=axisswap +order=2,1 +step " - "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " - "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=axisswap +order=2,1 +step " + "+proj=unitconvert +xy_in=deg +z_in=m +xy_out=rad +z_out=m " + "+step +proj=cart +ellps=GRS80 +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector"); } // --------------------------------------------------------------------------- @@ -4954,13 +4964,15 @@ TEST(operation, geocentricCRS_to_geogCRS_different_datum_context) { EXPECT_EQ(list[0]->nameStr(), "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv " - "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " - "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv " + "+proj=cart +ellps=GRS80 +step +proj=unitconvert +xy_in=rad " + "+z_in=m +xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- @@ -4984,21 +4996,23 @@ TEST(operation, esri_projectedCRS_to_geogCRS_with_ITRF_intermediate_context) { "(geocentric) + Inverse of ITRF2000 to NAD83(CORS96) (1) + " "ITRF2000 to ITRF2005 (1) + " "Conversion from ITRF2005 (geocentric) to ITRF2005 (geog3D)"); - EXPECT_EQ(list[0]->exportToPROJString(PROJStringFormatter::create().get()), - "+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +z_in=us-ft " - "+xy_out=m +z_out=m +step +inv +proj=lcc +lat_0=33.75 +lon_0=-79 " - "+lat_1=34.3333333333333 +lat_2=36.1666666666667 " - "+x_0=609601.219202438 +y_0=0 +ellps=GRS80 +step +proj=cart " - "+ellps=GRS80 +step +inv +proj=helmert +x=0.9956 +y=-1.9013 " - "+z=-0.5215 +rx=0.025915 +ry=0.009426 +rz=0.011599 +s=0.00062 " - "+dx=0.0007 +dy=-0.0007 +dz=0.0005 +drx=6.7e-05 +dry=-0.000757 " - "+drz=-5.1e-05 +ds=-0.00018 +t_epoch=1997 " - "+convention=coordinate_frame +step +proj=helmert +x=-0.0001 " - "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " - "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " - "+t_epoch=2000 +convention=position_vector +step +inv +proj=cart " - "+ellps=GRS80 +step +proj=unitconvert +xy_in=rad +z_in=m " - "+xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); + EXPECT_PRED_FORMAT2( + ComparePROJString, + list[0]->exportToPROJString(PROJStringFormatter::create().get()), + "+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +z_in=us-ft " + "+xy_out=m +z_out=m +step +inv +proj=lcc +lat_0=33.75 +lon_0=-79 " + "+lat_1=34.3333333333333 +lat_2=36.1666666666667 " + "+x_0=609601.219202438 +y_0=0 +ellps=GRS80 +step +proj=cart " + "+ellps=GRS80 +step +inv +proj=helmert +x=0.9956 +y=-1.9013 " + "+z=-0.5215 +rx=0.025915 +ry=0.009426 +rz=0.011599 +s=0.00062 " + "+dx=0.0007 +dy=-0.0007 +dz=0.0005 +drx=6.7e-05 +dry=-0.000757 " + "+drz=-5.1e-05 +ds=-0.00018 +t_epoch=1997 " + "+convention=coordinate_frame +step +proj=helmert +x=-0.0001 " + "+y=0.0008 +z=0.0058 +rx=0 +ry=0 +rz=0 +s=-0.0004 +dx=0.0002 " + "+dy=-0.0001 +dz=0.0018 +drx=0 +dry=0 +drz=0 +ds=-8e-05 " + "+t_epoch=2000 +convention=position_vector +step +inv +proj=cart " + "+ellps=GRS80 +step +proj=unitconvert +xy_in=rad +z_in=m " + "+xy_out=deg +z_out=m +step +proj=axisswap +order=2,1"); } // --------------------------------------------------------------------------- diff --git a/test/unit/test_primitives.hpp b/test/unit/test_primitives.hpp new file mode 100644 index 00000000..86e52d0a --- /dev/null +++ b/test/unit/test_primitives.hpp @@ -0,0 +1,99 @@ +/****************************************************************************** + * + * Project: PROJ + * Purpose: Test ISO19111:2018 implementation + * Author: Even Rouault + * + ****************************************************************************** + * Copyright (c) 2018, Even Rouault + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + ****************************************************************************/ + +#include "gtest_include.h" + +#ifndef FROM_PROJ_CPP +#define FROM_PROJ_CPP +#endif + +#include "proj/internal/internal.hpp" + +#include +#include + +using namespace osgeo::proj::internal; + +static ::testing::AssertionResult ComparePROJString(const char* m_expr, + const char* n_expr, + const std::string& m, + const std::string& n) { + //if (m == n) return ::testing::AssertionSuccess(); + auto mTokens = split(m, ' '); + auto nTokens = split(n, ' '); + if( mTokens.size() == nTokens.size() ) + { + bool success = true; + for( size_t i = 0; i < mTokens.size(); i++ ) + { + auto mSubTokens = split(mTokens[i], '='); + auto nSubTokens = split(nTokens[i], '='); + if( mSubTokens.size() != nSubTokens.size() ) { + success = false; + break; + } + if( mSubTokens.size() == 2 && nSubTokens.size() == 2 ) { + if( mSubTokens[0] != nSubTokens[0] ) { + success = false; + break; + } + double mValue = 0.0; + bool mIsDouble = false; + try { + mValue = c_locale_stod(mSubTokens[1]); + mIsDouble = true; + } catch( const std::exception &) {} + double nValue = 0.0; + bool nIsDouble = false; + try { + nValue = c_locale_stod(nSubTokens[1]); + nIsDouble = true; + } catch( const std::exception &) {} + if( mIsDouble != nIsDouble ) { + success = false; + break; + } + if( mIsDouble ) { + success = std::abs(mValue - nValue) <= 1e-14 * std::abs(mValue); + } else { + success = mSubTokens[1] == nSubTokens[1]; + } + if( !success ) { + break; + } + } + } + + if( success ) { + return ::testing::AssertionSuccess(); + } + } + + return ::testing::AssertionFailure() << m_expr << " and " << n_expr + << " (" << m << " and " << n << ") are different"; +} -- cgit v1.2.3