MeteoIODoc 20241230.207bde49
mio::Grid2DObject Class Reference

Detailed Description

A class to represent 2D Grids. Typical application as DEM or Landuse Model.

Author
Thomas Egger
Date
2008-12-20

#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...
 
Grid2DObjectoperator= (const double &value)
 Assignement operator. More...
 
Grid2DObjectoperator+= (const double &rhs)
 
const Grid2DObject operator+ (const double &rhs) const
 
Grid2DObjectoperator+= (const Grid2DObject &rhs)
 
const Grid2DObject operator+ (const Grid2DObject &rhs) const
 
Grid2DObjectoperator-= (const double &rhs)
 
const Grid2DObject operator- (const double &rhs) const
 
Grid2DObjectoperator-= (const Grid2DObject &rhs)
 
const Grid2DObject operator- (const Grid2DObject &rhs) const
 
Grid2DObjectoperator*= (const double &rhs)
 
const Grid2DObject operator* (const double &rhs) const
 
Grid2DObjectoperator*= (const Grid2DObject &rhs)
 
const Grid2DObject operator* (const Grid2DObject &rhs) const
 
Grid2DObjectoperator/= (const double &rhs)
 
const Grid2DObject operator/ (const double &rhs) const
 
Grid2DObjectoperator/= (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)
 

Constructor & Destructor Documentation

◆ Grid2DObject() [1/6]

mio::Grid2DObject::Grid2DObject ( )

Default constructor. Initializes all variables to 0, except lat/long which are initialized to IOUtils::nodata.

◆ Grid2DObject() [2/6]

mio::Grid2DObject::Grid2DObject ( const size_t &  ncols,
const size_t &  nrows,
const double &  cellsize,
const Coords i_llcorner 
)

◆ Grid2DObject() [3/6]

mio::Grid2DObject::Grid2DObject ( const size_t &  ncols,
const size_t &  nrows,
const double &  cellsize,
const Coords i_llcorner,
const double &  init 
)

◆ Grid2DObject() [4/6]

mio::Grid2DObject::Grid2DObject ( const Grid2DObject i_grid,
const double &  init 
)

◆ Grid2DObject() [5/6]

mio::Grid2DObject::Grid2DObject ( const double &  cellsize,
const Coords i_llcorner,
const Array2D< double > &  grid2D_in 
)

◆ Grid2DObject() [6/6]

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

Parameters
i_grid2Dobjinitial grid object
i_nxstarting column of the subset
i_nystarting row of the subset
i_ncolsnumber of columns of the subset
i_nrowsnumber of rows of the subset

Member Function Documentation

◆ allNodata()

bool mio::Grid2DObject::allNodata ( ) const

◆ binning()

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.

Parameters
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.

◆ calculate_cellsize()

double mio::Grid2DObject::calculate_cellsize ( const double &  i_ur_lat,
const double &  i_ur_lon 
) const
protected

◆ calculate_XYcellsize()

double mio::Grid2DObject::calculate_XYcellsize ( const std::vector< double > &  vecX,
const std::vector< double > &  vecY 
)
staticprotected

◆ clear()

void mio::Grid2DObject::clear ( )

deletes the data, but keeps geolocalization

◆ compute_spatial_mean()

void mio::Grid2DObject::compute_spatial_mean ( const double &  radius)

Spatially average the grid over a given radius.

Parameters
[in]radiusradius in meters over which to spatially average

◆ empty()

bool mio::Grid2DObject::empty ( ) const

Check if a grid does not contain any data (but it can contain geolocalization)

Returns
true if the grid is 0x0

◆ extractPoints()

std::vector< double > mio::Grid2DObject::extractPoints ( const std::vector< std::pair< size_t, size_t > > &  Pts) const

extract point values from grid

Parameters
Pts(const std::vector< std::pair<size_t, size_t> >) vector of pairs consisting of column, row to read
Returns
vector of doubles holding the values of the points provided in Pts.

◆ getMax()

double mio::Grid2DObject::getMax ( ) const

◆ getMean()

double mio::Grid2DObject::getMean ( ) const

◆ getMin()

double mio::Grid2DObject::getMin ( ) const

◆ getNx()

size_t mio::Grid2DObject::getNx ( ) const

◆ getNy()

size_t mio::Grid2DObject::getNy ( ) const

◆ grid_to_WGS84()

bool mio::Grid2DObject::grid_to_WGS84 ( Coords point) const
protected

Converts grid coordinates (i,j) into WGS84 coordinates.

Parameters
pointcoordinate to convert
Returns
false if the given point was invalid (outside the grid or nodata and if possible sets (i,j) to closest values within the grid)

◆ gridify() [1/3]

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.

Parameters
pointcoordinate to convert
Returns
false if the given point was invalid or outside the grid (sets (i,j) to closest values within the grid)

◆ gridify() [2/3]

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.

Parameters
vec_pointsvector containing the coordinates to convert
keep_invalidkeep invalid coordinates? (default: false)
Returns
false if invalid or external points had to be removed

◆ gridify() [3/3]

bool mio::Grid2DObject::gridify ( std::vector< StationData > &  vec_points,
const bool &  keep_invalid = false 
) const

◆ isLatlon()

bool mio::Grid2DObject::isLatlon ( ) const
inlineprotected

◆ isSameGeolocalization()

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)

Parameters
targetgrid to compare to
Returns
true if same geolocalization

◆ operator!=()

bool mio::Grid2DObject::operator!= ( const Grid2DObject in) const

Operator that tests for inequality.

