aboutsummaryrefslogtreecommitdiff
path: root/test/unit/test_crs.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-01-08 16:22:15 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-01-08 21:25:07 +0100
commitf5e5435fd5071d550e0d13f7a5d71e09c1fab2c0 (patch)
treef569d5270f7cb34adf056d04c84a23db6b4f6ed0 /test/unit/test_crs.cpp
parentfdee4277efb45b07db2dcc4d93376cbd01cfbd0a (diff)
downloadPROJ-f5e5435fd5071d550e0d13f7a5d71e09c1fab2c0.tar.gz
PROJ-f5e5435fd5071d550e0d13f7a5d71e09c1fab2c0.zip
ISO19111: remove PROJ.5 specific format for CRS (refs #1214)
As discussed in https://github.com/OSGeo/proj.4/issues/1214#issuecomment-452084720, the introduction of a new PROJ.5 format to export CRS using pipeline/unitconvert/axisswap as an attempt of improving the PROJ.4 format used by GDAL and other products is likely a dead-end since it is still lossy in many aspects and can cause confusion with coodinate operations. Consequently the PROJ_5 convention will be identical to PROJ_4 for CRS export. Note: on the import side, I've kept the code that could parse unitconvert and axisswap when building a CRS definition from a pipeline. It is there as a hidden feature as it was kind of a tear to remove that code in case it might still be useful...
Diffstat (limited to 'test/unit/test_crs.cpp')
-rw-r--r--test/unit/test_crs.cpp212
1 files changed, 81 insertions, 131 deletions
diff --git a/test/unit/test_crs.cpp b/test/unit/test_crs.cpp
index fe0ac7e8..d694d297 100644
--- a/test/unit/test_crs.cpp
+++ b/test/unit/test_crs.cpp
@@ -388,14 +388,7 @@ TEST(crs, EPSG_4326_as_WKT1_ESRI_without_database) {
TEST(crs, EPSG_4326_as_PROJ_string) {
auto crs = GeographicCRS::EPSG_4326;
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=longlat +ellps=WGS84 +step "
- "+proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap "
- "+order=2,1");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=longlat +datum=WGS84 +no_defs");
+ "+proj=longlat +datum=WGS84 +no_defs");
}
// ---------------------------------------------------------------------------
@@ -595,14 +588,7 @@ TEST(crs, EPSG_4807_as_WKT1_ESRI_without_database) {
TEST(crs, EPSG_4807_as_PROJ_string) {
auto crs = GeographicCRS::EPSG_4807;
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=longlat +ellps=clrk80ign "
- "+pm=paris +step +proj=unitconvert +xy_in=rad +xy_out=grad +step "
- "+proj=axisswap +order=2,1");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=longlat +ellps=clrk80ign +pm=paris +no_defs");
+ "+proj=longlat +ellps=clrk80ign +pm=paris +no_defs");
}
// ---------------------------------------------------------------------------
@@ -624,11 +610,8 @@ TEST(crs, EPSG_4267) {
" ORDER[2],\n"
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
" ID[\"EPSG\",4267]]");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=longlat +datum=NAD27 +no_defs");
+ EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=longlat +datum=NAD27 +no_defs");
}
// ---------------------------------------------------------------------------
@@ -663,11 +646,8 @@ TEST(crs, EPSG_4269) {
" ORDER[2],\n"
" ANGLEUNIT[\"degree\",0.0174532925199433]],\n"
" ID[\"EPSG\",4269]]");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=longlat +datum=NAD83 +no_defs");
+ EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=longlat +datum=NAD83 +no_defs");
}
// ---------------------------------------------------------------------------
@@ -725,15 +705,6 @@ TEST(crs, EPSG_27561_projected_with_geodetic_in_grad_as_PROJ_string_and_WKT1) {
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(
crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
- "+proj=unitconvert +xy_in=grad +xy_out=rad +step +inv +proj=longlat "
- "+ellps=clrk80ign +pm=paris +step +proj=lcc +lat_1=49.5 "
- "+lat_0=49.5 +lon_0=0 +k_0=0.999877341 +x_0=600000 +y_0=200000 "
- "+ellps=clrk80ign +pm=paris");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
"+proj=lcc +lat_1=49.5 +lat_0=49.5 +lon_0=0 +k_0=0.999877341 "
"+x_0=600000 +y_0=200000 +ellps=clrk80ign +pm=paris +units=m +no_defs");
@@ -811,9 +782,7 @@ TEST(crs, EPSG_3040_projected_northing_easting_as_PROJ_string) {
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
- "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=utm "
- "+zone=28 +ellps=GRS80 +step +proj=axisswap +order=2,1");
+ "+proj=utm +zone=28 +ellps=GRS80 +units=m +no_defs");
}
// ---------------------------------------------------------------------------
@@ -843,17 +812,8 @@ TEST(crs, EPSG_2222_projected_unit_foot_as_PROJ_string_and_WKT1) {
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
- "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=tmerc "
- "+lat_0=31 +lon_0=-110.166666666667 +k=0.9999 +x_0=213360 "
- "+y_0=0 +ellps=GRS80 +step +proj=unitconvert +xy_in=m +z_in=m "
- "+xy_out=ft +z_out=ft");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=tmerc +lat_0=31 +lon_0=-110.166666666667 +k=0.9999 "
- "+x_0=213360 +y_0=0 +datum=NAD83 +units=ft +no_defs");
+ "+proj=tmerc +lat_0=31 +lon_0=-110.166666666667 +k=0.9999 "
+ "+x_0=213360 +y_0=0 +datum=NAD83 +units=ft +no_defs");
auto wkt1 = crs->exportToWKT(
WKTFormatter::create(WKTFormatter::Convention::WKT1_GDAL).get());
@@ -931,22 +891,18 @@ TEST(crs, EPSG_32661_projected_north_pole_north_east) {
auto crs = factory->createCoordinateReferenceSystem("32661");
auto proj_crs = nn_dynamic_pointer_cast<ProjectedCRS>(crs);
ASSERT_TRUE(proj_crs != nullptr);
+
auto proj_string =
"+proj=pipeline +step +proj=axisswap +order=2,1 +step "
"+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere "
"+lat_0=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 "
"+ellps=WGS84 +step +proj=axisswap +order=2,1";
- EXPECT_EQ(proj_crs->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- auto obj_from_proj = PROJStringParser().createFromPROJString(proj_string);
- auto crs_from_proj = nn_dynamic_pointer_cast<ProjectedCRS>(obj_from_proj);
- ASSERT_TRUE(crs_from_proj != nullptr);
- EXPECT_EQ(
- crs_from_proj->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- EXPECT_TRUE(crs_from_proj->coordinateSystem()->isEquivalentTo(
- proj_crs->coordinateSystem().get()));
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, NN_NO_CHECK(proj_crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ proj_string);
}
// ---------------------------------------------------------------------------
@@ -962,17 +918,12 @@ TEST(crs, EPSG_5041_projected_north_pole_east_north) {
"+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere "
"+lat_0=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 "
"+ellps=WGS84";
- EXPECT_EQ(proj_crs->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- auto obj_from_proj = PROJStringParser().createFromPROJString(proj_string);
- auto crs_from_proj = nn_dynamic_pointer_cast<ProjectedCRS>(obj_from_proj);
- ASSERT_TRUE(crs_from_proj != nullptr);
- EXPECT_EQ(
- crs_from_proj->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- EXPECT_TRUE(crs_from_proj->coordinateSystem()->isEquivalentTo(
- proj_crs->coordinateSystem().get()));
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, NN_NO_CHECK(proj_crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ proj_string);
}
// ---------------------------------------------------------------------------
@@ -988,17 +939,12 @@ TEST(crs, EPSG_32761_projected_south_pole_north_east) {
"+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere "
"+lat_0=-90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 "
"+ellps=WGS84 +step +proj=axisswap +order=2,1";
- EXPECT_EQ(proj_crs->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- auto obj_from_proj = PROJStringParser().createFromPROJString(proj_string);
- auto crs_from_proj = nn_dynamic_pointer_cast<ProjectedCRS>(obj_from_proj);
- ASSERT_TRUE(crs_from_proj != nullptr);
- EXPECT_EQ(
- crs_from_proj->exportToPROJString(PROJStringFormatter::create().get()),
- proj_string);
- EXPECT_TRUE(crs_from_proj->coordinateSystem()->isEquivalentTo(
- proj_crs->coordinateSystem().get()));
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, NN_NO_CHECK(proj_crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ proj_string);
}
// ---------------------------------------------------------------------------
@@ -1009,11 +955,17 @@ TEST(crs, EPSG_5042_projected_south_pole_east_north) {
auto crs = factory->createCoordinateReferenceSystem("5042");
auto proj_crs = nn_dynamic_pointer_cast<ProjectedCRS>(crs);
ASSERT_TRUE(proj_crs != nullptr);
- EXPECT_EQ(proj_crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
- "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere "
- "+lat_0=-90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 "
- "+ellps=WGS84");
+ auto proj_string =
+ "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
+ "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=stere "
+ "+lat_0=-90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 "
+ "+ellps=WGS84";
+
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, NN_NO_CHECK(proj_crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ proj_string);
}
// ---------------------------------------------------------------------------
@@ -1157,12 +1109,7 @@ TEST(crs, EPSG_4978_as_WKT1_GDAL_with_database) {
TEST(crs, geocentricCRS_as_PROJ_string) {
auto crs = createGeocentric();
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=cart +ellps=WGS84");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=geocent +datum=WGS84 +units=m +no_defs");
+ "+proj=geocent +datum=WGS84 +units=m +no_defs");
}
// ---------------------------------------------------------------------------
@@ -1173,14 +1120,17 @@ TEST(crs, geocentricCRS_non_meter_unit_as_PROJ_string) {
CartesianCS::createGeocentric(
UnitOfMeasure("kilometre", 1000.0, UnitOfMeasure::Type::LINEAR)));
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=cart +ellps=WGS84 +step "
- "+proj=unitconvert +xy_in=m +z_in=m +xy_out=km +z_out=km");
- EXPECT_THROW(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- FormattingException);
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, crs);
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
+ "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=cart "
+ "+ellps=WGS84 +step +proj=unitconvert +xy_in=m +z_in=m "
+ "+xy_out=km +z_out=km");
+
+ EXPECT_THROW(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ FormattingException);
}
// ---------------------------------------------------------------------------
@@ -1191,9 +1141,14 @@ TEST(crs, geocentricCRS_unsupported_unit_as_PROJ_string) {
CartesianCS::createGeocentric(
UnitOfMeasure("my unit", 500.0, UnitOfMeasure::Type::LINEAR)));
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=pipeline +step +proj=cart +ellps=WGS84 +step "
- "+proj=unitconvert +xy_in=m +z_in=m +xy_out=500 +z_out=500");
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, crs);
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
+ "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=cart "
+ "+ellps=WGS84 +step +proj=unitconvert +xy_in=m +z_in=m "
+ "+xy_out=500 +z_out=500");
}
// ---------------------------------------------------------------------------
@@ -1556,7 +1511,7 @@ TEST(crs, projectedCRS_shallowClone) {
}
EXPECT_EQ(clone->baseCRS()->exportToPROJString(
PROJStringFormatter::create().get()),
- "+proj=cart +ellps=WGS84");
+ "+proj=geocent +datum=WGS84 +units=m +no_defs");
}
}
@@ -1785,15 +1740,16 @@ TEST(crs, projectedCRS_from_WKT1_ESRI_as_WKT1_ESRI) {
TEST(crs, projectedCRS_as_PROJ_string) {
auto crs = createProjected();
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ GeographicCRS::EPSG_4326, crs);
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline +step +proj=axisswap +order=2,1 +step "
"+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=utm "
"+zone=31 +ellps=WGS84");
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs");
+ EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ "+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs");
}
// ---------------------------------------------------------------------------
@@ -1802,7 +1758,10 @@ TEST(crs, projectedCRS_Krovak_EPSG_5221_as_PROJ_string) {
auto factory = AuthorityFactory::create(DatabaseContext::create(), "EPSG");
auto crs = factory->createProjectedCRS("5221");
// 30deg 17' 17.30311'' = 30.28813975277777776
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ crs->baseCRS(), crs);
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline +step +proj=axisswap +order=2,1 "
"+step +proj=unitconvert +xy_in=deg +xy_out=rad "
"+step +inv +proj=longlat +ellps=bessel +pm=ferro "
@@ -1819,7 +1778,10 @@ TEST(crs, projectedCRS_Krovak_with_approximate_alpha_as_PROJ_string) {
"+proj=krovak +lat_0=49.5 +lon_0=42.5 +alpha=30.28813972222222 "
"+k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +pm=ferro +units=m +no_defs");
auto crs = nn_dynamic_pointer_cast<ProjectedCRS>(obj);
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ crs->baseCRS(), NN_NO_CHECK(crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline "
"+step +proj=unitconvert +xy_in=deg +xy_out=rad "
"+step +inv +proj=longlat +ellps=bessel +pm=ferro "
@@ -3159,17 +3121,8 @@ TEST(crs, compoundCRS_as_WKT1_GDAL) {
TEST(crs, compoundCRS_as_PROJ_string) {
auto crs = createCompoundCRS();
- auto expected = "+proj=pipeline +step +proj=axisswap +order=2,1 +step "
- "+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=utm "
- "+zone=31 +ellps=WGS84 +vunits=m";
-
EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- expected);
- EXPECT_EQ(
- crs->exportToPROJString(
- PROJStringFormatter::create(PROJStringFormatter::Convention::PROJ_4)
- .get()),
- "+proj=utm +zone=31 +datum=WGS84 +units=m +vunits=m +no_defs");
+ "+proj=utm +zone=31 +datum=WGS84 +units=m +vunits=m +no_defs");
}
// ---------------------------------------------------------------------------
@@ -4022,8 +3975,11 @@ TEST(crs, derivedGeographicCRS_to_PROJ) {
auto obj = WKTParser().createFromWKT(wkt);
auto crs = nn_dynamic_pointer_cast<DerivedGeographicCRS>(obj);
ASSERT_TRUE(crs != nullptr);
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ crs->baseCRS(), NN_NO_CHECK(crs));
+ ASSERT_TRUE(op != nullptr);
EXPECT_EQ(
- crs->exportToPROJString(PROJStringFormatter::create().get()),
+ op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=pipeline +step +proj=axisswap +order=2,1 +step "
"+proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=ob_tran "
"+o_proj=longlat +o_lat_p=52 +o_lon_p=-30 +lon_0=-25 +ellps=WGS84 "
@@ -4071,7 +4027,10 @@ TEST(crs, derivedGeographicCRS_with_affine_transform_to_PROJ) {
auto crs = nn_dynamic_pointer_cast<DerivedGeographicCRS>(obj);
ASSERT_TRUE(crs != nullptr);
EXPECT_TRUE(crs->derivingConversion()->validateParameters().empty());
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
+ auto op = CoordinateOperationFactory::create()->createOperation(
+ crs->baseCRS(), NN_NO_CHECK(crs));
+ ASSERT_TRUE(op != nullptr);
+ EXPECT_EQ(op->exportToPROJString(PROJStringFormatter::create().get()),
"+proj=affine +xoff=0.5 +s11=1 +s12=0 +yoff=2.5 +s21=0 +s22=1");
}
@@ -4254,15 +4213,6 @@ TEST(crs, derivedProjectedCRS_WKT2_2015) {
// ---------------------------------------------------------------------------
-TEST(crs, derivedProjectedCRS_to_PROJ) {
-
- auto crs = createDerivedProjectedCRS();
- EXPECT_EQ(crs->exportToPROJString(PROJStringFormatter::create().get()),
- "+proj=unimplemented");
-}
-
-// ---------------------------------------------------------------------------
-
static DateTimeTemporalCSNNPtr createDateTimeTemporalCS() {
return DateTimeTemporalCS::create(
PropertyMap(),