A class to represent 2D Grids. Typical application as DEM or Landuse Model.
#include <Grid2DObject.h>
Public Member Functions | |
double & | operator() (const size_t &ix, const size_t &iy) |
double | operator() (const size_t &ix, const size_t &iy) const |
double & | operator() (const size_t &i) |
double | operator() (const size_t &i) const |
const std::string | toString () const |
Grid2DObject () | |
Default constructor. Initializes all variables to 0, except lat/long which are initialized to IOUtils::nodata. More... | |
Grid2DObject (const size_t &ncols, const size_t &nrows, const double &cellsize, const Coords &i_llcorner) | |
Grid2DObject (const size_t &ncols, const size_t &nrows, const double &cellsize, const Coords &i_llcorner, const double &init) | |
Grid2DObject (const Grid2DObject &i_grid, const double &init) | |
Grid2DObject (const double &cellsize, const Coords &i_llcorner, const Array2D< double > &grid2D_in) | |
Grid2DObject (const Grid2DObject &i_grid2Dobj, const size_t &i_nx, const size_t &i_ny, const size_t &i_ncols, const size_t &i_nrows) | |
constructs an object as a subset of another grid object More... | |
bool | gridify (Coords &point) const |
Compute the positional parameters that are not already known This means that the Coords::point object that is given either contains geographic coordinates or grid indices. This method will calculate the missing ones (so that (i,j) match with (lat,lon) and (east,north)). If the given point had a "NULL" projection, it will be set to the grid's. More... | |
bool | gridify (std::vector< Coords > &vec_points, const bool &keep_invalid=false) const |
Compute the positional parameters that are not already known This means that the Coords::point object that is given either contains geographic coordinates or grid indices. This method will calculate the missing ones (so that (i,j) match with (lat,lon) and (east,north)). Any point that is either invalid or outside the grid is removed from the vector. If the given point had a "NULL" projection, it will be set to the grid's. More... | |
bool | gridify (std::vector< StationData > &vec_points, const bool &keep_invalid=false) const |
void | set (const size_t &ncols, const size_t &nrows, const double &cellsize, const Coords &i_llcorner) |
Set all variables in one go. More... | |
void | set (const double &cellsize, const Coords &i_llcorner, const Array2D< double > &grid2D_in) |
Set all variables in one go. Notably the member grid2D of type Array2D<double> will be destroyed and recreated to size ncols x nrows. More... | |
void | set (const size_t &ncols, const size_t &nrows, const double &cellsize, const Coords &i_llcorner, const double &init) |
void | set (const Grid2DObject &i_grid, const double &init) |
void | rescale (const double &i_cellsize) |
Rescale (bilinear resampling) the grid to match the given cell size. More... | |
void | compute_spatial_mean (const double &radius) |
Spatially average the grid over a given radius. More... | |
void | size (size_t &o_ncols, size_t &o_nrows) const |
size_t | size () const |
size_t | getNx () const |
size_t | getNy () const |
double | getMin () const |
double | getMax () const |
double | getMean () const |
void | clear () |
deletes the data, but keeps geolocalization More... | |
bool | empty () const |
Check if a grid does not contain any data (but it can contain geolocalization) More... | |
bool | allNodata () const |
bool | isSameGeolocalization (const Grid2DObject &target) const |
check if the current Grid2DObject has the same geolocalization attributes as another Grid2DObject (as well as same cells). The grid coordinates (xllcorner & yllcorner) are NOT checked as these might be tweaked for convenience (like between input grid and local grid) More... | |
void | binning (const std::vector< double > &thresholds, const std::vector< double > &ids) |
Partitional algorithm to classify each point of the grid into a 'bin'. The classification is given by a list of growing thresholds, the 'bins' are then a simple range of values. Threshold values will be put into the next higher bin. Each bin comes with an 'id' that replaces the values of the points. More... | |
std::vector< double > | extractPoints (const std::vector< std::pair< size_t, size_t > > &Pts) const |
extract point values from grid More... | |
Grid2DObject & | operator= (const double &value) |
Assignement operator. More... | |
Grid2DObject & | operator+= (const double &rhs) |
const Grid2DObject | operator+ (const double &rhs) const |
Grid2DObject & | operator+= (const Grid2DObject &rhs) |
const Grid2DObject | operator+ (const Grid2DObject &rhs) const |
Grid2DObject & | operator-= (const double &rhs) |
const Grid2DObject | operator- (const double &rhs) const |
Grid2DObject & | operator-= (const Grid2DObject &rhs) |
const Grid2DObject | operator- (const Grid2DObject &rhs) const |
Grid2DObject & | operator*= (const double &rhs) |
const Grid2DObject | operator* (const double &rhs) const |
Grid2DObject & | operator*= (const Grid2DObject &rhs) |
const Grid2DObject | operator* (const Grid2DObject &rhs) const |
Grid2DObject & | operator/= (const double &rhs) |
const Grid2DObject | operator/ (const double &rhs) const |
Grid2DObject & | operator/= (const Grid2DObject &rhs) |
const Grid2DObject | operator/ (const Grid2DObject &rhs) const |
bool | operator== (const Grid2DObject &in) const |
Operator that tests for equality. More... | |
bool | operator!= (const Grid2DObject &in) const |
Operator that tests for inequality. More... | |
Public Attributes | |
Array2D< double > | grid2D |
the grid itself (simple 2D table containing the values for each point) More... | |
Coords | llcorner |
lower left corner of the grid More... | |
double | cellsize |
dimension in meters of a cell (considered to be square) More... | |
Protected Member Functions | |
void | setValues (const double &cellsize, const Coords &i_llcorner) |
bool | WGS84_to_grid (Coords &point) const |
Converts WGS84 coordinates into grid coordinates (i,j) More... | |
bool | grid_to_WGS84 (Coords &point) const |
Converts grid coordinates (i,j) into WGS84 coordinates. More... | |
bool | isLatlon () const |
void | reproject () |
double | calculate_cellsize (const double &i_ur_lat, const double &i_ur_lon) const |
void | setLatLon (const double &i_ur_lat, const double &i_ur_lon) |
Static Protected Member Functions | |
static double | calculate_XYcellsize (const std::vector< double > &vecX, const std::vector< double > &vecY) |
Protected Attributes | |
double | ur_lat |
double | ur_lon |
bool | isLatLon |
Friends | |
class | IOInterface |
class | GridsManager |
std::ostream & | operator<< (std::ostream &os, const Grid2DObject &grid) |
std::istream & | operator>> (std::istream &is, Grid2DObject &grid) |
mio::Grid2DObject::Grid2DObject | ( | ) |
Default constructor. Initializes all variables to 0, except lat/long which are initialized to IOUtils::nodata.
mio::Grid2DObject::Grid2DObject | ( | const size_t & | ncols, |
const size_t & | nrows, | ||
const double & | cellsize, | ||
const Coords & | i_llcorner | ||
) |
mio::Grid2DObject::Grid2DObject | ( | const size_t & | ncols, |
const size_t & | nrows, | ||
const double & | cellsize, | ||
const Coords & | i_llcorner, | ||
const double & | init | ||
) |
mio::Grid2DObject::Grid2DObject | ( | const Grid2DObject & | i_grid, |
const double & | init | ||
) |
mio::Grid2DObject::Grid2DObject | ( | const double & | cellsize, |
const Coords & | i_llcorner, | ||
const Array2D< double > & | grid2D_in | ||
) |
mio::Grid2DObject::Grid2DObject | ( | const Grid2DObject & | i_grid2Dobj, |
const size_t & | i_nx, | ||
const size_t & | i_ny, | ||
const size_t & | i_ncols, | ||
const size_t & | i_nrows | ||
) |
constructs an object as a subset of another grid object
i_grid2Dobj | initial grid object |
i_nx | starting column of the subset |
i_ny | starting row of the subset |
i_ncols | number of columns of the subset |
i_nrows | number of rows of the subset |
bool mio::Grid2DObject::allNodata | ( | ) | const |
void mio::Grid2DObject::binning | ( | const std::vector< double > & | thresholds, |
const std::vector< double > & | ids | ||
) |
Partitional algorithm to classify each point of the grid into a 'bin'. The classification is given by a list of growing thresholds, the 'bins' are then a simple range of values. Threshold values will be put into the next higher bin. Each bin comes with an 'id' that replaces the values of the points.
thresholds | (const std::vector<double>&) ordered list of thresholds representing a scale of values. Each level of this scale defines a bin. |
ids | (const std::vector<double>&) clusters Ids to be used. clustersId.size()=thresholds.size()+1 The first id will replace all values between 0 and the first threshold, and the last id will replace all values greater than the last threshold. Hence, you need one more id than threshold values. |
|
protected |
|
staticprotected |
void mio::Grid2DObject::clear | ( | ) |
deletes the data, but keeps geolocalization
void mio::Grid2DObject::compute_spatial_mean | ( | const double & | radius | ) |
Spatially average the grid over a given radius.
[in] | radius | radius in meters over which to spatially average |
bool mio::Grid2DObject::empty | ( | ) | const |
Check if a grid does not contain any data (but it can contain geolocalization)
std::vector< double > mio::Grid2DObject::extractPoints | ( | const std::vector< std::pair< size_t, size_t > > & | Pts | ) | const |
extract point values from grid
Pts | (const std::vector< std::pair<size_t, size_t> >) vector of pairs consisting of column, row to read |
double mio::Grid2DObject::getMax | ( | ) | const |
double mio::Grid2DObject::getMean | ( | ) | const |
double mio::Grid2DObject::getMin | ( | ) | const |
size_t mio::Grid2DObject::getNx | ( | ) | const |
size_t mio::Grid2DObject::getNy | ( | ) | const |
|
protected |
Converts grid coordinates (i,j) into WGS84 coordinates.
point | coordinate to convert |
bool mio::Grid2DObject::gridify | ( | Coords & | point | ) | const |
Compute the positional parameters that are not already known This means that the Coords::point object that is given either contains geographic coordinates or grid indices. This method will calculate the missing ones (so that (i,j) match with (lat,lon) and (east,north)). If the given point had a "NULL" projection, it will be set to the grid's.
point | coordinate to convert |
bool mio::Grid2DObject::gridify | ( | std::vector< Coords > & | vec_points, |
const bool & | keep_invalid = false |
||
) | const |
Compute the positional parameters that are not already known This means that the Coords::point object that is given either contains geographic coordinates or grid indices. This method will calculate the missing ones (so that (i,j) match with (lat,lon) and (east,north)). Any point that is either invalid or outside the grid is removed from the vector. If the given point had a "NULL" projection, it will be set to the grid's.
vec_points | vector containing the coordinates to convert |
keep_invalid | keep invalid coordinates? (default: false) |
bool mio::Grid2DObject::gridify | ( | std::vector< StationData > & | vec_points, |
const bool & | keep_invalid = false |
||
) | const |
|
inlineprotected |
bool mio::Grid2DObject::isSameGeolocalization | ( | const Grid2DObject & | target | ) | const |
check if the current Grid2DObject has the same geolocalization attributes as another Grid2DObject (as well as same cells). The grid coordinates (xllcorner & yllcorner) are NOT checked as these might be tweaked for convenience (like between input grid and local grid)
target | grid to compare to |
bool mio::Grid2DObject::operator!= | ( | const Grid2DObject & | in | ) | const |
Operator that tests for inequality.
double & mio::Grid2DObject::operator() | ( | const size_t & | i | ) |
double mio::Grid2DObject::operator() | ( | const size_t & | i | ) | const |
double & mio::Grid2DObject::operator() | ( | const size_t & | ix, |
const size_t & | iy | ||
) |
double mio::Grid2DObject::operator() | ( | const size_t & | ix, |
const size_t & | iy | ||
) | const |
const Grid2DObject mio::Grid2DObject::operator* | ( | const double & | rhs | ) | const |
const Grid2DObject mio::Grid2DObject::operator* | ( | const Grid2DObject & | rhs | ) | const |
Grid2DObject & mio::Grid2DObject::operator*= | ( | const double & | rhs | ) |
Grid2DObject & mio::Grid2DObject::operator*= | ( | const Grid2DObject & | rhs | ) |
const Grid2DObject mio::Grid2DObject::operator+ | ( | const double & | rhs | ) | const |
const Grid2DObject mio::Grid2DObject::operator+ | ( | const Grid2DObject & | rhs | ) | const |
Grid2DObject & mio::Grid2DObject::operator+= | ( | const double & | rhs | ) |
Grid2DObject & mio::Grid2DObject::operator+= | ( | const Grid2DObject & | rhs | ) |
const Grid2DObject mio::Grid2DObject::operator- | ( | const double & | rhs | ) | const |
const Grid2DObject mio::Grid2DObject::operator- | ( | const Grid2DObject & | rhs | ) | const |
Grid2DObject & mio::Grid2DObject::operator-= | ( | const double & | rhs | ) |
Grid2DObject & mio::Grid2DObject::operator-= | ( | const Grid2DObject & | rhs | ) |
const Grid2DObject mio::Grid2DObject::operator/ | ( | const double & | rhs | ) | const |
const Grid2DObject mio::Grid2DObject::operator/ | ( | const Grid2DObject & | rhs | ) | const |
Grid2DObject & mio::Grid2DObject::operator/= | ( | const double & | rhs | ) |
Grid2DObject & mio::Grid2DObject::operator/= | ( | const Grid2DObject & | rhs | ) |
Grid2DObject & mio::Grid2DObject::operator= | ( | const double & | value | ) |
Assignement operator.
bool mio::Grid2DObject::operator== | ( | const Grid2DObject & | in | ) | const |
Operator that tests for equality.
|
protected |
void mio::Grid2DObject::rescale | ( | const double & | i_cellsize | ) |
Rescale (bilinear resampling) the grid to match the given cell size.
i_cellsize | new value for cellsize |
void mio::Grid2DObject::set | ( | const double & | cellsize, |
const Coords & | i_llcorner, | ||
const Array2D< double > & | grid2D_in | ||
) |
Set all variables in one go. Notably the member grid2D of type Array2D<double> will be destroyed and recreated to size ncols x nrows.
cellsize | value for cellsize in grid2D |
i_llcorner | lower left corner point |
grid2D_in | grid to be copied by value |
void mio::Grid2DObject::set | ( | const Grid2DObject & | i_grid, |
const double & | init | ||
) |
void mio::Grid2DObject::set | ( | const size_t & | ncols, |
const size_t & | nrows, | ||
const double & | cellsize, | ||
const Coords & | i_llcorner | ||
) |
Set all variables in one go.
ncols | number of colums in the grid2D |
nrows | number of rows in the grid2D |
cellsize | value for cellsize in grid2D |
i_llcorner | lower left corner point |
void mio::Grid2DObject::set | ( | const size_t & | ncols, |
const size_t & | nrows, | ||
const double & | cellsize, | ||
const Coords & | i_llcorner, | ||
const double & | init | ||
) |
|
inlineprotected |
|
protected |
size_t mio::Grid2DObject::size | ( | ) | const |
void mio::Grid2DObject::size | ( | size_t & | o_ncols, |
size_t & | o_nrows | ||
) | const |
const std::string mio::Grid2DObject::toString | ( | ) | const |
|
protected |
Converts WGS84 coordinates into grid coordinates (i,j)
point | coordinate to convert |
|
friend |
|
friend |
|
friend |
|
friend |
double mio::Grid2DObject::cellsize |
dimension in meters of a cell (considered to be square)
Array2D<double> mio::Grid2DObject::grid2D |
the grid itself (simple 2D table containing the values for each point)
|
protected |
Coords mio::Grid2DObject::llcorner |
lower left corner of the grid
|
protected |
|
protected |