27 #include "../geometry/Coord2D.h" 
   28 #include "../geometry/Envelope.h" 
   51       throw te::rst::Exception(
"Unable to compute affine parameters");
 
   62                     double resX, 
double resY,
 
   77                     double resX, 
double resY,
 
   89       throw te::rst::Exception(
"Unable to compute affine parameters");
 
  110     throw te::rst::Exception(
"Missing extent");
 
  119     throw te::rst::Exception(
"Unable to compute affine parameters");
 
  136     m_nCols(rhs.m_nCols),
 
  137     m_nRows(rhs.m_nRows),
 
  161     memcpy(m_geoT, rhs.
m_geoT, 
sizeof(
double) * 6);
 
  162     memcpy(m_geoTInverse, rhs.
m_geoTInverse, 
sizeof(
double) * 6);
 
  186   if( ! computeAffineParameters( m_extent->getWidth(), m_extent->getHeight(),
 
  187     m_nCols, m_nRows, m_extent->m_llx, m_extent->m_ury, m_geoT, m_geoTInverse ) )
 
  189     throw te::rst::Exception(
"Unable to compute affine parameters");
 
  202   if( ! computeAffineParameters( m_extent->getWidth(), m_extent->getHeight(),
 
  203     m_nCols, m_nRows, m_extent->m_llx, m_extent->m_ury, m_geoT, m_geoTInverse ) )
 
  205     throw te::rst::Exception(
"Unable to compute affine parameters");
 
  218   const double extentWidth = ((double)m_nCols) * resX;
 
  219   const double extentheight = ((double)m_nRows) * resY;
 
  221   if( ! computeAffineParameters( extentWidth, extentheight,
 
  222     m_nCols, m_nRows, ulLocation.
x, ulLocation.
y, m_geoT, m_geoTInverse ) )
 
  224     throw te::rst::Exception(
"Unable to compute affine parameters");
 
  233   m_geoT[0] = geoTrans[0];
 
  234   m_geoT[1] = geoTrans[1];
 
  235   m_geoT[2] = geoTrans[2];
 
  236   m_geoT[3] = geoTrans[3];
 
  237   m_geoT[4] = geoTrans[4];
 
  238   m_geoT[5] = geoTrans[5];
 
  240   if( ! computeInverseParameters( m_geoT, m_geoTInverse ) )
 
  242     throw te::rst::Exception(
"Unable to compute the inverse affine parameters");
 
  256   return m_extent->getWidth() / ((double)m_nCols );
 
  262   return m_extent->getHeight() / ((double)m_nRows );
 
  288   te::gm::Coord2D lr = gridToGeo( ((
double)m_nCols) - 0.5, ((
double)m_nRows) - 0.5 );
 
  298     std::max(ur.
x, lr.
x), std::max(ul.
y, ur.
y) );
 
  303   x = col * m_geoT[0] + row * m_geoT[1] + m_geoT[2];
 
  304   y = col * m_geoT[3] + row * m_geoT[4] + m_geoT[5];
 
  309   col = x * m_geoTInverse[0] + y * m_geoTInverse[1] + m_geoTInverse[2];
 
  310   row = x * m_geoTInverse[3] + y * m_geoTInverse[4] + m_geoTInverse[5];
 
  318   if (!m_extent->equals(*rhs.
m_extent) ||
 
  334   const double extentHeight, 
const unsigned int nColumns,
 
  335   const unsigned int nRows, 
const double extentULX,
 
  336   const double extentULY, 
double* affineParamsPtr,
 
  337   double* inverseAffineParamsPtr )
 const 
  339   affineParamsPtr[0] = extentWidth / ((double)nColumns);
 
  340   affineParamsPtr[1] = 0.0;
 
  341   affineParamsPtr[2] = extentULX + ( extentWidth / 
static_cast<double>(nColumns) / 2.0 );
 
  342   affineParamsPtr[3] = 0.0;
 
  343   affineParamsPtr[4] = -1.0 * extentHeight / ((double)nRows);
 
  344   affineParamsPtr[5] = extentULY - ( extentHeight / 
static_cast<double>(nRows) / 2.0 );
 
  346   return computeInverseParameters( affineParamsPtr, inverseAffineParamsPtr );
 
  350   double* inverseAffineParamsPtr )
 const 
  352   const double determinant = ( affineParamsPtr[0] * affineParamsPtr[4] ) -
 
  353     ( affineParamsPtr[1] * affineParamsPtr[3] );
 
  354   if( determinant == 0.0 )
 
  359   inverseAffineParamsPtr[0] = affineParamsPtr[4] / determinant;
 
  360   inverseAffineParamsPtr[1] = ( -1.0 * affineParamsPtr[1] ) / determinant;
 
  361   inverseAffineParamsPtr[2] = 
 
  363       ( affineParamsPtr[1] * affineParamsPtr[5] ) 
 
  365       ( affineParamsPtr[2] * affineParamsPtr[4] ) 
 
  369   inverseAffineParamsPtr[3] = ( -1.0 * affineParamsPtr[3] ) / determinant;
 
  370   inverseAffineParamsPtr[4] = ( affineParamsPtr[0] ) / determinant;
 
  371   inverseAffineParamsPtr[5] = 
 
  373       ( -1.0 * ( affineParamsPtr[0] * affineParamsPtr[5] ) )
 
  375       ( affineParamsPtr[3] * affineParamsPtr[2] )
 
