20 #include <boost/random/mersenne_twister.hpp> 21 #include <boost/random/uniform_int_distribution.hpp> 25 std::cout <<
"Example of Band Iterator" << std::endl;
28 std::map<std::string, std::string> rinfo;
29 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
39 double max = std::numeric_limits<unsigned char>::min();
54 std::cout << std::endl;
55 std::cout <<
" using iterator" << std::endl;
56 std::cout <<
" the maximum value for band 0 is " << max << std::endl;
58 max = std::numeric_limits<double>::min();
69 std::cout <<
" not using iterator" << std::endl;
70 std::cout <<
" the maximum value for band 0 is " << max << std::endl << std::endl;
78 std::cout <<
"Example of Band Iterator Mask" << std::endl;
81 std::map<std::string, std::string> rinfo;
82 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
88 std::map<std::string, std::string> minfo;
89 minfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_mask_1bit.tif";
93 std::map<std::string, std::string> orinfo;
94 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_mask_8bits.tif";
96 std::vector<te::rst::BandProperty*> obprops;
106 std::vector<std::complex<double> > pixels;
123 std::cout <<
"Example of Raster Iterator" << std::endl;
126 std::map<std::string, std::string> rinfo;
127 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
131 std::vector<unsigned int>
bands;
156 std::cout << std::endl;
157 std::cout <<
" the mean for band " << bands[0] <<
" is " << mean0 / N << std::endl;
158 std::cout <<
" the mean for band " << bands[1] <<
" is " << mean1 / N << std::endl << std::endl;
166 std::cout <<
"Example of Band Iterator Window" << std::endl;
169 std::map<std::string, std::string> rinfo;
170 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
174 std::map<std::string, std::string> orinfo;
175 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_band3_crop_median_5x5.tif";
179 std::vector<te::rst::BandProperty*>
bands;
199 std::set<unsigned char> values;
202 if ((R > (
unsigned)(H / 2) && R < inraster->getNumberOfRows() - (H / 2)) &&
203 (C > (
unsigned)(W / 2) && C < inraster->getNumberOfColumns() - (W / 2)))
205 for (
int r = -(H / 2); r <= (H / 2); r++)
206 for (
int c = -(W / 2); c <= (W / 2); c++)
212 std::set<unsigned char>::iterator vit = values.begin();
215 for (std::size_t i = 0; i < values.size()/2; i++)
218 outraster->
setValue(C, R, (
double) *vit);
223 std::cout << std::endl <<
" Check the file " << orinfo[
"URI"] << std::endl << std::endl;
232 std::cout <<
"Example of Polygon Iterator" << std::endl;
235 std::map<std::string, std::string> rinfo;
236 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
239 unsigned int nvalues = 0;
240 double sum_pixels = 0.0;
262 sum_pixels += (*it)[0];
270 mean = sum_pixels / nvalues;
272 std::cout <<
"The average pixel value (mean) inside the upper left region of band 0 is: " << mean << std::endl << std::endl;
274 std::cout <<
"Done!" << std::endl << std::endl;
282 std::cout <<
"Example of Line Iterator" << std::endl;
285 std::map<std::string, std::string> rinfo;
286 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
295 std::vector<double> pixels_in_line;
303 pixels_in_line.push_back((*it)[0]);
308 std::cout <<
"Pixels in line: ";
309 for (
unsigned int i = 0; i < pixels_in_line.size(); i++)
310 std::cout << pixels_in_line[i] <<
" ";
311 std::cout << std::endl << std::endl;
313 std::cout <<
"Done!" << std::endl << std::endl;
321 std::cout <<
"Example of Point Set Iterator" << std::endl;
324 std::map<std::string, std::string> rinfo;
325 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
329 int srid = inraster->
getSRID();
330 std::vector<te::gm::Point*> points;
332 boost::random::mt19937 gen(static_cast<boost::uint32_t>(std::time(0)));
335 for (
unsigned int i = 0; i < 50; i++)
342 std::vector<double> pixels_in_points;
350 pixels_in_points.push_back((*it)[0]);
355 std::cout <<
"Pixels in point set: ";
356 for (
unsigned int i = 0; i < pixels_in_points.size(); i++)
357 std::cout << pixels_in_points[i] <<
" ";
358 std::cout << std::endl << std::endl;
360 std::cout <<
"Done!" << std::endl << std::endl;
370 std::cout <<
"This test creates iterators over Bands, Windows, and Rasters." << std::endl << std::endl;
380 std::cout <<
"Done!" << std::endl << std::endl;
382 catch(
const std::exception& e)
384 std::cout << std::endl <<
"An exception has occurred in ExemplifyIterators(): " << e.what() << std::endl;
388 std::cout << std::endl <<
"An unexpected exception has occurred in ExemplifyIterators()!" << std::endl;
This class implements an iterator to "navigate" over a single band, with a spatial restriction given ...
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.
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell.
unsigned int getRow() const
Returns the current row in iterator.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
A Line is LineString with 2 points.
unsigned int getColumn() const
Returns the current column in iterator.
void ExemplifyIterators()
An example to test iterators over Bands, Windows, and Rasters.
A raster band description.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
unsigned int getColumn() const
Returns the current column in iterator.
This class implements and iterator to "navigate" over a raster, with a predefined number of bands...
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const
Returns the imaginary attribute values in all complex bands of a cell.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
void ExemplifyPointSetIterator()
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
static PointSetIterator end(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to after the end of the iterator.
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
unsigned int getRow() const
Returns the current row in iterator.
It implements and iterator to "navigate" over a single band, optimized by a window structure (e...
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
static BandIterator begin(Band *b)
Returns an iterator referring to the first value of the band.
Utility functions for the raster module.
A LinearRing is a LineString that is both closed and simple.
This is the abstract factory for Rasters.
static BandIteratorWithMask end(Band *b, Raster *m)
Returns an iterator with the mask referring to after the end of the iterator.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
A point with x and y coordinate values.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An abstract class for raster data strucutures.
static RasterIterator begin(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to the first value.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
It implements an iterator to "navigate" over a single band (const or not const).
void ExemplifyPolygonIterator()
void ExemplifyBandIteratorMask()
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
void ExemplifyBandIteratorWindow()
static BandIteratorWindow end(Band const *const b, std::size_t w, const std::size_t h)
Returns an iterator referring to after the end of the iterator.
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, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
It implements and iterator to "navigate" over a raster, with a predefined number of bands...
int getSRID() const
Returns the raster spatial reference system identifier.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
A rectified grid is the spatial support for raster data.
These routines show how to use the raster module and the GDAL data source module. ...
This class implements an iterator to "navigate" over a single band.
static Raster * make()
It creates and returns an empty raster with default raster driver.
static LineIterator end(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to after the end of the iterator.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
static RasterIterator end(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to after the end of the iterator.
void ExemplifyRasterIterator()
static BandIteratorWithMask begin(Band *b, Raster *m)
Returns an iterator with the mask referring to the first value of the band.
A rectified grid is the spatial support for raster data.
It implements and iterator to "navigate" over a single band, optimized by a window structure (e...
static BandIterator end(Band *b)
Returns an iterator referring to after the end of the iterator.
void ExemplifyBandIterator()
static BandIteratorWindow begin(Band const *const b, std::size_t w, const std::size_t h)
Returns an iterator referring to the first value of the band.
T getValue() const
Returns the value in current position (column, row) from iterator.
void ExemplifyLineIterator()
static PointSetIterator begin(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to the first value of the band.
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.
static LineIterator begin(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to the first value of the band.