14template <
class T,
class V = T>
18 [[nodiscard]]
bool contains(
const XYIdx& location)
const
20 return this->
data.end() != this->
data.find(location);
22 [[nodiscard]] T at(
const XYIdx& location)
const override
24 const auto value = this->
data.find(location);
25 if (value == this->
data.end())
29 return get<1>(*value);
36 void set(
const XYIdx& location,
const T value)
override
38 this->
data[location] = value;
39 assert(at(location) == value);
44 const MathSize cell_size,
53 const string_view
proj4
69 constexpr auto max_hash = numeric_limits<HashSize>::max();
71 const auto MAX_WIDTH =
static_cast<MathSize
>(max_hash) /
static_cast<MathSize
>(this->height());
73 this->width() >= MAX_WIDTH,
74 "Grid is too big for cells to be hashed - "
75 "recompile with a larger HashSize value"
80 const auto n1 =
static_cast<NodataIntType
>(n0);
81 const auto n2 =
static_cast<V
>(n1);
82 const auto n3 =
static_cast<NodataIntType
>(n2);
83 logging::check_equal(n1, n3,
"nodata_input_ as int");
84 logging::check_equal(n0, n2,
"nodata_input_ from int");
111 static_cast<Idx>(grid_info.calculateWidth()),
112 static_cast<Idx>(grid_info.calculateHeight()),
114 static_cast<int>(no_data),
119 string(grid_info.
proj4())
124 this->
data = std::move(rhs.data);
126 GridMap(
const GridMap& rhs) : GridData<T, V, map<XYIdx, T>>(rhs) { this->
data = rhs.data; }
127 GridMap& operator=(GridMap&& rhs)
noexcept
131 this->
data = std::move(rhs.data);
135 GridMap& operator=(
const GridMap& rhs)
139 this->
data = rhs.data;
149 tuple<Idx, Idx, Idx, Idx> dataBounds()
const override
151 Idx min_y = this->height();
153 Idx min_x = this->width();
155 for (
const auto& kv : this->
data)
157 const Idx r = kv.first.y_value();
158 const Idx c = kv.first.x_value();
159 min_y = min(min_y, r);
160 max_y = max(max_y, r);
161 min_x = min(min_x, c);
162 max_x = max(max_x, c);
168 min_y = max_y = this->height() / 2;
172 min_x = max_x = this->width() / 2;
174 return {min_x, min_y, max_x, max_y};
187 const string_view dir,
188 const string_view base_name,
192 auto div = [=](T value) -> R {
return static_cast<R
>(value / divisor); };
202 const MathSize per_width = (this->
cellSize() / 100.0);
204 return static_cast<MathSize
>(this->data.size()) * per_width * per_width;
213 for (
const auto& kv : this->data)
217 auto [x_loc, y_loc] = hash_to_xy(loc);
218 auto on_edge =
false;
219 for (Idx r = -1; !on_edge && r <= 1; ++r)
221 const Idx y = y_loc.value + r;
222 if (!(y < 0 || y >= this->height()))
224 for (Idx c = -1; !on_edge && c <= 1; ++c)
226 const Idx x = x_loc.value + c;
227 if (!(x < 0 || x >= this->width()) && this->data.find(
XYIdx{x, y}) == this->data.end())
240 "Created edge for perimeter with length {:d} m",
241 static_cast<size_t>(this->
cellSize() * edge.size())
251 list<XYIdx> result{this->data.size()};
256 [](
const pair<const XYIdx, const T>& kv) { return kv.first; }
The base class with information for a grid of data with geographic coordinates.
Definition Grid.h:23
constexpr const string & proj4() const noexcept
Proj4 string defining coordinate system for this grid. Must be a UTM projection.
Definition Grid.h:67
constexpr MathSize xllcorner() const noexcept
Lower left corner X coordinate in metres.
Definition Grid.h:47
constexpr MathSize xurcorner() const noexcept
Upper right corner X coordinate in metres.
Definition Grid.h:57
constexpr MathSize yllcorner() const noexcept
Lower left corner Y coordinate in metres.
Definition Grid.h:52
constexpr MathSize yurcorner() const noexcept
Upper right corner Y coordinate in metres.
Definition Grid.h:62
constexpr MathSize cellSize() const noexcept
Cell size used for GridBase.
Definition Grid.h:34
A Grid that defines the data structure used for storing values.
Definition Grid.h:267
FileList saveToFile(const string_view dir, const string_view base_name, std::function< R(T value)> convert, const R no_data) const
Definition Grid.h:537
map< XYIdx, T > data
Definition Grid.h:327
A GridData that uses an unordered_map for storage.
Definition GridMap.h:16
list< XYIdx > makeEdge() const
Make a list of all Locations that are on the edge of cells with a value.
Definition GridMap.h:210
GridMap(const Grid< T, V > &grid)
Construct empty GridMap with same extent as given Grid.
Definition GridMap.h:91
void clear() noexcept
Clear data from GridMap.
Definition GridMap.h:146
FileList saveToProbabilityFile(const string_view dir, const string_view base_name, const R divisor) const
Save GridMap contents to .asc file as probability.
Definition GridMap.h:186
GridMap(const GridBase &grid_info, T no_data)
Construct empty GridMap with same extent as given Grid.
Definition GridMap.h:108
MathSize fireSize() const noexcept
Calculate area for cells that have a value (ha)
Definition GridMap.h:199
void set(const XYIdx &location, const T value) override
Set value at Location.
Definition GridMap.h:36
list< XYIdx > makeList() const
Make a list of all Locations that have a value.
Definition GridMap.h:249
A GridBase with an associated type of data.
Definition Grid.h:175
constexpr T nodataInput() const noexcept
Definition Grid.h:183
constexpr T nodataValue() const noexcept
Definition Grid.h:188