unsigned int getNumberOfRows() const 
Returns the grid number of rows. 
 
te::gm::Envelope * m_extent
The grid extent. 
 
bool computeInverseParameters(double *const affineParamsPtr, double *inverseAffineParamsPtr) const 
Compute inverse affine parameters. 
 
int getSRID() const 
Returns the grid spatial reference system identifier. 
 
Grid & operator=(const Grid &rhs)
Assignment operator. 
 
Grid(unsigned int nCols=0, unsigned int nRows=0, te::gm::Envelope *mbr=0, int srid=TE_UNKNOWN_SRS)
Constructor. 
 
double getWidth() const 
It returns the envelope width. 
 
An utility struct for representing 2D coordinates. 
 
void setGeoreference(const te::gm::Coord2D &ulLocation, int srid, double resX, double resY)
Sets the information needed to georeference the grid. 
 
void geoToGrid(const double &x, const double &y, double &col, double &row) const 
Get the grid point associated to a spatial location. 
 
double getResolutionY() const 
Returns the grid vertical (y-axis) resolution. 
 
An exception class for the Raster module. 
 
double m_llx
Lower left corner x-coordinate. 
 
An Envelope defines a 2D rectangular region. 
 
int m_srid
The associated SRS. 
 
unsigned int m_nCols
Number of columns. 
 
const double * getGeoreference() const 
Returns a list of 6 coefficients describing an affine transformation to georeference a grid...
 
bool operator==(const Grid &rhs) const 
Equal operator. 
 
double m_geoT[6]
A list of 6 coefficients describing an affine transformation to georeference a grid. 
 
unsigned int getNumberOfColumns() const 
Returns the grid number of columns. 
 
double getResolutionX() const 
Returns the grid horizontal (x-axis) resolution. 
 
void setNumberOfRows(unsigned int nRows)
Sets the grid number of rows. 
 
bool computeAffineParameters(const double extentWidth, const double extentHeight, const unsigned int nColumns, const unsigned int nRows, const double extentULX, const double extentULY, double *affineParamsPtr, double *inverseAffineParamsPtr) const 
Compute affine parameters from the given input parameters. 
 
void setNumberOfColumns(unsigned int nCols)
Sets the grid number of columns. 
 
double m_ury
Upper right corner y-coordinate. 
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid. 
 
void gridToGeo(const double &col, const double &row, double &x, double &y) const 
Get the spatial location of a grid point. 
 
A rectified grid is the spatial support for raster data. 
 
void setSRID(int srid)
Just sets the grid spatial reference system identifier. 
 
A rectified grid is the spatial support for raster data. 
 
double getHeight() const 
It returns the envelope height. 
 
void computeExtent() const 
Computes the geographic extension of the grid. 
 
double m_geoTInverse[6]
A list of 6 coefficients describing an inverse affine transformation to georeference a grid...
 
unsigned int m_nRows
Number of rows.