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

Method RasterGrid

include/extractor/raster_source.hpp:38–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36{
37 public:
38 RasterGrid(const std::filesystem::path &filepath, std::size_t _xdim, std::size_t _ydim)
39 {
40 xdim = _xdim;
41 ydim = _ydim;
42 _data.resize(ydim * xdim);
43 BOOST_ASSERT(ydim * xdim <= _data.capacity());
44
45 // Construct FileReader
46 storage::io::FileReader file_reader(filepath, storage::io::FileReader::HasNoFingerprint);
47 std::string buffer;
48 buffer.resize(xdim * 11); // INT32_MAX = 2147483647 = 10 chars + 1 white space = 11
49 BOOST_ASSERT(xdim * 11 <= buffer.size());
50
51 for (unsigned int y = 0; y < ydim; y++)
52 {
53 // read one line from file.
54 file_reader.ReadLine(buffer.data(), xdim * 11);
55 boost::algorithm::trim(buffer);
56
57 std::vector<std::string> result;
58 boost::split(
59 result, buffer, boost::is_any_of(" \r\n\0"), boost::algorithm::token_compress_on);
60 unsigned int x = 0;
61 for (const auto &s : result)
62 {
63 if (x < xdim)
64 _data[(y * xdim) + x] = atoi(s.c_str());
65 ++x;
66 }
67 BOOST_ASSERT(x == xdim);
68 }
69 }
70
71 RasterGrid(const RasterGrid &) = default;
72 RasterGrid &operator=(const RasterGrid &) = default;

Callers

nothing calls this directly

Calls 5

ReadLineMethod · 0.80
resizeMethod · 0.45
capacityMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected