9#include "ConstantGrid.h"
20template <
class T,
class V = T>
22 :
public GridData<T, V, map<Location, T>>
32 return this->
data.end() != this->
data.find(location);
44 [[nodiscard]] T
at(
const Location& location)
const override
46 const auto value = this->
data.find(location);
47 if (value == this->
data.end())
51 return get<1>(*value);
65 this->
data[location] = value;
66 assert(
at(location) == value);
106 std::forward<string>(
proj4),
109 constexpr auto max_hash = numeric_limits<HashSize>::max();
111 const auto max_columns =
static_cast<MathSize
>(max_hash) /
static_cast<MathSize
>(this->
rows());
112 logging::check_fatal(this->
columns() >= max_columns,
113 "Grid is too big for cells to be hashed - "
114 "recompile with a larger HashSize value");
118 const auto n1 =
static_cast<NodataIntType
>(n0);
119 const auto n2 =
static_cast<V
>(n1);
120 const auto n3 =
static_cast<NodataIntType
>(n2);
121 logging::check_equal(
124 "nodata_input_ as int");
125 logging::check_equal(
128 "nodata_input_ from int");
162 static_cast<int>(no_data),
167 string(grid_info.
proj4()))
177 this->
data = std::move(rhs.data);
197 this->
data = std::move(rhs.data);
224 tuple<Idx, Idx, Idx, Idx> dataBounds()
const override
226 Idx min_row = this->
rows();
228 Idx min_column = this->
columns();
230 for (
const auto& kv : this->
data)
232 const Idx r = kv.first.row();
233 const Idx c = kv.first.column();
234 min_row = min(min_row, r);
235 max_row = max(max_row, r);
236 min_column = min(min_column, c);
237 max_column = max(max_column, c);
241 if (min_row > max_row)
243 min_row = max_row = this->
rows() / 2;
245 if (min_column > max_column)
247 min_column = max_column = this->
columns() / 2;
249 return tuple<Idx, Idx, Idx, Idx>{
264 const string& base_name,
265 const R divisor)
const
267 auto div = [divisor](T value) -> R {
268 return static_cast<R
>(value / divisor);
279 const MathSize per_width = (this->
cellSize() / 100.0);
281 return static_cast<MathSize
>(this->data.size()) * per_width * per_width;
289 list<Location> edge{};
290 for (
const auto& kv : this->data)
293 auto on_edge =
false;
294 for (Idx r = -1; !on_edge && r <= 1; ++r)
296 const Idx row_index = loc.row() + r;
297 if (!(row_index < 0 || row_index >= this->
rows()))
299 for (Idx c = -1; !on_edge && c <= 1; ++c)
301 const Idx col_index = loc.column() + c;
302 if (!(col_index < 0 || col_index >= this->
columns())
303 && this->data.find(
Location(row_index, col_index)) == this->data.end())
315 logging::info(
"Created edge for perimeter with length %lu m",
316 static_cast<size_t>(this->
cellSize() * edge.size()));
325 list<Location> result{this->data.size()};
326 std::transform(this->data.begin(),
329 [](
const pair<const Location, const T>& kv) { return kv.first; });
The base class with information for a grid of data with geographic coordinates.
Definition Grid.h:43
constexpr MathSize xurcorner() const noexcept
Upper right corner X coordinate in meters.
Definition Grid.h:116
constexpr const string & proj4() const noexcept
Proj4 string defining coordinate system for this grid. Must be a UTM projection.
Definition Grid.h:132
constexpr FullIdx calculateRows() const noexcept
Number of rows in the GridBase.
Definition Grid.h:80
constexpr MathSize cellSize() const noexcept
Cell size used for GridBase.
Definition Grid.h:72
constexpr MathSize yllcorner() const noexcept
Lower left corner Y coordinate in meters.
Definition Grid.h:108
constexpr MathSize xllcorner() const noexcept
Lower left corner X coordinate in meters.
Definition Grid.h:100
constexpr MathSize yurcorner() const noexcept
Upper right corner Y coordinate in meters.
Definition Grid.h:124
constexpr FullIdx calculateColumns() const noexcept
Number of columns in the GridBase.
Definition Grid.h:90
A Grid that defines the data structure used for storing values.
Definition Grid.h:408
string saveToFile(const string &dir, const string &base_name, std::function< R(T value)> convert, const R no_data) const
Definition Grid.h:856
map< Location, T > data
Definition Grid.h:506
A GridData that uses an unordered_map for storage.
Definition GridMap.h:23
GridMap(const Grid< T, V > &grid)
Construct empty GridMap with same extent as given Grid.
Definition GridMap.h:141
GridMap & operator=(const GridMap &rhs)
Copy assignment.
Definition GridMap.h:206
list< Location > makeEdge() const
Make a list of all Locations that are on the edge of cells with a value.
Definition GridMap.h:287
GridMap(const MathSize cell_size, const Idx rows, const Idx columns, T no_data, const int nodata, const MathSize xllcorner, const MathSize yllcorner, const MathSize xurcorner, const MathSize yurcorner, string &&proj4)
Constructor.
Definition GridMap.h:87
GridMap & operator=(GridMap &&rhs) noexcept
Move assignment.
Definition GridMap.h:193
list< Location > makeList() const
Make a list of all Locations that have a value.
Definition GridMap.h:323
void set(const Location &location, const T value) override
Set value at Location.
Definition GridMap.h:63
GridMap(const GridMap &rhs)
Copy constructor.
Definition GridMap.h:183
GridMap(const GridBase &grid_info, T no_data)
Construct empty GridMap with same extent as given Grid.
Definition GridMap.h:157
string saveToProbabilityFile(const string &dir, const string &base_name, const R divisor) const
Save GridMap contents to .asc file as probability.
Definition GridMap.h:263
MathSize fireSize() const noexcept
Calculate area for cells that have a value (ha)
Definition GridMap.h:276
T at(const Location &location) const override
Retrieve value at Location.
Definition GridMap.h:44
void clear() noexcept
Clear data from GridMap.
Definition GridMap.h:217
bool contains(const Location &location) const
Determine if Location has a value.
Definition GridMap.h:30
GridMap(GridMap &&rhs) noexcept
Move constructor.
Definition GridMap.h:174
A GridBase with an associated type of data.
Definition Grid.h:251
constexpr T nodataInput() const noexcept
Definition Grid.h:273
constexpr Idx rows() const noexcept
Definition Grid.h:257
constexpr Idx columns() const noexcept
Definition Grid.h:265
constexpr T nodataValue() const noexcept
Definition Grid.h:281
Definition Location.h:229
A Position with a row and column.
Definition Location.h:57
constexpr HashSize hash() const noexcept
Hash derived from row and column.
Definition Location.h:80