| 81 | // --------------------------------------------------------------------------- |
| 82 | |
| 83 | static 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 | /********************************************************************************/ |
| 137 | static PJ_XYZ pj_deformation_get_grid_shift(PJ *P, const PJ_XYZ &cartesian) { |
no test coverage detected