27#ifndef __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
28#define __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
95 virtual std::complex< T >
operator()(
const unsigned int i)
const = 0;
98 virtual unsigned int getRow()
const = 0;
204 std::complex< T >
operator()(
const unsigned int i)
const;
206 unsigned int getRow()
const;
274 std::vector<std::pair<int, int> >& intersectionRanges )
const;
282 std::vector<std::pair<int, int> >& intersectionRanges )
const;
291 std::vector<std::pair<int, int> >& intersectionRanges )
const;
313 std::vector< te::gm::Geometry const * >& geoms)
const;
352 std::complex< T >
operator()(
const unsigned int i)
const;
354 unsigned int getRow()
const;
425 std::complex< T >
operator()(
const unsigned int i)
const;
427 unsigned int getRow()
const;
501 throw te::rst::Exception(
TE_TR(
"Iterator initialization error") );
511 throw te::rst::Exception(
TE_TR(
"Iterator initialization error") );
528 std::vector<T> values(
m_raster->getNumberOfBands());
531 for (
unsigned int b = 0; b < this->
m_raster->getNumberOfBands(); b++)
534 values[b] = ((T) value);
787 std::vector<std::pair<int, int> >& intersectionRanges )
const
808 throw te::rst::Exception(
TE_TR(
"Invalid iteration type") );
816 std::vector<std::pair<int, int> >& intersectionRanges )
const
818 intersectionRanges.clear();
822 const double& rasterEnvelopeLLX =
823 m_raster->getGrid()->getExtent()->m_llx;
824 const double& rasterEnvelopeURX =
825 m_raster->getGrid()->getExtent()->m_urx;
829 const double lineY = this->
m_raster->getGrid()->gridToGeo(0, (
double)lineIndex).y;
835 currline.
setX(0, std::min(
837 m_polygon->getMBR()->getLowerLeft().x) );
838 currline.
setY(0, lineY);
840 currline.
setX(1, std::max(
842 m_polygon->getMBR()->getUpperRight().x ) );
843 currline.
setY(1, lineY);
846 std::vector<te::gm::Point*> intersectionPoints;
856 ( currentTilePtr != 0 )
860 std::unique_ptr<te::gm::Line> tileSeg;
861 std::unique_ptr< te::gm::Geometry > interResultPtr;
862 std::vector< te::gm::Geometry const* > singleGeomsPtrs;
863 std::size_t singleGeomsPtrsIdx = 0;
872 for (std::size_t i = 0; i < currentTilePtr->size(); i++)
874 assert((*currentTilePtr)[i].first < m_polygon->getNumRings());
880 assert((*currentTilePtr)[i].second < m_polygon->getNPoints());
884 ringTile->
getY((*currentTilePtr)[i].second),
887 ringTile->
getY((*currentTilePtr)[i].second + 1),
893 interResultPtr.reset( tileSeg->intersection( &currline ) );
895 if( interResultPtr.get() != 0 )
897 singleGeomsPtrs.clear();
900 for( singleGeomsPtrsIdx = 0 ; singleGeomsPtrsIdx < singleGeomsPtrs.size() ;
901 ++singleGeomsPtrsIdx )
903 if( singleGeomsPtrs[ singleGeomsPtrsIdx ]->getGeomTypeId() ==
907 singleGeomsPtrs[ singleGeomsPtrsIdx ]->clone() ) );
909 else if( singleGeomsPtrs[ singleGeomsPtrsIdx ]->getGeomTypeId() ==
913 singleGeomsPtrsIdx ]);
915 if( lineStrPtr->
size() > 1 )
917 intersectionPoints.push_back( lineStrPtr->
getStartPoint().release() );
918 intersectionPoints.push_back( lineStrPtr->
getEndPoint().release() );
925 catch(
const std::exception& e)
927 TE_LOG_WARN(
"Geometry intersection error:" + e.what() );
931 for( std::size_t intersectionPointsIdx = 0; intersectionPointsIdx <
932 intersectionPoints.size() ; ++intersectionPointsIdx )
934 delete intersectionPoints[intersectionPointsIdx];
937 intersectionPoints.clear();
945 for( std::size_t intersectionPointsIdx = 0; intersectionPointsIdx <
946 intersectionPoints.size() ; ++intersectionPointsIdx )
948 delete intersectionPoints[intersectionPointsIdx];
951 intersectionPoints.clear();
958 std::size_t positionBegin = 0;
959 std::size_t positionEnd = 0;
960 std::vector<te::gm::Point*> intersectionPointsAux = intersectionPoints;
962 intersectionPoints.clear();
964 while( positionBegin < intersectionPointsAux.size() )
966 if( intersectionPointsAux[positionBegin] )
968 positionEnd = positionBegin + 1;
970 while( positionEnd < intersectionPointsAux.size() )
973 ( intersectionPointsAux[positionEnd] != 0 )
975 intersectionPointsAux[positionBegin]->equals(
976 intersectionPointsAux[positionEnd],
true)
979 delete intersectionPointsAux[positionEnd];
980 intersectionPointsAux[positionEnd] = 0;
986 intersectionPoints.push_back( intersectionPointsAux[positionBegin] );
994 std::sort(intersectionPoints.begin(), intersectionPoints.end(),
1000 std::size_t positionBegin = 0;
1001 std::size_t positionEnd = 0;
1002 int startingCol = 0;
1004 double startingX = 0;
1005 double startingY = 0;
1009 while( ( positionBegin + 1 ) < intersectionPoints.size() )
1011 positionEnd = positionBegin + 1;
1013 startingX = intersectionPoints[positionBegin]->getX();
1014 startingX = std::max( startingX, rasterEnvelopeLLX );
1016 startingY = intersectionPoints[positionBegin]->getY();
1018 endingX = intersectionPoints[positionEnd]->getX();
1019 endingX = std::min( endingX, rasterEnvelopeURX );
1021 endingY = intersectionPoints[positionEnd]->getY();
1028 ( startingX != endingX )
1032 (startingX + (endingX - startingX) / 2.0 ),
1033 (startingY +(endingY - startingY) / 2.0 ),
1041 startingCol = (int)std::ceil(
m_raster->getGrid()->geoToGrid(startingX, startingY).x );
1042 startingCol = std::max( 0, startingCol );
1045 endingCol = (int)std::floor(
m_raster->getGrid()->geoToGrid(endingX, endingY).x );
1046 endingCol = std::max( 0, endingCol );
1049 if( endingCol >= startingCol )
1051 intersectionRanges.push_back(std::pair<int, int>(startingCol, endingCol));
1055 positionBegin = positionEnd;
1062 while ( positionBegin < intersectionPoints.size() )
1064 delete intersectionPoints[positionBegin];
1069 template<
typename T>
1071 const bool areDisjoint, std::vector<std::pair<int, int> >& intersectionRanges )
const
1073 intersectionRanges.clear();
1075 double ulXCoord = 0;
1076 double ulYCoord = 0;
1078 ((
double)lineIndex) - 0.5, ulXCoord, ulYCoord);
1080 const double yRes = this->
m_raster->getGrid()->getResolutionY();
1081 const double xRes = this->
m_raster->getGrid()->getResolutionX();
1088 bool rangeStarted =
false;
1089 std::pair<int, int> range;
1094 currBBOXCoordsPtr[ 0 ].
x = currBBOXCoordsPtr[ 4 ].
x =
1096 currBBOXCoordsPtr[ 0 ].
y = currBBOXCoordsPtr[ 4 ].
y = ulYCoord;
1099 currBBOXCoordsPtr[ 1 ].
x = currBBOXCoordsPtr[ 0 ].
x + xRes;
1100 currBBOXCoordsPtr[ 1 ].
y = ulYCoord;
1103 currBBOXCoordsPtr[ 2 ].
x = currBBOXCoordsPtr[ 1 ].
x;
1104 currBBOXCoordsPtr[ 2 ].
y = ulYCoord - yRes;
1107 currBBOXCoordsPtr[ 3 ].
x = currBBOXCoordsPtr[ 0 ].
x;
1108 currBBOXCoordsPtr[ 3 ].
y = ulYCoord - yRes;
1118 rangeStarted =
true;
1119 range.first = range.second = col;
1126 rangeStarted =
false;
1127 intersectionRanges.push_back( range );
1135 intersectionRanges.push_back( range );
1139 template<
typename T>
1165 ( ll.
x > rasterEnvelope.
m_urx )
1167 ( ur.
x < rasterEnvelope.
m_llx )
1169 ( ur.
y < rasterEnvelope.
m_lly )
1171 ( ll.
y > rasterEnvelope.
m_ury )
1250 template<
typename T>
1253 std::vector< te::gm::Geometry const * >& geoms)
const
1263 for (std::size_t i = 0; i < nGeoms ; ++i)
1271 geoms.push_back( g );
1295 throw te::rst::Exception( TE_TR(
"Invalid line SRID") );
1298 int srid = this->m_raster->getSRID();
1304 if (inter->isEmpty())
1315 double startingcolumn;
1317 std::unique_ptr<te::gm::Point> startpoint = inrasterline->
getStartPoint();
1318 this->m_raster->getGrid()->geoToGrid(startpoint->getX(), startpoint->getY(),
1319 startingcolumn, startingrow);
1321 double endingcolumn;
1323 std::unique_ptr<te::gm::Point> endpoint = inrasterline->getEndPoint();
1324 this->m_raster->getGrid()->geoToGrid(endpoint->getX(), endpoint->getY(),
1325 endingcolumn, endingrow);
1328 const double resXdiv2 = this->m_raster->getResolutionX() / 2;
1329 const double resYdiv2 = this->m_raster->getResolutionY() / 2;
1330 double x1, x2, y1, y2, geoX, geoY;
1331 for(
int r = (
int)startingrow; r <= (
int)endingrow; r++)
1332 for(
int c = (
int)startingcolumn; c <= (
int)endingcolumn; c++)
1335 this->m_raster->getGrid()->gridToGeo(c, r, geoX, geoY);
1336 x1 = geoX - resXdiv2; y1 = geoY - resYdiv2;
1337 x2 = geoX + resXdiv2; y2 = geoY + resYdiv2;
1339 te::gm::Envelope* pixelbox = new te::gm::Envelope(x1, y1, x2, y2);
1340 te::gm::Geometry* pixelboxgeometry = GetGeomFromEnvelope(pixelbox, srid);
1342 if (te::gm::SatisfySpatialRelation(inrasterline, pixelboxgeometry, te::gm::INTERSECTS))
1343 m_pixelsinline.push_back(new te::gm::Point(c, r, srid));
1364 std::vector<T> values(this->
m_raster->getNumberOfBands());
1367 for (
unsigned int b = 0; b < this->
m_raster->getNumberOfBands(); b++)
1370 values[b] = ((T) value);
1430 template<
typename T>
1461 template<
typename T>
1481 const int rasterSRID = this->
m_raster->getSRID();
1484 te::gm::Geometry* rasterboxgeometry = GetGeomFromEnvelope(rasterbox, rasterSRID);
1487 std::vector<te::gm::Point*> inside_points;
1494 throw te::rst::Exception(
TE_TR(
"Invalid point SRID") );
1526 std::vector<T> values(this->
m_raster->getNumberOfBands());
1529 for (
unsigned int b = 0; b < this->
m_raster->getNumberOfBands(); b++)
1532 values[b] = ((T) value);
1591 template<
typename T>
1622 template<
typename T>
It describes one band (or dimension) of a raster.
Utility functions for dealing with raster data blocks.
This class is designed to manage the log of information in TerraLib.
#define TE_LOG_WARN(message)
Use this tag in order to log a message to the TerraLib default logger with the WARN level.
This file contains several utility functions for dealing with STL containers.
#define TE_TR(message)
It marks a string in order to get translated.
An Envelope defines a 2D rectangular region.
double m_llx
Lower left corner x-coordinate.
double m_urx
Upper right corner x-coordinate.
double m_ury
Upper right corner y-coordinate.
double m_lly
Lower left corner y-coordinate.
It is a collection of other geometric objects.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual Geometry * intersection(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set intersection with another geometry.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
virtual bool disjoint(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially disjoint from rhs geometry.
LineString is a curve with linear interpolation between points.
void setX(std::size_t i, const double &x)
It sets the n-th x coordinate value.
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
std::unique_ptr< Point > getEndPoint() const
It returns the curve end point.
void setNumCoordinates(std::size_t size)
It reserves room for the number of coordinates in this LineString.
std::size_t size() const
It returns the number of points (vertexes) in the geometry.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
std::unique_ptr< Point > getStartPoint() const
The length of this Curve in its associated spatial reference.
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
A Line is LineString with 2 points.
A LinearRing is a LineString that is both closed and simple.
A point with x and y coordinate values.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
This class is the base for implementing ways to navigate over the band with spatial restriction,...
virtual T operator[](const unsigned int i) const =0
Returns the real value in current position (column, row, band) from iterator.
virtual const std::vector< T > operator*() const =0
Returns a vector of the values in current position (column, row) from iterator.
virtual void operator--()=0
Returns to the previous position.
virtual std::complex< T > operator()(const unsigned int i) const =0
Returns the complex value in current position (column, row, band) from iterator.
virtual ~AbstractPositionIterator()
Destructor.
virtual AbstractPositionIterator< T > & operator=(const AbstractPositionIterator< T > &rhs)
Assignment operator.
virtual unsigned int getRow() const =0
Returns the current row in iterator.
virtual bool operator!=(const AbstractPositionIterator< T > &rhs) const =0
Difference operator.
AbstractPositionIterator()
Constructor.
virtual void operator++()=0
Advances to the next position.
virtual void setEnd()=0
Sets the iterator position to the end of the current band.
virtual unsigned int getColumn() const =0
Returns the current column in iterator.
A raster band description.
A rectified grid is the spatial support for raster data.
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
static LineIterator begin(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to the first value of the band.
void operator--()
Returns to the previous position.
bool operator!=(const LineIterator< T > &rhs) const
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
static LineIterator end(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to after the end of the iterator.
unsigned int getColumn() const
Returns the current column in iterator.
unsigned int getRow() const
Returns the current row in iterator.
LineIterator & operator=(const LineIterator &rhs)
double m_operatorBrackets_value
Used by the operator[] method.
void setEnd()
Sets the iterator position to the end of the current band.
void operator++()
Advances to the next position.
const te::gm::Line * m_line
The spatial restriction to be applied in the iterator.
std::vector< te::gm::Point * > m_pixelsinline
A vector of pixel locations that intersects the line.
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
const te::rst::Raster * m_raster
The band from where to get the values.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
int m_currentpixelindex
The index of the current pixel location.
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
PointSetIterator & operator=(const PointSetIterator &rhs)
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
unsigned int getRow() const
Returns the current row in iterator.
unsigned int getColumn() const
Returns the current column in iterator.
void operator--()
Returns to the previous position.
bool operator!=(const PointSetIterator< T > &rhs) const
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
void setEnd()
Sets the iterator position to the end of the current band.
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.
std::vector< te::gm::Point * > m_pixelsinpointset
The spatial restriction to be applied in the iterator.
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
int m_currentpixelindex
The index of the current pixel location.
double m_operatorBrackets_value
Used by the operator[] method.
const te::rst::Raster * m_raster
The band from where to get the values.
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.
void operator++()
Advances to the next position.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
PolygonIterator & operator=(const PolygonIterator &rhs)
const te::gm::Polygon * m_polygon
The spatial restriction to be applied in the iterator (default 0).
bool operator!=(const PolygonIterator< T > &rhs) const
int m_row
The current row of the iterator (default -1).
int m_totalRasterColumns
The number of columns in band (default: 0).
int m_polygonEndingRow
Polygon last raster row (default: -1).
void breakIntoSingleGeoms(te::gm::Geometry const *const g, std::vector< te::gm::Geometry const * > &geoms) const
It will get a GeometryCollection and distribute in a vector.
void setEnd()
Sets the iterator position to the end of the current band.
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
std::vector< std::pair< int, int > > m_currentLineIntersectionRanges
Coordinates of the columns to be transversed.
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
int m_polygonStartingColumn
Polygon first raster column (default: -1).
void getIntersectionRanges(int lineIndex, std::vector< std::pair< int, int > > &intersectionRanges) const
Returns the given line intersection ranges (Coordinates of the columns to be transversed) using the c...
void clear()
Clear all internal allocated objects and reset back to the initial state.
IterationType m_iterationType
Current iteration type (default ScanLineIterationT).
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.
void getBBOXIntersectionRanges(int lineIndex, const bool areDisjoint, std::vector< std::pair< int, int > > &intersectionRanges) const
Returns the given line intersection ranges using the pixel bounding box as reference.
void initiateVariables()
Initialize all internal variables to initial states.
void operator--()
Returns to the previous position.
int m_column
The current column of the iterator (default -1).
bool initialize(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Initialize this instance.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
const te::rst::Raster * m_raster
The band from where to get the values (default 0).
std::complex< double > m_operatorParenthesis_value
int m_currentRangeEndingColumn
The current line iteration range column to finalize the iteration (default: -1).
@ ScanLineIterationT
Scan line iteration type.
@ DisjointBBOXIterationT
Itaration over pixels whose bounding boxes are disjoint in relation with the polygon.
@ NDisjointBBOXIterationT
Itaration over pixels whose bounding boxes are not disjoint in relation with the polygon.
double m_operatorBrackets_value
void operator++()
Advances to the next position.
std::unique_ptr< te::rst::TileIndexer > m_tileIndexerPtr
Tile indexer used to optimize the geometric operations.
unsigned int getRow() const
Returns the current row in iterator.
int m_totalRasterRows
The number of rows in band (default: 0).
int m_currentLineIntersectionRangesIndex
The actual line of the iterator (default -1).
void getScanLineIntersectionRanges(int lineIndex, std::vector< std::pair< int, int > > &intersectionRanges) const
Returns the given line intersection ranges (Coordinates of the columns to be transversed) using the S...
int m_polygonStartingRow
Polygon first raster row (default: -1).
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
int m_polygonEndingColumn
Polygon last raster column (default: -1).
unsigned int getColumn() const
Returns the current column in iterator.
int m_currentRangeStartingColumn
The current line iteration range starting column (default: -1).
An abstract class for raster data strucutures.
Grid * getGrid()
It returns the raster grid.
int getSRID() const
Returns the raster spatial reference system identifier.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Polygon tile indexing class for optmized geometrical relational tests.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
TEDATAACCESSEXPORT te::da::Expression * operator!=(const te::da::Expression &e1, const te::da::Expression &e2)
This file contains include headers for the Vector Geometry model of TerraLib.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
Namespace for the Raster module of TerraLib.
bool StdSortPointPointerComparison(te::gm::Point *p1, te::gm::Point *p2)
It gives access to values in one band (dimension) of a raster.
An exception class for the Raster module.
A rectified grid is the spatial support for raster data.
An utility struct for representing 2D coordinates.