27 #include <terralib_buildconfig.h> 34 #include "../Config.h" 40 #include <boost/test/unit_test.hpp> 41 #include <boost/shared_ptr.hpp> 45 void drawPolygonInRaster( const
te::gm::Polygon& polygon,
46 const
unsigned char polValue,
47 const
te::
rst::
Grid& rasterGrid, const
std::
string& rasterFileName )
51 std::vector< te::rst::BandProperty * > bandsProps;
54 bandsProps[ 0 ]->m_noDataValue = 255;
56 std::map< std::string, std::string > rasterInfo;
57 rasterInfo[
"URI" ] = rasterFileName;
63 const unsigned int nLines = rasterPointer->getNumberOfRows();
64 const unsigned nCols = rasterPointer->getNumberOfColumns();
65 unsigned int band = 0;
66 unsigned int line = 0;
73 rasterPointer->setValue( col, line, 0, band );
89 rasterPointer->setValue(it.
getColumn(), it.
getRow(), (double)polValue, 0);
97 std::vector< te::rst::BandProperty * > bandsProps;
98 for(
unsigned int bandsPropsIdx = 0 ; bandsPropsIdx < nBands ; ++bandsPropsIdx )
102 bandsProps[ bandsPropsIdx ]->m_noDataValue = 0;
107 std::map< std::string, std::string >(), 0, 0 ) );
109 unsigned int band = 0;
110 unsigned int line = 0;
111 unsigned int col = 0;
114 for( band = 0 ; band < nBands ; ++
band )
116 for( col = 0 ; col <
nCols ; ++
col )
118 rasterPointer->setValue( col, line, pixelValue, band );
124 void Copy2DiskShp(std::vector<te::gm::Polygon*> polygons, std::string shpName)
126 std::unique_ptr< te::mem::DataSet> memDataSetPtr;
132 propPtr->
setSRID(polygons[0]->getSRID());
133 dataSetTypePtr->add(propPtr);
137 for (
unsigned int polygonsIdx = 0; polygonsIdx < polygons.size(); polygonsIdx++)
142 memDataSetPtr->add(dsItemPtr);
145 std::string connInfo(
"file://" + shpName);
150 memDataSetPtr->moveBeforeFirst();
152 te::da::Create(dsOGR.get(), dataSetTypePtr.get(), memDataSetPtr.get());
158 const std::string& fileName )
168 unsigned int bandIdx =0;
170 std::vector< te::rst::BandProperty* > bandsProperties;
171 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
177 std::unique_ptr< te::rst::Raster > outRasterPtr;
179 std::map< std::string, std::string > rInfo;
180 rInfo[
"URI" ] = fileName;
191 unsigned int col = 0;
192 unsigned int row = 0;
194 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
199 for( row = 0 ; row < nRows ; ++row )
201 for( col = 0 ; col <
nCols ; ++
col )
204 outBand.
setValue( col, row, value );
213 const double& lateralSize,
int srid)
216 double halfSize = lateralSize * 0.5;
217 s->
setPoint(0, xCenter - halfSize, yCenter - halfSize);
218 s->
setPoint(1, xCenter - halfSize, yCenter + halfSize);
219 s->
setPoint(2, xCenter + halfSize, yCenter + halfSize);
220 s->
setPoint(3, xCenter + halfSize, yCenter - halfSize);
221 s->
setPoint(4, xCenter - halfSize, yCenter - halfSize);
226 const double& diagonalSize,
int srid)
229 double halfSize = diagonalSize * 0.5;
230 s->
setPoint(0, xCenter - halfSize, yCenter);
231 s->
setPoint(1, xCenter, yCenter + halfSize);
232 s->
setPoint(2, xCenter + halfSize, yCenter);
233 s->
setPoint(3, xCenter, yCenter - halfSize);
234 s->
setPoint(4, xCenter - halfSize, yCenter);
266 rasterPointer->getGrid()->getSRID() ) );
268 double pixelValueCounter = 0;
270 for(
unsigned int band = 0 ;
band < rasterPointer->getNumberOfBands() ;
289 while ( (*itPtr) != (*itEndPtr) )
291 BOOST_CHECK_EQUAL((
double)pixelValueCounter, itPtr->operator[](
band ) );
292 BOOST_CHECK_EQUAL(row, (
int)itPtr->
getRow());
293 BOOST_CHECK_EQUAL(col, (
int)itPtr->
getColumn());
299 if (col < rasterPointer->getNumberOfColumns() - 1)
307 BOOST_CHECK_EQUAL(count, 9);
315 const unsigned int nLines = 30;
316 const unsigned int nCols = 30;
318 std::vector< te::rst::BandProperty * > bandsProps;
321 bandsProps[ 0 ]->m_noDataValue = 0;
329 std::map< std::string, std::string >(), 0, 0 ) );
331 unsigned int band = 0;
332 unsigned int line = 0;
333 unsigned int col = 0;
337 for( col = 0 ; col <
nCols ; ++
col )
339 rasterPointer->setValue( col, line, 0, band );
345 rasterPointer->getSRID()) );
347 internalPol_1->add(l1);
350 rasterPointer->getSRID()) );
352 internalPol_2->add(l2);
355 rasterPointer->getSRID()) );
357 internalPol_3->add(l3);
360 rasterPointer->getSRID()) );
368 internalPol_4->add(l4);
371 rasterPointer->getSRID()) );
386 internalPol_5->add(l5);
389 rasterPointer->getSRID()) );
396 internalPol_6->add(l6);
399 rasterPointer->getSRID()) );
401 internalPol_7->add( l7 );
404 rasterPointer->getSRID()) );
406 internalPol_8->add( l8 );
409 rasterPointer->getSRID()) );
411 internalPol_9->add( l9 );
414 rasterPointer->getSRID()) );
416 internalPol_10->add( l10 );
419 rasterPointer->getSRID()) );
421 internalPol_11->add( l11 );
424 rasterPointer->getGrid()->getExtent(), rasterPointer->getGrid()->getSRID()) );
439 std::vector<te::gm::Polygon* > polVector;
440 polVector.push_back(internalPol_1.get());
441 polVector.push_back(internalPol_2.get());
442 polVector.push_back(internalPol_3.get());
443 polVector.push_back(internalPol_4.get());
444 polVector.push_back(internalPol_5.get());
445 polVector.push_back(internalPol_6.get());
446 polVector.push_back(internalPol_7.get());
447 polVector.push_back(internalPol_8.get());
448 polVector.push_back(internalPol_9.get());
449 polVector.push_back(internalPol_10.get());
450 polVector.push_back(internalPol_11.get());
451 polVector.push_back(externalPol.get());
455 double pixelValueCounter = 0;
457 for (
int countPol = 0; countPol < polVector.size(); countPol++)
461 polVector[countPol]);
464 polVector[countPol]);
471 rasterPointer->setValue(it.
getColumn(), it.
getRow(), (countPol + 1), 0);
486 std::vector<te::gm::Polygon*> polVector( 1 );
492 polygonPtr->add(linearRingPtr);
493 polygonPtr->setSRID( rasterGrid.
getSRID() );
494 polVector[ 0 ] = polygonPtr.get();
495 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test1.shp" );
496 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
497 "polygonIterator3_outsidepol_test1.tif" );
507 polygonPtr->add(linearRingPtr);
509 polVector[ 0 ] = polygonPtr.get();
510 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test2.shp" );
511 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
512 "polygonIterator3_outsidepol_test2.tif" );
522 polygonPtr->add(linearRingPtr);
524 polVector[ 0 ] = polygonPtr.get();
525 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test3.shp" );
526 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
527 "polygonIterator3_outsidepol_test3.tif" );
539 polygonPtr->add(linearRingPtr);
541 polVector[ 0 ] = polygonPtr.get();
542 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test4.shp" );
543 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
544 "polygonIterator3_outsidepol_test4.tif" );
555 polygonPtr->add(linearRingPtr);
557 polVector[ 0 ] = polygonPtr.get();
558 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test5.shp" );
559 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
560 "polygonIterator3_outsidepol_test5.tif" );
576 polygonPtr->add(linearRingPtr);
577 polygonPtr->setSRID( rasterGrid.
getSRID() );
578 polVector[ 0 ] = polygonPtr.get();
579 Copy2DiskShp( polVector,
"polygonIterator3_outsidepol_test6.shp" );
580 drawPolygonInRaster( *polygonPtr, 1, rasterGrid,
581 "polygonIterator3_outsidepol_test6.tif" );
589 Copy2DiskRaster( *rasterPointer,
"polygonIterator_NDisjointBBOXIterationT_test1.tif" );
593 rasterPointer->getGrid()->getSRID() ) );
595 double pixelValueCounter = 0;
597 for(
unsigned int band = 0 ;
band < rasterPointer->getNumberOfBands() ;
610 while ( it != itEnd )
612 BOOST_CHECK_EQUAL((
double)pixelValueCounter, it(
band ) );
613 BOOST_CHECK_EQUAL(row, (
int)it.
getRow());
614 BOOST_CHECK_EQUAL(col, (
int)it.
getColumn());
620 if (col < rasterPointer->getNumberOfColumns() - 1)
628 BOOST_CHECK_EQUAL(count, 9);
636 const unsigned int nLines = 30;
637 const unsigned int nCols = 30;
639 std::vector< te::rst::BandProperty * > bandsProps;
642 bandsProps[ 0 ]->m_noDataValue = 0;
650 std::map< std::string, std::string >(), 0, 0 ) );
652 unsigned int band = 0;
653 unsigned int line = 0;
654 unsigned int col = 0;
658 for( col = 0 ; col <
nCols ; ++
col )
660 rasterPointer->setValue( col, line, 0, band );
666 rasterPointer->getSRID()) );
668 internalPol_1->add(l1);
671 rasterPointer->getSRID()) );
673 internalPol_2->add(l2);
676 rasterPointer->getSRID()) );
678 internalPol_3->add(l3);
681 rasterPointer->getSRID()) );
689 internalPol_4->add(l4);
692 rasterPointer->getSRID()) );
707 internalPol_5->add(l5);
710 rasterPointer->getSRID()) );
717 internalPol_6->add(l6);
720 rasterPointer->getSRID()) );
722 internalPol_7->add( l7 );
725 rasterPointer->getSRID()) );
727 internalPol_8->add( l8 );
730 rasterPointer->getSRID()) );
732 internalPol_9->add( l9 );
735 rasterPointer->getSRID()) );
737 internalPol_10->add( l10 );
740 rasterPointer->getSRID()) );
742 internalPol_11->add( l11 );
745 rasterPointer->getGrid()->getExtent(), rasterPointer->getGrid()->getSRID()) );
760 std::vector<te::gm::Polygon* > polVector;
761 polVector.push_back(internalPol_1.get());
762 polVector.push_back(internalPol_2.get());
763 polVector.push_back(internalPol_3.get());
764 polVector.push_back(internalPol_4.get());
765 polVector.push_back(internalPol_5.get());
766 polVector.push_back(internalPol_6.get());
767 polVector.push_back(internalPol_7.get());
768 polVector.push_back(internalPol_8.get());
769 polVector.push_back(internalPol_9.get());
770 polVector.push_back(internalPol_10.get());
771 polVector.push_back(internalPol_11.get());
772 polVector.push_back(externalPol.get());
774 Copy2DiskShp( polVector,
"polygonIterator_NDisjointBBOXIterationT_test2.shp" );
776 double pixelValueCounter = 0;
778 for (
int countPol = 0; countPol < polVector.size(); countPol++)
792 rasterPointer->setValue(it.
getColumn(), it.
getRow(), (countPol + 1), 0);
800 Copy2DiskRaster( *rasterPointer,
"polygonIterator_NDisjointBBOXIterationT_test2.tif" );
803 BOOST_AUTO_TEST_SUITE_END ()
unsigned int unsigned int std::unique_ptr< te::rst::Raster > & rasterPointer
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
This file contains include headers for the memory data source of TerraLib.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
te::gm::LinearRing * createSquare(const double &xCenter, const double &yCenter, const double &lateralSize, int srid)
A raster band description.
int getSRID() const
Returns the grid spatial reference system identifier.
A class that models the description of a dataset.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
double m_urx
Upper right corner x-coordinate.
This class is the base for implementing ways to navigate over the band with spatial restriction...
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
void CreateTestRaster(unsigned int nBands, unsigned int nLines, unsigned int nCols, boost::shared_ptr< te::rst::Raster > &rasterPointer, bool zero)
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
te::dt::AbstractData * clone() const
It clones the linear ring.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
unsigned int unsigned int nCols
bool Copy2DiskRaster(const te::rst::Raster &inputRaster, const std::string &fileName)
Coord2D getCenter() const
It returns the rectangle's center coordinate.
A LinearRing is a LineString that is both closed and simple.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
void Copy2DiskShp(std::vector< te::gm::Polygon * > polygons, std::string shpName)
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.
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
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.
BandProperty * getProperty()
Returns the band property.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
This file contains include headers for the TerraLib Raster Processing module.
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.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
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.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double m_ury
Upper right corner y-coordinate.
static Raster * make()
It creates and returns an empty raster with default raster driver.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
BOOST_AUTO_TEST_SUITE(rasterIterator_tests) void drawPolygonInRaster(const te
This file contains include headers for the Vector Geometry model of TerraLib.
te::gm::LinearRing * createRotatedSquare(const double &xCenter, const double &yCenter, const double &diagonalSize, int srid)
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
This file contains include headers for the Data Access module of TerraLib.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
BOOST_AUTO_TEST_CASE(rasterIteratorConstructor1_test)