Skip to content

Commit 2ce37db

Browse files
committed
Vertical Offset by Grid Interpolation (NRCan byn) operations: reverse the sign of the value of the grid
1 parent 47ad6a3 commit 2ce37db

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/iso19111/operation/singleoperation.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -2187,12 +2187,20 @@ createSimilarPropertiesMethod(common::IdentifiedObjectNNPtr obj) {
21872187

21882188
// ---------------------------------------------------------------------------
21892189

2190-
static bool isRegularVerticalGridMethod(int methodEPSGCode) {
2190+
static bool isRegularVerticalGridMethod(int methodEPSGCode,
2191+
bool &reverseOffsetSign) {
2192+
if (methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_NRCAN_BYN) {
2193+
// NRCAN vertical shift grids use a reverse convention from other
2194+
// grids: the value in the grid is the value to subtract from the
2195+
// source vertical CRS to get the target value.
2196+
reverseOffsetSign = true;
2197+
return true;
2198+
}
2199+
reverseOffsetSign = false;
21912200
return methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_NZLVD ||
21922201
methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_BEV_AT ||
21932202
methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_GTX ||
2194-
methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_PL_TXT ||
2195-
methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_NRCAN_BYN;
2203+
methodEPSGCode == EPSG_CODE_METHOD_VERTICALGRID_PL_TXT;
21962204
}
21972205

21982206
// ---------------------------------------------------------------------------
@@ -2477,8 +2485,9 @@ TransformationNNPtr SingleOperation::substitutePROJAlternativeGridNames(
24772485
}
24782486
}
24792487

2488+
bool reverseOffsetSign = false;
24802489
if (methodEPSGCode == EPSG_CODE_METHOD_VERTCON ||
2481-
isRegularVerticalGridMethod(methodEPSGCode)) {
2490+
isRegularVerticalGridMethod(methodEPSGCode, reverseOffsetSign)) {
24822491
auto fileParameter =
24832492
parameterValue(EPSG_NAME_PARAMETER_VERTICAL_OFFSET_FILE,
24842493
EPSG_CODE_PARAMETER_VERTICAL_OFFSET_FILE);
@@ -4146,15 +4155,16 @@ bool SingleOperation::exportToPROJStringGeneric(
41464155
}
41474156
}
41484157

4149-
if (isRegularVerticalGridMethod(methodEPSGCode)) {
4158+
bool reverseOffsetSign = false;
4159+
if (isRegularVerticalGridMethod(methodEPSGCode, reverseOffsetSign)) {
41504160
auto fileParameter =
41514161
parameterValue(EPSG_NAME_PARAMETER_VERTICAL_OFFSET_FILE,
41524162
EPSG_CODE_PARAMETER_VERTICAL_OFFSET_FILE);
41534163
if (fileParameter &&
41544164
fileParameter->type() == ParameterValue::Type::FILENAME) {
41554165
formatter->addStep("vgridshift");
41564166
formatter->addParam("grids", fileParameter->valueFile());
4157-
formatter->addParam("multiplier", 1.0);
4167+
formatter->addParam("multiplier", reverseOffsetSign ? -1.0 : 1.0);
41584168
return true;
41594169
}
41604170
}

test/unit/test_operationfactory.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -9698,7 +9698,7 @@ TEST(operation,
96989698
"+step +inv +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
96999699
"+x_0=304800 +y_0=0 +ellps=GRS80 "
97009700
"+step +proj=vgridshift +grids=ca_nrc_HT2_1997_CGG2013a.tif "
9701-
"+multiplier=1 "
9701+
"+multiplier=-1 "
97029702
"+step +proj=utm +zone=19 +ellps=GRS80");
97039703
}
97049704
{
@@ -9712,7 +9712,7 @@ TEST(operation,
97129712
"+step +inv +proj=utm +zone=19 +ellps=GRS80 "
97139713
"+step +inv +proj=vgridshift "
97149714
"+grids=ca_nrc_HT2_1997_CGG2013a.tif "
9715-
"+multiplier=1 "
9715+
"+multiplier=-1 "
97169716
"+step +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
97179717
"+x_0=304800 +y_0=0 +ellps=GRS80");
97189718
}
@@ -9746,7 +9746,7 @@ TEST(operation,
97469746
"+step +inv +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
97479747
"+x_0=304800 +y_0=0 +ellps=GRS80 "
97489748
"+step +proj=vgridshift +grids=ca_nrc_HT2_2002v70_CGG2013a.tif "
9749-
"+multiplier=1 "
9749+
"+multiplier=-1 "
97509750
"+step +proj=utm +zone=19 +ellps=GRS80");
97519751
}
97529752
{
@@ -9760,7 +9760,7 @@ TEST(operation,
97609760
"+step +inv +proj=utm +zone=19 +ellps=GRS80 "
97619761
"+step +inv +proj=vgridshift "
97629762
"+grids=ca_nrc_HT2_2002v70_CGG2013a.tif "
9763-
"+multiplier=1 "
9763+
"+multiplier=-1 "
97649764
"+step +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
97659765
"+x_0=304800 +y_0=0 +ellps=GRS80");
97669766
}
@@ -9794,7 +9794,7 @@ TEST(operation,
97949794
"+step +inv +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
97959795
"+x_0=304800 +y_0=0 +ellps=GRS80 "
97969796
"+step +proj=vgridshift +grids=ca_nrc_HT2_2010v70_CGG2013a.tif "
9797-
"+multiplier=1 "
9797+
"+multiplier=-1 "
97989798
"+step +proj=utm +zone=19 +ellps=GRS80");
97999799
}
98009800
{
@@ -9808,7 +9808,7 @@ TEST(operation,
98089808
"+step +inv +proj=utm +zone=19 +ellps=GRS80 "
98099809
"+step +inv +proj=vgridshift "
98109810
"+grids=ca_nrc_HT2_2010v70_CGG2013a.tif "
9811-
"+multiplier=1 "
9811+
"+multiplier=-1 "
98129812
"+step +proj=tmerc +lat_0=0 +lon_0=-70.5 +k=0.9999 "
98139813
"+x_0=304800 +y_0=0 +ellps=GRS80");
98149814
}

0 commit comments

Comments
 (0)