| 239 | #define REL_TOLERANCE_HGRIDSHIFT 1e-5 |
| 240 | |
| 241 | PJ_XYZ gridshiftData::grid_interpolate(PJ_CONTEXT *ctx, const std::string &type, |
| 242 | PJ_XY xy, const GenericShiftGrid *grid, |
| 243 | bool &biquadraticInterpolationOut) { |
| 244 | PJ_XYZ val; |
| 245 | |
| 246 | val.x = val.y = HUGE_VAL; |
| 247 | val.z = 0; |
| 248 | |
| 249 | const bool isProjectedCoord = !grid->extentAndRes().isGeographic; |
| 250 | auto iterCache = m_cacheGridInfo.find(grid); |
| 251 | if (iterCache == m_cacheGridInfo.end()) { |
| 252 | bool eastingNorthingOffset = false; |
| 253 | const auto samplesPerPixel = grid->samplesPerPixel(); |
| 254 | int idxSampleY = -1; |
| 255 | int idxSampleX = -1; |
| 256 | int idxSampleZ = -1; |
| 257 | for (int i = 0; i < samplesPerPixel; i++) { |
| 258 | const auto desc = grid->description(i); |
| 259 | if (!isProjectedCoord && desc == "latitude_offset") { |
| 260 | idxSampleY = i; |
| 261 | const auto unit = grid->unit(idxSampleY); |
| 262 | if (!unit.empty() && unit != "arc-second") { |
| 263 | pj_log(ctx, PJ_LOG_ERROR, |
| 264 | "gridshift: Only unit=arc-second currently handled"); |
| 265 | return val; |
| 266 | } |
| 267 | } else if (!isProjectedCoord && desc == "longitude_offset") { |
| 268 | idxSampleX = i; |
| 269 | const auto unit = grid->unit(idxSampleX); |
| 270 | if (!unit.empty() && unit != "arc-second") { |
| 271 | pj_log(ctx, PJ_LOG_ERROR, |
| 272 | "gridshift: Only unit=arc-second currently handled"); |
| 273 | return val; |
| 274 | } |
| 275 | } else if (isProjectedCoord && desc == "easting_offset") { |
| 276 | eastingNorthingOffset = true; |
| 277 | idxSampleX = i; |
| 278 | const auto unit = grid->unit(idxSampleX); |
| 279 | if (!unit.empty() && unit != "metre") { |
| 280 | pj_log(ctx, PJ_LOG_ERROR, |
| 281 | "gridshift: Only unit=metre currently handled"); |
| 282 | return val; |
| 283 | } |
| 284 | } else if (isProjectedCoord && desc == "northing_offset") { |
| 285 | eastingNorthingOffset = true; |
| 286 | idxSampleY = i; |
| 287 | const auto unit = grid->unit(idxSampleY); |
| 288 | if (!unit.empty() && unit != "metre") { |
| 289 | pj_log(ctx, PJ_LOG_ERROR, |
| 290 | "gridshift: Only unit=metre currently handled"); |
| 291 | return val; |
| 292 | } |
| 293 | } else if (desc == "ellipsoidal_height_offset" || |
| 294 | desc == "geoid_undulation" || desc == "hydroid_height" || |
| 295 | desc == "vertical_offset") { |
| 296 | idxSampleZ = i; |
| 297 | const auto unit = grid->unit(idxSampleZ); |
| 298 | if (!unit.empty() && unit != "metre") { |
nothing calls this directly
no test coverage detected