From d81ffc6fa8a32db72bdfd1ff034c705222d0cdb3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 25 Nov 2019 14:56:31 +0100 Subject: Pipeline: support +omit_fwd and +omit_inv keywords Inspired from syntax of https://github.com/OSGeo/PROJ/pull/453/files but 'rebased' on top of previous commit that cleans up the pipeline implementation Different situations: - +omit_fwd: the step when followed in the forward path will be omitted the step when followed in the reverse path will be executed - +omit_fwd +inv: the step when followed in the forward path will be omitted the step when followed in the reverse path will be executed (with the inv method) - +omit_inv: the step when followed in the forward path will be executed the step when followed in the reverse path will be omitted - +omit_inv +inv: the step when followed in the forward path will be executed (with the inv method) the step when followed in the reverse path will be omitted This will be used in the next commit to optimize constructs like +step +proj=hgridshift +grids=foo +step +proj=vgridshift +grids=bar +step +inv +proj=hgridshift +grids=foo Such steps are used for CRS to CRS transformations where applying the vertical grid requires to do a transformation to an interpolating CRS. One can notice that in the last step will just restore the horizontal coordinates before the first step, so doing an inverse hgridshift is overkill. So that could be optimized as: +step +proj=push +v_1 +v_2 +step +proj=hgridshift +grids=foo +omit_inv +step +proj=vgridshift +grids=bar +step +inv +proj=hgridshift +grids=foo +omit_fwd +step +proj=pop +v_1 +v_2 In the forward path, this will be equivalent to: +step +proj=push +v_1 +v_2 +step +proj=hgridshift +grids=foo +step +proj=vgridshift +grids=bar +step +prop=pop +v_1 +v_2 And similarly in the reverse path, this will be quivalent to: +step +proj=push +v_1 +v_2 +step +proj=hgridshift +grids=foo +step +inv +proj=vgridshift +grids=bar +step +proj=pop +v_1 +v_2 --- test/gie/4D-API_cs2cs-style.gie | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test') diff --git a/test/gie/4D-API_cs2cs-style.gie b/test/gie/4D-API_cs2cs-style.gie index 19b3ad96..e5722b5e 100644 --- a/test/gie/4D-API_cs2cs-style.gie +++ b/test/gie/4D-API_cs2cs-style.gie @@ -386,6 +386,55 @@ operation +proj=pop +v_3 accept 12 56 0 0 expect 12 56 0 0 +------------------------------------------------------------------------------- +Test Pipeline +omit_inv +------------------------------------------------------------------------------- + +operation +proj=pipeline + +step +proj=affine +xoff=1 +yoff=1 +omit_inv + +accept 2 49 0 0 +expect 3 50 0 0 + +direction inverse +accept 2 49 0 0 +expect 2 49 0 0 + + +operation +proj=pipeline + +step +inv +proj=affine +xoff=1 +yoff=1 +omit_inv + +accept 2 49 0 0 +expect 1 48 0 0 + +direction inverse +accept 2 49 0 0 +expect 2 49 0 0 + +------------------------------------------------------------------------------- +Test Pipeline +omit_fwd +------------------------------------------------------------------------------- + +operation +proj=pipeline + +step +proj=affine +xoff=1 +yoff=1 +omit_fwd + +accept 2 49 0 0 +expect 2 49 0 0 + +direction inverse +accept 2 49 0 0 +expect 1 48 0 0 + + +operation +proj=pipeline + +step +inv +proj=affine +xoff=1 +yoff=1 +omit_fwd + +accept 2 49 0 0 +expect 2 49 0 0 + +direction inverse +accept 2 49 0 0 +expect 3 50 0 0 ------------------------------------------------------------------------------- Test bugfix of https://github.com/OSGeo/proj.4/issues/1002 -- cgit v1.2.3 From d1945ecbafc202a0034ad1aa1bb5f38cd10ee74c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 25 Nov 2019 15:12:33 +0100 Subject: PROJStringFormatter::toString(): optimize hgridshift, vgridshift, hgridshift inv constructs Given an initial pipeline with +step +proj=hgridshift +grids=foo +step +proj=vgridshift +grids=bar +step +inv +proj=hgridshift +grids=foo Transform it as +step +proj=push +v_1 +v_2 +step +proj=hgridshift +grids=foo +omit_inv +step +proj=vgridshift +grids=bar +step +inv +proj=hgridshift +grids=foo +omit_fwd +step +proj=pop +v_1 +v_2 So as to avoid doing a double application of the hgridshift. --- test/unit/test_io.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'test') diff --git a/test/unit/test_io.cpp b/test/unit/test_io.cpp index 07c4c6f1..0dc0dc1c 100644 --- a/test/unit/test_io.cpp +++ b/test/unit/test_io.cpp @@ -6832,6 +6832,95 @@ TEST(io, projstringformatter_axisswap_unitconvert_axisswap) { // --------------------------------------------------------------------------- +TEST(io, projstringformatter_optim_hgridshift_vgridshift_hgridshift_inv) { + // Nominal case + { + auto fmt = PROJStringFormatter::create(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + + fmt->addStep("vgridshift"); + fmt->addParam("grids", "bar"); + + fmt->startInversion(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + fmt->stopInversion(); + + EXPECT_EQ(fmt->toString(), + "+proj=pipeline " + "+step +proj=push +v_1 +v_2 " + "+step +proj=hgridshift +grids=foo +omit_inv " + "+step +proj=vgridshift +grids=bar " + "+step +inv +proj=hgridshift +grids=foo +omit_fwd " + "+step +proj=pop +v_1 +v_2"); + } + + // Variant with first hgridshift inverted, and second forward + { + auto fmt = PROJStringFormatter::create(); + + fmt->startInversion(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + fmt->stopInversion(); + + fmt->addStep("vgridshift"); + fmt->addParam("grids", "bar"); + + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + + EXPECT_EQ(fmt->toString(), + "+proj=pipeline " + "+step +proj=push +v_1 +v_2 " + "+step +inv +proj=hgridshift +grids=foo +omit_inv " + "+step +proj=vgridshift +grids=bar " + "+step +proj=hgridshift +grids=foo +omit_fwd " + "+step +proj=pop +v_1 +v_2"); + } + + // Do not apply ! not same grid name + { + auto fmt = PROJStringFormatter::create(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + + fmt->addStep("vgridshift"); + fmt->addParam("grids", "bar"); + + fmt->startInversion(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo2"); + fmt->stopInversion(); + + EXPECT_EQ(fmt->toString(), "+proj=pipeline " + "+step +proj=hgridshift +grids=foo " + "+step +proj=vgridshift +grids=bar " + "+step +inv +proj=hgridshift +grids=foo2"); + } + + // Do not apply ! missing inversion + { + auto fmt = PROJStringFormatter::create(); + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + + fmt->addStep("vgridshift"); + fmt->addParam("grids", "bar"); + + fmt->addStep("hgridshift"); + fmt->addParam("grids", "foo"); + + EXPECT_EQ(fmt->toString(), "+proj=pipeline " + "+step +proj=hgridshift +grids=foo " + "+step +proj=vgridshift +grids=bar " + "+step +proj=hgridshift +grids=foo"); + } +} + +// --------------------------------------------------------------------------- + TEST(io, projparse_longlat) { auto expected = "GEODCRS[\"unknown\",\n" -- cgit v1.2.3