Load raster source into memory
| 78 | |
| 79 | // Load raster source into memory |
| 80 | int RasterContainer::LoadRasterSource(const std::string &path_string, |
| 81 | double xmin, |
| 82 | double xmax, |
| 83 | double ymin, |
| 84 | double ymax, |
| 85 | std::size_t nrows, |
| 86 | std::size_t ncols) |
| 87 | { |
| 88 | const auto _xmin = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmin})); |
| 89 | const auto _xmax = static_cast<std::int32_t>(util::toFixed(util::FloatLongitude{xmax})); |
| 90 | const auto _ymin = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymin})); |
| 91 | const auto _ymax = static_cast<std::int32_t>(util::toFixed(util::FloatLatitude{ymax})); |
| 92 | |
| 93 | const auto itr = RasterCache::getInstance().getLoadedSourcePaths().find(path_string); |
| 94 | if (itr != RasterCache::getInstance().getLoadedSourcePaths().end()) |
| 95 | { |
| 96 | util::Log() << "[source loader] Already loaded source '" << path_string << "' at source_id " |
| 97 | << itr->second; |
| 98 | return itr->second; |
| 99 | } |
| 100 | |
| 101 | int source_id = static_cast<int>(RasterCache::getInstance().getLoadedSources().size()); |
| 102 | |
| 103 | util::Log() << "[source loader] Loading from " << path_string << " ... "; |
| 104 | TIMER_START(loading_source); |
| 105 | |
| 106 | std::filesystem::path filepath(path_string); |
| 107 | if (!std::filesystem::exists(filepath)) |
| 108 | { |
| 109 | throw util::RuntimeError( |
| 110 | path_string, ErrorCode::FileOpenError, SOURCE_REF, "File not found"); |
| 111 | } |
| 112 | |
| 113 | RasterGrid rasterData{filepath, ncols, nrows}; |
| 114 | |
| 115 | RasterSource source{std::move(rasterData), ncols, nrows, _xmin, _xmax, _ymin, _ymax}; |
| 116 | TIMER_STOP(loading_source); |
| 117 | RasterCache::getInstance().getLoadedSourcePaths().emplace(path_string, source_id); |
| 118 | RasterCache::getInstance().getLoadedSources().push_back(std::move(source)); |
| 119 | |
| 120 | util::Log() << "[source loader] ok, after " << TIMER_SEC(loading_source) << "s"; |
| 121 | |
| 122 | return source_id; |
| 123 | } |
| 124 | |
| 125 | // External function for looking up nearest data point from a specified source |
| 126 | RasterDatum RasterContainer::GetRasterDataFromSource(unsigned int source_id, double lon, double lat) |
no test coverage detected