MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / LoadRasterSource

Method LoadRasterSource

src/extractor/raster_source.cpp:80–123  ·  view source on GitHub ↗

Load raster source into memory

Source from the content-addressed store, hash-verified

78
79// Load raster source into memory
80int 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
126RasterDatum RasterContainer::GetRasterDataFromSource(unsigned int source_id, double lon, double lat)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 7

toFixedFunction · 0.85
LogClass · 0.85
RuntimeErrorClass · 0.85
endMethod · 0.45
sizeMethod · 0.45
emplaceMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected