MCPcopy Create free account
hub / github.com/OSGeo/PROJ / pj_deformation_get_grid_values

Function pj_deformation_get_grid_values

src/transformations/deformation.cpp:83–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81// ---------------------------------------------------------------------------
82
83static bool pj_deformation_get_grid_values(PJ *P, deformationData *Q,
84 const PJ_LP &lp, double &vx,
85 double &vy, double &vz) {
86 GenericShiftGridSet *gridset = nullptr;
87 auto grid = pj_find_generic_grid(Q->grids, lp, gridset);
88 if (!grid) {
89 return false;
90 }
91 if (grid->isNullGrid()) {
92 vx = 0;
93 vy = 0;
94 vz = 0;
95 return true;
96 }
97 const auto samplesPerPixel = grid->samplesPerPixel();
98 if (samplesPerPixel < 3) {
99 proj_log_error(P, "grid has not enough samples");
100 return false;
101 }
102 int sampleE = 0;
103 int sampleN = 1;
104 int sampleU = 2;
105 for (int i = 0; i < samplesPerPixel; i++) {
106 const auto desc = grid->description(i);
107 if (desc == "east_velocity") {
108 sampleE = i;
109 } else if (desc == "north_velocity") {
110 sampleN = i;
111 } else if (desc == "up_velocity") {
112 sampleU = i;
113 }
114 }
115 const auto unit = grid->unit(sampleE);
116 if (!unit.empty() && unit != "millimetres per year") {
117 proj_log_error(P, "Only unit=millimetres per year currently handled");
118 return false;
119 }
120
121 bool must_retry = false;
122 if (!pj_bilinear_interpolation_three_samples(P->ctx, grid, lp, sampleE,
123 sampleN, sampleU, vx, vy, vz,
124 must_retry)) {
125 if (must_retry)
126 return pj_deformation_get_grid_values(P, Q, lp, vx, vy, vz);
127 return false;
128 }
129 // divide by 1000 to get m/year
130 vx /= 1000;
131 vy /= 1000;
132 vz /= 1000;
133 return true;
134}
135
136/********************************************************************************/
137static PJ_XYZ pj_deformation_get_grid_shift(PJ *P, const PJ_XYZ &cartesian) {

Callers 1

Calls 8

pj_find_generic_gridFunction · 0.85
proj_log_errorFunction · 0.85
isNullGridMethod · 0.45
samplesPerPixelMethod · 0.45
descriptionMethod · 0.45
unitMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected