27 #include <terralib_buildconfig.h> 38 #include <boost/test/unit_test.hpp> 45 template<
typename DataType>
52 m_nCols( raster.getNumberOfColumns() )
58 void getFeature(
const unsigned int& elementIndex,
const unsigned int& featureIndex,
59 DataType& featureValue )
const 88 template<
typename DataType>
95 m_nCols( raster.getNumberOfColumns() )
102 const unsigned int& featureIndex,
const DataType& value )
134 std::vector< std::vector< double > > samples;
135 std::vector<unsigned int> samplesAttributesIndices;
136 std::vector<unsigned int> samplesLabels;
138 samplesAttributesIndices.push_back( 0 );
139 samplesAttributesIndices.push_back( 1 );
140 samplesAttributesIndices.push_back( 2 );
142 std::vector< double > sample;
147 sample.push_back( 41 );
148 sample.push_back( 212 );
149 sample.push_back( 81 );
150 samples.push_back( sample );
151 samplesLabels.push_back( 1 );
154 sample.push_back( 38 );
155 sample.push_back( 213 );
156 sample.push_back( 76 );
157 samples.push_back( sample );
158 samplesLabels.push_back( 1 );
161 sample.push_back( 42 );
162 sample.push_back( 128 );
163 sample.push_back( 70 );
164 samples.push_back( sample );
165 samplesLabels.push_back( 1 );
168 sample.push_back( 31 );
169 sample.push_back( 159 );
170 sample.push_back( 59 );
171 samples.push_back( sample );
172 samplesLabels.push_back( 1 );
177 sample.push_back( 39 );
178 sample.push_back( 36 );
179 sample.push_back( 81 );
180 samples.push_back( sample );
181 samplesLabels.push_back( 20 );
184 sample.push_back( 35 );
185 sample.push_back( 41 );
186 sample.push_back( 72 );
187 samples.push_back( sample );
188 samplesLabels.push_back( 20 );
191 sample.push_back( 39 );
192 sample.push_back( 42 );
193 sample.push_back( 76 );
194 samples.push_back( sample );
195 samplesLabels.push_back( 20 );
198 sample.push_back( 38 );
199 sample.push_back( 38 );
200 sample.push_back( 77 );
201 samples.push_back( sample );
202 samplesLabels.push_back( 20 );
207 std::map<std::string, std::string> auxRasterInfo;
209 auxRasterInfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop1.tif";
212 BOOST_CHECK( inputRasterPtrPointer.get() );
214 std::vector< unsigned int >
bands;
215 bands.push_back( 0 );
216 bands.push_back( 1 );
217 bands.push_back( 2 );
221 std::vector< te::rst::BandProperty* > bProps;
222 bProps.push_back(
new te::rst::BandProperty( *inputRasterPtrPointer->getBand( 0 )->getProperty() ) );
224 auxRasterInfo[
"URI"] =
"terralib_unittest_map_test_1.tif";
242 BOOST_CHECK( classifierInstance.
initialize( params ) );
244 BOOST_CHECK( classifierInstance.
train( samplesAdaptor, samplesAttributesIndices,
245 samplesLabels,
true ) );
250 std::vector< double > inputNoDataValues( inputRasterPtrPointer->getNumberOfBands(),
251 std::numeric_limits< double >::max() );
253 BOOST_CHECK( classifierInstance.
classify( inputRasterAdp, samplesAttributesIndices,
254 inputNoDataValues, outputRasterAdp, 0, 255,
true ) );
257 BOOST_AUTO_TEST_SUITE_END()
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
Classifiers raster output data adaptor.
This file contains include headers for the TerraLib Classification module.
A raster band description.
bool train(const InputAdaptor< double > &samples, const std::vector< unsigned int > &attributesIndices, const std::vector< unsigned int > &sampleLabels, const bool enableProgressInterface)
Train this classifier instance using the initialization parameters and the suppied train data...
bool initialize(const Parameters ¶ms)
Initialize this classifier instance with new parameters.
te::rst::Raster & m_raster
bool classify(const InputAdaptor< double > &input, const std::vector< unsigned int > &attributesIndices, const std::vector< double > &inputNoDataValues, OutputAdaptor< unsigned int > &output, const unsigned int outputIndex, const double outputNoDataValue, const bool enableProgressInterface)
Classify an input iterated data and save the result on the output iterated data.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
Classifiers output data adaptor.
MAP strategy for classification.
unsigned int getFeaturesCount() const
Returns the total features per element number.
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.
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
BOOST_AUTO_TEST_SUITE(classification_map_tests) BOOST_AUTO_TEST_CASE(map_test_1)
static Raster * make()
It creates and returns an empty raster with default raster driver.
BOOST_AUTO_TEST_CASE(encoding_test_utf8_latin1)
RasterOutputAdaptor(te::rst::Raster &raster)
A rectified grid is the spatial support for raster data.
unsigned int getElementsCount() const
Returns the total elements number.
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.