aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-12-29 23:57:23 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-12-29 23:57:23 +0100
commit830f94a8117eff270acd2ef928850a9de5e164a9 (patch)
treeef7b780bedec5692dabbcd9097b7fbac7feae20b /src
parent28e1770f27bb335d29bfa44a5c963904007b5e73 (diff)
downloadPROJ-830f94a8117eff270acd2ef928850a9de5e164a9.tar.gz
PROJ-830f94a8117eff270acd2ef928850a9de5e164a9.zip
proj_hgrid_value(): do not apply compensation for west-oriented longitude_offset. Fixes regression due to grid refactoring work on proj=deformation use case
Diffstat (limited to 'src')
-rw-r--r--src/apply_gridshift.cpp16
-rw-r--r--src/grids.cpp38
-rw-r--r--src/grids.hpp4
3 files changed, 34 insertions, 24 deletions
diff --git a/src/apply_gridshift.cpp b/src/apply_gridshift.cpp
index b994474b..4ef86fc0 100644
--- a/src/apply_gridshift.cpp
+++ b/src/apply_gridshift.cpp
@@ -119,7 +119,7 @@ ListOfHGrids proj_hgrid_init(PJ* P, const char *gridkey) {
typedef struct { pj_int32 lam, phi; } ILP;
-static PJ_LP nad_intr(PJ_LP t, const HorizontalShiftGrid* grid) {
+static PJ_LP nad_intr(PJ_LP t, const HorizontalShiftGrid* grid, bool compensateNTConvention) {
PJ_LP val, frct;
ILP indx;
int in;
@@ -164,10 +164,10 @@ static PJ_LP nad_intr(PJ_LP t, const HorizontalShiftGrid* grid) {
float f10Lon = 0, f10Lat = 0;
float f01Lon = 0, f01Lat = 0;
float f11Lon = 0, f11Lat = 0;
- if( !grid->valueAt(indx.lam, indx.phi, f00Lon, f00Lat) ||
- !grid->valueAt(indx.lam + 1, indx.phi, f10Lon, f10Lat) ||
- !grid->valueAt(indx.lam, indx.phi + 1, f01Lon, f01Lat) ||
- !grid->valueAt(indx.lam + 1, indx.phi + 1, f11Lon, f11Lat) )
+ if( !grid->valueAt(indx.lam, indx.phi, compensateNTConvention, f00Lon, f00Lat) ||
+ !grid->valueAt(indx.lam + 1, indx.phi, compensateNTConvention, f10Lon, f10Lat) ||
+ !grid->valueAt(indx.lam, indx.phi + 1, compensateNTConvention, f01Lon, f01Lat) ||
+ !grid->valueAt(indx.lam + 1, indx.phi + 1, compensateNTConvention, f11Lon, f11Lat) )
{
return val;
}
@@ -210,7 +210,7 @@ PJ_LP nad_cvt(projCtx ctx, PJ_LP in, int inverse, const HorizontalShiftGrid* gri
tb.lam = adjlon (tb.lam - M_PI) + M_PI;
- t = nad_intr (tb, grid);
+ t = nad_intr (tb, grid, true);
if (t.lam == HUGE_VAL)
return t;
@@ -224,7 +224,7 @@ PJ_LP nad_cvt(projCtx ctx, PJ_LP in, int inverse, const HorizontalShiftGrid* gri
t.phi = tb.phi - t.phi;
do {
- del = nad_intr(t, grid);
+ del = nad_intr(t, grid, true);
/* We can possibly go outside of the initial guessed grid, so try */
/* to fetch a new grid into which iterate... */
@@ -297,7 +297,7 @@ PJ_LP proj_hgrid_value(PJ *P, const ListOfHGrids& grids, PJ_LP lp) {
lp.lam = adjlon(lp.lam - M_PI) + M_PI;
- out = nad_intr(lp, grid);
+ out = nad_intr(lp, grid, false);
if (out.lam == HUGE_VAL || out.phi == HUGE_VAL) {
pj_ctx_set_errno(P->ctx, PJD_ERR_GRID_AREA);
diff --git a/src/grids.cpp b/src/grids.cpp
index a3d984de..5a99106b 100644
--- a/src/grids.cpp
+++ b/src/grids.cpp
@@ -1431,14 +1431,15 @@ class NullHorizontalShiftGrid : public HorizontalShiftGrid {
bool isNullGrid() const override { return true; }
- bool valueAt(int, int, float &lonShift, float &latShift) const override;
+ bool valueAt(int, int, bool, float &lonShift,
+ float &latShift) const override;
void reassign_context(PJ_CONTEXT *) override {}
};
// ---------------------------------------------------------------------------
-bool NullHorizontalShiftGrid::valueAt(int, int, float &lonShift,
+bool NullHorizontalShiftGrid::valueAt(int, int, bool, float &lonShift,
float &latShift) const {
lonShift = 0.0f;
latShift = 0.0f;
@@ -1471,7 +1472,8 @@ class NTv1Grid : public HorizontalShiftGrid {
~NTv1Grid() override;
- bool valueAt(int, int, float &lonShift, float &latShift) const override;
+ bool valueAt(int, int, bool, float &lonShift,
+ float &latShift) const override;
static NTv1Grid *open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const std::string &filename);
@@ -1549,7 +1551,8 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
// ---------------------------------------------------------------------------
-bool NTv1Grid::valueAt(int x, int y, float &lonShift, float &latShift) const {
+bool NTv1Grid::valueAt(int x, int y, bool compensateNTConvention,
+ float &lonShift, float &latShift) const {
assert(x >= 0 && y >= 0 && x < m_width && y < m_height);
double two_doubles[2];
@@ -1566,7 +1569,8 @@ bool NTv1Grid::valueAt(int x, int y, float &lonShift, float &latShift) const {
/* convert seconds to radians */
latShift = static_cast<float>(two_doubles[0] * ((M_PI / 180.0) / 3600.0));
// west longitude positive convention !
- lonShift = -static_cast<float>(two_doubles[1] * ((M_PI / 180.0) / 3600.0));
+ lonShift = (compensateNTConvention ? -1 : 1) *
+ static_cast<float>(two_doubles[1] * ((M_PI / 180.0) / 3600.0));
return true;
}
@@ -1589,7 +1593,8 @@ class CTable2Grid : public HorizontalShiftGrid {
~CTable2Grid() override;
- bool valueAt(int, int, float &lonShift, float &latShift) const override;
+ bool valueAt(int, int, bool, float &lonShift,
+ float &latShift) const override;
static CTable2Grid *open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const std::string &filename);
@@ -1659,8 +1664,8 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
// ---------------------------------------------------------------------------
-bool CTable2Grid::valueAt(int x, int y, float &lonShift,
- float &latShift) const {
+bool CTable2Grid::valueAt(int x, int y, bool compensateNTConvention,
+ float &lonShift, float &latShift) const {
assert(x >= 0 && y >= 0 && x < m_width && y < m_height);
float two_floats[2];
@@ -1675,7 +1680,7 @@ bool CTable2Grid::valueAt(int x, int y, float &lonShift,
latShift = two_floats[1];
// west longitude positive convention !
- lonShift = -two_floats[0];
+ lonShift = (compensateNTConvention ? -1 : 1) * two_floats[0];
return true;
}
@@ -1725,7 +1730,8 @@ class NTv2Grid : public HorizontalShiftGrid {
m_name(nameIn), m_ctx(ctx), m_fp(fp), m_offset(offsetIn),
m_mustSwap(mustSwapIn) {}
- bool valueAt(int, int, float &lonShift, float &latShift) const override;
+ bool valueAt(int, int, bool, float &lonShift,
+ float &latShift) const override;
void reassign_context(PJ_CONTEXT *ctx) override {
m_ctx = ctx;
@@ -1735,7 +1741,8 @@ class NTv2Grid : public HorizontalShiftGrid {
// ---------------------------------------------------------------------------
-bool NTv2Grid::valueAt(int x, int y, float &lonShift, float &latShift) const {
+bool NTv2Grid::valueAt(int x, int y, bool compensateNTConvention,
+ float &lonShift, float &latShift) const {
assert(x >= 0 && y >= 0 && x < m_width && y < m_height);
float two_float[2];
@@ -1755,7 +1762,8 @@ bool NTv2Grid::valueAt(int x, int y, float &lonShift, float &latShift) const {
/* convert seconds to radians */
latShift = static_cast<float>(two_float[0] * ((M_PI / 180.0) / 3600.0));
// west longitude positive convention !
- lonShift = -static_cast<float>(two_float[1] * ((M_PI / 180.0) / 3600.0));
+ lonShift = (compensateNTConvention ? -1 : 1) *
+ static_cast<float>(two_float[1] * ((M_PI / 180.0) / 3600.0));
return true;
}
@@ -1938,7 +1946,8 @@ class GTiffHGrid : public HorizontalShiftGrid {
~GTiffHGrid() override;
- bool valueAt(int x, int y, float &lonShift, float &latShift) const override;
+ bool valueAt(int x, int y, bool, float &lonShift,
+ float &latShift) const override;
void insertGrid(PJ_CONTEXT *ctx, std::unique_ptr<GTiffHGrid> &&subgrid);
@@ -1968,7 +1977,8 @@ GTiffHGrid::~GTiffHGrid() = default;
// ---------------------------------------------------------------------------
-bool GTiffHGrid::valueAt(int x, int y, float &lonShift, float &latShift) const {
+bool GTiffHGrid::valueAt(int x, int y, bool, float &lonShift,
+ float &latShift) const {
if (!m_grid->valueAt(m_idxLatShift, x, y, latShift) ||
!m_grid->valueAt(m_idxLonShift, x, y, lonShift)) {
return false;
diff --git a/src/grids.hpp b/src/grids.hpp
index fde3eb3e..aa852ef6 100644
--- a/src/grids.hpp
+++ b/src/grids.hpp
@@ -132,8 +132,8 @@ class HorizontalShiftGrid : public Grid {
const HorizontalShiftGrid *gridAt(double lon, double lat) const;
// x = 0 is western-most column, y = 0 is southern-most line
- virtual bool valueAt(int x, int y, float &lonShift,
- float &latShift) const = 0;
+ virtual bool valueAt(int x, int y, bool compensateNTConvention,
+ float &lonShift, float &latShift) const = 0;
virtual void reassign_context(PJ_CONTEXT *ctx) = 0;
};