◆ operator()() [1/4]

double & mio::Grid2DObject::operator() ( const size_t &  i)

◆ operator()() [2/4]

double mio::Grid2DObject::operator() ( const size_t &  i) const

◆ operator()() [3/4]

double & mio::Grid2DObject::operator() ( const size_t &  ix,
const size_t &  iy 
)

◆ operator()() [4/4]

double mio::Grid2DObject::operator() ( const size_t &  ix,
const size_t &  iy 
) const

◆ operator*() [1/2]

const Grid2DObject mio::Grid2DObject::operator* ( const double &  rhs) const

◆ operator*() [2/2]

const Grid2DObject mio::Grid2DObject::operator* ( const Grid2DObject rhs) const

◆ operator*=() [1/2]

Grid2DObject & mio::Grid2DObject::operator*= ( const double &  rhs)

◆ operator*=() [2/2]

Grid2DObject & mio::Grid2DObject::operator*= ( const Grid2DObject rhs)

◆ operator+() [1/2]

const Grid2DObject mio::Grid2DObject::operator+ ( const double &  rhs) const

◆ operator+() [2/2]

const Grid2DObject mio::Grid2DObject::operator+ ( const Grid2DObject rhs) const

◆ operator+=() [1/2]

Grid2DObject & mio::Grid2DObject::operator+= ( const double &  rhs)

◆ operator+=() [2/2]

Grid2DObject & mio::Grid2DObject::operator+= ( const Grid2DObject rhs)

◆ operator-() [1/2]

const Grid2DObject mio::Grid2DObject::operator- ( const double &  rhs) const

◆ operator-() [2/2]

const Grid2DObject mio::Grid2DObject::operator- ( const Grid2DObject rhs) const

◆ operator-=() [1/2]

Grid2DObject & mio::Grid2DObject::operator-= ( const double &  rhs)

◆ operator-=() [2/2]

Grid2DObject & mio::Grid2DObject::operator-= ( const Grid2DObject rhs)

◆ operator/() [1/2]

const Grid2DObject mio::Grid2DObject::operator/ ( const double &  rhs) const

◆ operator/() [2/2]

const Grid2DObject mio::Grid2DObject::operator/ ( const Grid2DObject rhs) const

◆ operator/=() [1/2]

Grid2DObject & mio::Grid2DObject::operator/= ( const double &  rhs)

◆ operator/=() [2/2]

Grid2DObject & mio::Grid2DObject::operator/= ( const Grid2DObject rhs)

◆ operator=()

Grid2DObject & mio::Grid2DObject::operator= ( const double &  value)

Assignement operator.

◆ operator==()

bool mio::Grid2DObject::operator== ( const Grid2DObject in) const

Operator that tests for equality.

◆ reproject()

void mio::Grid2DObject::reproject ( )
protected

◆ rescale()

void mio::Grid2DObject::rescale ( const double &  i_cellsize)

Rescale (bilinear resampling) the grid to match the given cell size.

Parameters
i_cellsizenew value for cellsize

◆ set() [1/4]

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.

Parameters
cellsizevalue for cellsize in grid2D
i_llcornerlower left corner point
grid2D_ingrid to be copied by value

◆ set() [2/4]

void mio::Grid2DObject::set ( const Grid2DObject i_grid,
const double &  init 
)

◆ set() [3/4]

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.

Parameters
ncolsnumber of colums in the grid2D
nrowsnumber of rows in the grid2D
cellsizevalue for cellsize in grid2D
i_llcornerlower left corner point

◆ set() [4/4]

void mio::Grid2DObject::set ( const size_t &  ncols,
const size_t &  nrows,
const double &  cellsize,
const Coords i_llcorner,
const double &  init 
)

◆ setLatLon()

void mio::Grid2DObject::setLatLon ( const double &  i_ur_lat,
const double &  i_ur_lon 
)
inlineprotected

◆ setValues()

void mio::Grid2DObject::setValues ( const double &  cellsize,
const Coords i_llcorner 
)
protected

◆ size() [1/2]

size_t mio::Grid2DObject::size ( ) const

◆ size() [2/2]

void mio::Grid2DObject::size ( size_t &  o_ncols,
size_t &  o_nrows 
) const

◆ toString()

const std::string mio::Grid2DObject::toString ( ) const

◆ WGS84_to_grid()

bool mio::Grid2DObject::WGS84_to_grid ( Coords point) const
protected

Converts WGS84 coordinates into grid coordinates (i,j)

Parameters
pointcoordinate to convert
Returns
false if the given point was outside the grid (sets (i,j) to closest values within the grid)

Friends And Related Function Documentation

◆ GridsManager

friend class GridsManager
friend

◆ IOInterface

friend class IOInterface
friend

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Grid2DObject grid 
)
friend

◆ operator>>

std::istream & operator>> ( std::istream &  is,
Grid2DObject grid 
)
friend

Member Data Documentation

◆ cellsize

double mio::Grid2DObject::cellsize

dimension in meters of a cell (considered to be square)

◆ grid2D

Array2D<double> mio::Grid2DObject::grid2D

the grid itself (simple 2D table containing the values for each point)

◆ isLatLon

bool mio::Grid2DObject::isLatLon
protected

◆ llcorner

Coords mio::Grid2DObject::llcorner

lower left corner of the grid

◆ ur_lat

double mio::Grid2DObject::ur_lat
protected

◆ ur_lon

double mio::Grid2DObject::ur_lon
protected

The documentation for this class was generated from the following files: