Skip to content

Commit

Permalink
Validate that units match between pipeline steps
Browse files Browse the repository at this point in the history
As suggested in [0], steps in a pipeline are now checked for compliance.
If the right side units in step n differ from the left side units in
step n+1 the pipeline can't be constructed and an error is raised.

[0] https://lists.osgeo.org/pipermail/grass-dev/2018-March/088123.html
  • Loading branch information
kbevers committed Mar 26, 2018
1 parent 0962d1e commit d1ebfcc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/source/operations/pipeline.rst
Expand Up @@ -95,4 +95,16 @@ In the following the GRS80 ellipsoid will be applied to all steps.
+step +proj=cart +inv
+step +proj=merc

**5. Units of operations must match between steps.**

The output units of step *n* must match the expected input unit of step *n+1*. E.g., you can't
pass an operation that outputs projected coordinates to an operation that expects angular units
(degrees). An example of such a unit mismatch is displayed below.

::

+proj=pipeline
+step +proj=merc # Mercator outputs projected coordinates
+step +proj=robin # The Robinson projection expects angular input

.. versionadded:: 5.1.0
13 changes: 13 additions & 0 deletions src/PJ_pipeline.c
Expand Up @@ -470,6 +470,19 @@ PJ *OPERATION(pipeline,0) {
}
}

/* Check that units are compatible between steps */
for (i = 1; i < nsteps; i++) {
enum pj_io_units right = pj_right (P->opaque->pipeline[i]);
enum pj_io_units left = pj_left (P->opaque->pipeline[i+1]);

if ( right == PJ_IO_UNITS_WHATEVER || left == PJ_IO_UNITS_WHATEVER )
continue;
if (right != left ) {
proj_log_error (P, "Pipeline: Mismatched units between step %d and %d", i, i+1);
return destructor (P, PJD_ERR_MALFORMED_PIPELINE);
}
}

proj_log_trace (P, "Pipeline: %d steps built. Determining i/o characteristics", nsteps);

/* Determine forward input (= reverse output) data type */
Expand Down
22 changes: 22 additions & 0 deletions test/gie/4D-API_cs2cs-style.gie
Expand Up @@ -243,4 +243,26 @@ accept 440720 3751320 0
expect 440719.958709357 3751294.2109841 -4.44340920541435
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Test that pipelines with unit mismatch between steps can't be constructed.
-------------------------------------------------------------------------------
operation +proj=pipeline
+step +proj=merc
+step +proj=merc
expect failure pjd_err_malformed_pipeline

operation +proj=pipeline
+step +proj=latlong
+step +proj=merc
+step +proj=helmert +x=200 +y=100
expect failure pjd_err_malformed_pipeline

operation +proj=pipeline
+step +proj=merc
+step +proj=unitconvert +xy_in=m +xy_out=km
accept 12 56
expect 1335.8339 7522.963
-------------------------------------------------------------------------------


</gie>

0 comments on commit d1ebfcc

Please sign in to comment.