MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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)
 
virtual ~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 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...
 
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 size (size_t &o_ncols, size_t &o_nrows) const
 
size_t size () const
 
size_t getNx () const
 
size_t getNy () 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 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...
 
bool clusterization (const std::vector< double > &thresholds, const std::vector< double > &ids)
 Partitional algorithm to classify each point of the grid. The classification is given by a list of growing thresholds, the 'clusters' are then a simple range of values. Each cluster comes with an 'id' that replaces the values of the points. More...
 
Grid2DObjectoperator= (const Grid2DObject &)
 Assignement operator. 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...
 

Friends

std::iostream & operator<< (std::iostream &os, const Grid2DObject &grid)
 
std::iostream & operator>> (std::iostream &is, Grid2DObject &grid)
 

Constructor & Destructor Documentation

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 
)
virtual mio::Grid2DObject::~Grid2DObject ( )
inlinevirtual
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

void mio::Grid2DObject::clear ( )

deletes the data, but keeps geolocalization

bool mio::Grid2DObject::clusterization ( const std::vector< double > &  thresholds,
const std::vector< double > &  ids 
)

Partitional algorithm to classify each point of the grid. The classification is given by a list of growing thresholds, the 'clusters' are then a simple range of values. Each cluster 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 cluster
ids(const std::vector<double>&) clusters Ids to be used. clustersId.size()=thresholds.size()+1
Returns
true if clusturization was succesfull
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
size_t mio::Grid2DObject::getNx ( ) const
size_t mio::Grid2DObject::getNy ( ) const
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)
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)
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
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
bool mio::Grid2DObject::operator!= ( const Grid2DObject in) const

Operator that tests for inequality.

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
double & mio::Grid2DObject::operator() ( const size_t &  i)
double mio::Grid2DObject::operator() ( const size_t &  i) 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 Grid2DObject source)

Assignement operator.

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

Assignement operator.

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

Operator that tests for equality.

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
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
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
void mio::Grid2DObject::set ( const size_t &  ncols,
const size_t &  nrows,
const double &  cellsize,
const Coords i_llcorner,
const double &  init 
)
void mio::Grid2DObject::set ( const Grid2DObject i_grid,
const double &  init 
)
void mio::Grid2DObject::setValues ( const double &  cellsize,
const Coords i_llcorner 
)
protected
void mio::Grid2DObject::size ( size_t &  o_ncols,
size_t &  o_nrows 
) const
size_t mio::Grid2DObject::size ( ) const
const std::string mio::Grid2DObject::toString ( ) const
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

std::iostream& operator<< ( std::iostream &  os,
const Grid2DObject grid 
)
friend
std::iostream& operator>> ( std::iostream &  is,
Grid2DObject grid 
)
friend

Member Data Documentation

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)

Coords mio::Grid2DObject::llcorner

lower left corner of the grid


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