| 478 | |
| 479 | |
| 480 | void GDALGrid::fillPercentiles(const size_t& idx, std::vector<double>& values) |
| 481 | { |
| 482 | std::sort(values.begin(), values.end()); |
| 483 | //!! This check is mostly for testing |
| 484 | if (values.size() != static_cast<size_t>(m_count->at(idx))) |
| 485 | { |
| 486 | throw error("Mismatch in size of accumulated values and count raster; " |
| 487 | "expected " + std::to_string(m_count->at(idx)) + " values, got " + |
| 488 | std::to_string(values.size())); |
| 489 | return; |
| 490 | } |
| 491 | //!! Could use nth_element? |
| 492 | for (auto& [pct, raster] : m_pctls) |
| 493 | { |
| 494 | const double pctIdxExact = (pct / 100.0) * (m_count->at(idx) - 1); |
| 495 | const size_t pctIdxFloor = static_cast<size_t>(pctIdxExact); |
| 496 | double fraction = pctIdxExact - pctIdxFloor; |
| 497 | if (!fraction) |
| 498 | (*raster)[idx] = values[pctIdxFloor]; |
| 499 | else |
| 500 | (*raster)[idx] = values[pctIdxFloor] + fraction * |
| 501 | (values[pctIdxFloor + 1] - values[pctIdxFloor]); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | |
| 506 | void GDALGrid::finalize() |