aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-07-01 14:09:02 +0200
committerEven Rouault <even.rouault@spatialys.com>2020-09-30 11:26:48 +0200
commit164c85cc8e7f4515c7c4da7a85fe75c4a21fafec (patch)
treea1400324adefc7d79488ed0fd661b0060c86490a /test
parentef48acb4ab6e3426ac66f37a6477521d7b7be6d3 (diff)
downloadPROJ-164c85cc8e7f4515c7c4da7a85fe75c4a21fafec.tar.gz
PROJ-164c85cc8e7f4515c7c4da7a85fe75c4a21fafec.zip
Add a +proj=tinshift for triangulation-based transformations
Implements RFC-6
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/gie/Makefile.am8
-rw-r--r--test/gie/tinshift.gie50
-rw-r--r--test/unit/CMakeLists.txt11
-rw-r--r--test/unit/Makefile.am9
-rw-r--r--test/unit/test_tinshift.cpp211
6 files changed, 287 insertions, 3 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9fc29103..c60f344b 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -17,6 +17,7 @@ proj_add_gie_test("adams_ws2" "gie/adams_ws2.gie")
proj_add_gie_test("guyou" "gie/guyou.gie")
proj_add_gie_test("peirce_q" "gie/peirce_q.gie")
proj_add_gie_test("defmodel" "gie/defmodel.gie")
+proj_add_gie_test("tinshift" "gie/tinshift.gie")
# GIGS tests. Uncommented tests are expected to fail due to issues with
# various projections. Should be investigated further and fixed.
diff --git a/test/gie/Makefile.am b/test/gie/Makefile.am
index e6bb9582..20f0ec8f 100644
--- a/test/gie/Makefile.am
+++ b/test/gie/Makefile.am
@@ -16,7 +16,8 @@ EXTRA_DIST = 4D-API_cs2cs-style.gie \
adams_ws2.gie \
guyou.gie \
peirce_q.gie \
- defmodel.gie
+ defmodel.gie \
+ tinshift.gie
PROJ_LIB ?= ../../data/for_tests
@@ -68,4 +69,7 @@ peirce_q: peirce_q.gie
defmodel: defmodel.gie
PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY=YES PROJ_LIB=$(PROJ_LIB) $(GIEEXE) $<
-check-local: 4D-API-cs2cs-style GDA axisswap builtins deformation ellipsoid more_builtins unitconvert DHDN_ETRS89 geotiff_grids adams_hemi adams_ws1 adams_ws2 guyou peirce_q defmodel
+tinshift: tinshift.gie
+ PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY=YES PROJ_LIB=$(PROJ_LIB) $(GIEEXE) $<
+
+check-local: 4D-API-cs2cs-style GDA axisswap builtins deformation ellipsoid more_builtins unitconvert DHDN_ETRS89 geotiff_grids adams_hemi adams_ws1 adams_ws2 guyou peirce_q defmodel tinshift
diff --git a/test/gie/tinshift.gie b/test/gie/tinshift.gie
new file mode 100644
index 00000000..dff62693
--- /dev/null
+++ b/test/gie/tinshift.gie
@@ -0,0 +1,50 @@
+
+-------------------------------------------------------------------------------
+===============================================================================
+Test +proj=tinshift
+===============================================================================
+
+<gie-strict>
+
+# Missing +file
+operation +proj=tinshift
+expect failure errno no_args
+
+# +file doesn't point to an existing file
+operation +proj=tinshift +file=i_do_not_exist
+expect failure errno invalid_arg
+
+# Not a JSON file
+operation +proj=tinshift +file=proj.ini
+expect failure errno invalid_arg
+
+
+# Tests on a file without explicit CRS
+operation +proj=tinshift +file=tests/tinshift_crs_implicit.json
+accept 2 49
+expect 2.1 49.1
+roundtrip 1
+
+accept 0 0
+expect failure
+
+direction inverse
+accept 0 0
+expect failure
+
+
+# Tests on a file with explicit CRS
+operation +proj=tinshift +file=tests/tinshift_simplified_kkj_etrs.json
+tolerance 0.1 mm
+# Verified with https://kartta.paikkatietoikkuna.fi/?lang=en with EPSG:2393 to EPSG:3067
+accept 3210000.0000 6700000.0000
+expect 209948.3217 6697187.0009
+roundtrip 1
+
+operation +proj=tinshift +file=tests/tinshift_simplified_n60_n2000.json
+tolerance 0.1 mm
+accept 3210000.0000 6700000.0000 10.0
+expect 3210000.0000 6700000.0000 10.2886
+roundtrip 1
+
+</gie-strict>
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 04c6acb6..2c0c19a9 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -181,3 +181,14 @@ target_link_libraries(test_defmodel
add_test(NAME test_defmodel COMMAND test_defmodel)
set_property(TEST test_defmodel
PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT})
+
+
+add_executable(test_tinshift
+ main.cpp
+ test_tinshift.cpp)
+target_link_libraries(test_tinshift
+ GTest::gtest
+ ${PROJ_LIBRARIES})
+add_test(NAME test_tinshift COMMAND test_tinshift)
+set_property(TEST test_tinshift
+ PROPERTY ENVIRONMENT ${PROJ_TEST_ENVIRONMENT})
diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am
index 2dd0dbff..483cb0bd 100644
--- a/test/unit/Makefile.am
+++ b/test/unit/Makefile.am
@@ -19,6 +19,7 @@ noinst_PROGRAMS += gie_self_tests
noinst_PROGRAMS += include_proj_h_from_c
noinst_PROGRAMS += test_network
noinst_PROGRAMS += test_defmodel
+noinst_PROGRAMS += test_tinshift
pj_transform_test_SOURCES = pj_transform_test.cpp main.cpp
pj_transform_test_LDADD = ../../src/libproj.la @GTEST_LIBS@
@@ -77,6 +78,12 @@ test_defmodel_LDADD = ../../src/libproj.la @GTEST_LIBS@
test_defmodel-check: test_defmodel
PROJ_LIB=$(PROJ_LIB) ./test_defmodel
+test_tinshift_SOURCES = test_tinshift.cpp main.cpp
+test_tinshift_LDADD = ../../src/libproj.la @GTEST_LIBS@
+
+test_tinshift-check: test_tinshift
+ PROJ_LIB=$(PROJ_LIB) ./test_tinshift
+
check-local: pj_transform_test-check pj_phi2_test-check proj_errno_string_test-check \
proj_angular_io_test-check proj_context_test-check test_cpp_api-check \
- gie_self_tests-check test_network-check test_defmodel-check
+ gie_self_tests-check test_network-check test_defmodel-check test_tinshift-check
diff --git a/test/unit/test_tinshift.cpp b/test/unit/test_tinshift.cpp
new file mode 100644
index 00000000..96da6e25
--- /dev/null
+++ b/test/unit/test_tinshift.cpp
@@ -0,0 +1,211 @@
+/******************************************************************************
+ *
+ * Project: PROJ
+ * Purpose: Test TIN shift
+ * Author: Even Rouault <even dot rouault at spatialys dot com>
+ *
+ ******************************************************************************
+ * Copyright (c) 2020, Even Rouault <even dot rouault at spatialys dot com>
+ *
+ * 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"
+
+#define PROJ_COMPILATION
+#define TINSHIFT_NAMESPACE TestTINShift
+#include "transformations/tinshift.hpp"
+
+using namespace TINSHIFT_NAMESPACE;
+
+namespace {
+
+static json getMinValidContent() {
+ json j;
+ j["file_type"] = "triangulation_file";
+ j["format_version"] = "1.0";
+ j["input_crs"] = "EPSG:2393";
+ j["output_crs"] = "EPSG:3067";
+ j["transformed_components"] = {"horizontal"};
+ j["vertices_columns"] = {"source_x", "source_y", "target_x", "target_y"};
+ j["triangles_columns"] = {"idx_vertex1", "idx_vertex2", "idx_vertex3"};
+ j["vertices"] = {{0, 0, 101, 101}, {0, 1, 100, 101}, {1, 1, 100, 100}};
+ j["triangles"] = {{0, 1, 2}};
+
+ return j;
+}
+
+// ---------------------------------------------------------------------------
+
+TEST(tinshift, basic) {
+ EXPECT_THROW(TINShiftFile::parse("foo"), ParsingException);
+ EXPECT_THROW(TINShiftFile::parse("null"), ParsingException);
+ EXPECT_THROW(TINShiftFile::parse("{}"), ParsingException);
+
+ const auto jMinValid(getMinValidContent());
+ {
+ auto f = TINShiftFile::parse(jMinValid.dump());
+ EXPECT_EQ(f->fileType(), "triangulation_file");
+ EXPECT_EQ(f->formatVersion(), "1.0");
+ EXPECT_EQ(f->inputCRS(), "EPSG:2393");
+ EXPECT_EQ(f->outputCRS(), "EPSG:3067");
+
+ auto eval = Evaluator(std::move(f));
+ double x_out = 0;
+ double y_out = 0;
+ double z_out = 0;
+
+ EXPECT_FALSE(eval.forward(-0.1, 0.0, 1000.0, x_out, y_out, z_out));
+
+ EXPECT_TRUE(eval.forward(0.0, 0.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 101.0);
+ EXPECT_EQ(y_out, 101.0);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.forward(0.0, 1.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.0);
+ EXPECT_EQ(y_out, 101.0);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.forward(1.0, 1.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.0);
+ EXPECT_EQ(y_out, 100.0);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.forward(0.0, 0.5, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.5);
+ EXPECT_EQ(y_out, 101.0);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.forward(0.5, 0.5, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.5);
+ EXPECT_EQ(y_out, 100.5);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.forward(0.5, 0.75, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.25);
+ EXPECT_EQ(y_out, 100.5);
+ EXPECT_EQ(z_out, 1000.0);
+
+ EXPECT_TRUE(eval.inverse(100.25, 100.5, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.0);
+ }
+
+ // Vertical only, through source_z / target_z
+ {
+ auto j(jMinValid);
+ j["transformed_components"] = {"vertical"};
+ j["vertices_columns"] = {"source_x", "source_y", "source_z",
+ "target_z"};
+ j["triangles_columns"] = {"idx_vertex1", "idx_vertex2", "idx_vertex3"};
+ j["vertices"] = {
+ {0, 0, 10.5, 10.6}, {0, 1, 15.0, 15.2}, {1, 1, 17.5, 18.0}};
+ j["triangles"] = {{0, 1, 2}};
+
+ auto f = TINShiftFile::parse(j.dump());
+ auto eval = Evaluator(std::move(f));
+ double x_out = 0;
+ double y_out = 0;
+ double z_out = 0;
+
+ EXPECT_TRUE(eval.forward(0.0, 0.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.0);
+ EXPECT_EQ(y_out, 0.0);
+ EXPECT_EQ(z_out, 1000.1);
+
+ EXPECT_TRUE(eval.forward(0.5, 0.75, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.325);
+
+ EXPECT_TRUE(eval.inverse(0.5, 0.75, 1000.325, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.0);
+ }
+
+ // Vertical only, through offset_z
+ {
+ auto j(jMinValid);
+ j["transformed_components"] = {"vertical"};
+ j["vertices_columns"] = {"source_x", "source_y", "offset_z"};
+ j["triangles_columns"] = {"idx_vertex1", "idx_vertex2", "idx_vertex3"};
+ j["vertices"] = {{0, 0, 0.1}, {0, 1, 0.2}, {1, 1, 0.5}};
+ j["triangles"] = {{0, 1, 2}};
+
+ auto f = TINShiftFile::parse(j.dump());
+ auto eval = Evaluator(std::move(f));
+ double x_out = 0;
+ double y_out = 0;
+ double z_out = 0;
+
+ EXPECT_TRUE(eval.forward(0.0, 0.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.0);
+ EXPECT_EQ(y_out, 0.0);
+ EXPECT_EQ(z_out, 1000.1);
+
+ EXPECT_TRUE(eval.forward(0.5, 0.75, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.325);
+
+ EXPECT_TRUE(eval.inverse(0.5, 0.75, 1000.325, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.0);
+ }
+
+ // Horizontal + vertical
+ {
+ auto j(jMinValid);
+ j["transformed_components"] = {"horizontal", "vertical"};
+ j["vertices_columns"] = {"source_x", "source_y", "target_x", "target_y",
+ "offset_z"};
+ j["triangles_columns"] = {"idx_vertex1", "idx_vertex2", "idx_vertex3"};
+ j["vertices"] = {{0, 0, 101, 101, 0.1},
+ {0, 1, 100, 101, 0.2},
+ {1, 1, 100, 100, 0.5}};
+ j["triangles"] = {{0, 1, 2}};
+
+ auto f = TINShiftFile::parse(j.dump());
+ auto eval = Evaluator(std::move(f));
+ double x_out = 0;
+ double y_out = 0;
+ double z_out = 0;
+
+ EXPECT_TRUE(eval.forward(0.0, 0.0, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 101.0);
+ EXPECT_EQ(y_out, 101.0);
+ EXPECT_EQ(z_out, 1000.1);
+
+ EXPECT_TRUE(eval.forward(0.5, 0.75, 1000.0, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 100.25);
+ EXPECT_EQ(y_out, 100.5);
+ EXPECT_EQ(z_out, 1000.325);
+
+ EXPECT_TRUE(eval.inverse(100.25, 100.5, 1000.325, x_out, y_out, z_out));
+ EXPECT_EQ(x_out, 0.5);
+ EXPECT_EQ(y_out, 0.75);
+ EXPECT_EQ(z_out, 1000.0);
+ }
+}
+
+} // namespace