27 #include "../geometry.h"
28 #include "../raster/Band.h"
29 #include "../raster/BandIterator.h"
30 #include "../raster/Grid.h"
31 #include "../raster/PositionIterator.h"
32 #include "../raster/Raster.h"
66 std::vector<std::complex<double> > values;
75 values.push_back((*it)[band]);
85 assert(bands.size() > 0);
88 std::vector<std::vector<std::complex<double> > > allvalues;
89 std::vector<std::complex<double> > values;
90 std::complex<double> value;
100 for (
unsigned int i = 0; i < bands.size(); i++)
104 values.push_back(value);
107 allvalues.push_back(values);
117 std::vector<unsigned int> b;
121 return getMeans(*band.
getRaster(), polygon, b)[0];
126 assert(bands.size() > 0);
129 std::vector<std::complex<double> > means;
131 for (
unsigned int i = 0; i < bands.size(); i++)
132 means.push_back(0.0);
134 unsigned int nvalues = 0;
136 std::complex<double> value;
143 for (
unsigned int i = 0; i < bands.size(); i++)
155 for (
unsigned int i = 0; i < means.size() && nvalues != 0; i++)
163 assert(bands.size() > 1);
169 unsigned int nbands = bands.size();
171 std::vector<std::vector<std::complex<double> > > valuesperband = getValuesFromRaster(raster, polygon, bands);
173 unsigned int nvalues = valuesperband.size();
175 boost::numeric::ublas::matrix<double> covariance(nbands, nbands);
177 std::vector<std::complex<double> > meansperband = getMeans(raster, polygon, bands);
181 for (i = 0; i < nbands; i++)
183 for (j = 0; j < nbands; j++)
184 covariance(i, j) = 0.0;
185 covariance(i, i) = 1000.0;
191 std::complex<double> sum;
193 for (i = 0; i < nbands; i++)
194 for (j = 0; j < nbands; j++)
196 sum = std::complex<double> (0.0, 0.0);
198 for (k = 0; k < nvalues; k++)
199 sum += (valuesperband[k][i] - meansperband[i]) * (valuesperband[k][j] - meansperband[j]);
201 covariance(i, j) = sum.real() / (nvalues - 1);
std::vector< std::complex< double > > getValuesFromBand(const te::rst::Raster &raster, unsigned int band, const te::gm::Polygon &polygon)
Returns the pixel values for the band, inside the polygon.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::complex< double > getMean(const te::rst::Band &band, const te::gm::Polygon &polygon)
Returns the mean value for the pixels of a band, inside the polygon.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
unsigned int getRow() const
Returns the current row in iterator.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
A raster band description.
boost::numeric::ublas::matrix< double > getCovarianceMatrix(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the covariance matrix between raster bands, inside the polygon.
virtual Raster * getRaster() const =0
Returns the associated raster.
RasterAttributes()
Public constructor.
std::vector< std::vector< std::complex< double > > > getValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the pixel values for all the bands in raster, inside the polygon.
Extraction of attributes from Raster, Bands, and Polygons.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
unsigned int getColumn() const
Returns the current column in iterator.
std::size_t m_idx
The band index.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
std::vector< std::complex< double > > getMeans(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the mean value for the pixels of a band, inside the polygon.
Raster Processing algorithm output parameters base interface.
An abstract class for raster data strucutures.
BandProperty * getProperty()
Returns the band property.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
Raster Processing algorithm input parameters base interface.