27 #ifndef __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H 28 #define __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H 31 #include "../common/STLUtils.h" 32 #include "../common/MathUtils.h" 33 #include "../core/logger/Logger.h" 34 #include "../geometry.h" 73 virtual const std::vector<T>
operator*()
const = 0;
84 virtual T
operator[](
const unsigned int i)
const = 0;
95 virtual std::complex< T >
operator()(
const unsigned int i)
const = 0;
98 virtual unsigned int getRow()
const = 0;
101 virtual unsigned int getColumn()
const = 0;
132 virtual void setEnd() = 0;
180 void setNextLine(
bool updatecurrline =
true);
186 std::complex< T >
operator()(
const unsigned int i)
const;
188 unsigned int getRow()
const;
275 std::complex< T >
operator()(
const unsigned int i)
const;
277 unsigned int getRow()
const;
348 std::complex< T >
operator()(
const unsigned int i)
const;
350 unsigned int getRow()
const;
419 m_actualintersection(-1),
441 throw te::rst::Exception(
TE_TR(
"Invalid polygon SRID") );
453 ( ll.
x > rasterEnvelope.
m_urx )
455 ( ur.
x < rasterEnvelope.
m_llx )
457 ( ur.
y < rasterEnvelope.
m_lly )
459 ( ll.
y > rasterEnvelope.
m_ury )
535 const double& rasterEnvelopeLLX =
537 const double& rasterEnvelopeURX =
564 std::vector<te::gm::Point*> intersectionPoints;
573 assert(currentTilePtr);
576 std::unique_ptr<te::gm::Line> tileSeg;
577 std::unique_ptr< te::gm::Geometry > interResultPtr;
578 std::vector< te::gm::Geometry * > singleGeomsPtrs;
579 std::size_t singleGeomsPtrsIdx = 0;
588 for (std::size_t i = 0; i < currentTilePtr->size(); i++)
590 assert((*currentTilePtr)[i].first < m_polygon->getNumRings());
593 assert(dynamic_cast<te::gm::LinearRing const*>((*
m_polygon)[(*currentTilePtr)[i].first]));
596 assert((*currentTilePtr)[i].second < m_polygon->getNPoints());
600 ringTile->
getY((*currentTilePtr)[i].second),
603 ringTile->
getY((*currentTilePtr)[i].second + 1),
609 interResultPtr.reset( tileSeg->intersection(
m_currline ) );
611 if( interResultPtr.get() != 0 )
613 for(
auto p : singleGeomsPtrs)
615 singleGeomsPtrs.clear();
618 for( singleGeomsPtrsIdx = 0 ; singleGeomsPtrsIdx < singleGeomsPtrs.size() ;
619 ++singleGeomsPtrsIdx )
621 if( singleGeomsPtrs[ singleGeomsPtrsIdx ]->getGeomTypeId() ==
625 singleGeomsPtrs[ singleGeomsPtrsIdx ]->clone() ) );
627 else if( singleGeomsPtrs[ singleGeomsPtrsIdx ]->getGeomTypeId() ==
631 singleGeomsPtrsIdx ]);
632 intersectionPoints.push_back( lineStrPtr->
getStartPoint().release() );
633 intersectionPoints.push_back( lineStrPtr->
getEndPoint().release() );
639 catch(
const std::exception& e)
641 TE_LOG_WARN(
"Geometry intersection error:" + e.what() );
645 for( std::size_t intersectionPointsIdx = 0; intersectionPointsIdx <
646 intersectionPoints.size() ; ++intersectionPointsIdx )
648 delete intersectionPoints[intersectionPointsIdx];
651 intersectionPoints.clear();
659 for( std::size_t intersectionPointsIdx = 0; intersectionPointsIdx <
660 intersectionPoints.size() ; ++intersectionPointsIdx )
662 delete intersectionPoints[intersectionPointsIdx];
665 intersectionPoints.clear();
668 for(
auto p : singleGeomsPtrs)
670 singleGeomsPtrs.clear();
676 std::size_t positionBegin = 0;
677 std::size_t positionEnd = 0;
678 std::vector<te::gm::Point*> intersectionPointsAux = intersectionPoints;
680 intersectionPoints.clear();
682 while( positionBegin < intersectionPointsAux.size() )
684 if( intersectionPointsAux[positionBegin] )
686 positionEnd = positionBegin + 1;
688 while( positionEnd < intersectionPointsAux.size() )
691 ( intersectionPointsAux[positionEnd] != 0 )
693 intersectionPointsAux[positionBegin]->equals(
694 intersectionPointsAux[positionEnd],
true)
697 delete intersectionPointsAux[positionEnd];
698 intersectionPointsAux[positionEnd] = 0;
704 intersectionPoints.push_back( intersectionPointsAux[positionBegin] );
712 std::sort(intersectionPoints.begin(), intersectionPoints.end(),
718 std::size_t positionBegin = 0;
719 std::size_t positionEnd = 0;
722 double startingX = 0;
723 double startingY = 0;
727 while( ( positionBegin + 1 ) < intersectionPoints.size() )
729 positionEnd = positionBegin + 1;
731 startingX = intersectionPoints[positionBegin]->getX();
732 startingX = std::max( startingX, rasterEnvelopeLLX );
734 startingY = intersectionPoints[positionBegin]->getY();
736 endingX = intersectionPoints[positionEnd]->getX();
737 endingX = std::min( endingX, rasterEnvelopeURX );
739 endingY = intersectionPoints[positionEnd]->getY();
746 ( startingX != endingX )
750 (startingX + (endingX - startingX) / 2.0 ),
751 (startingY +(endingY - startingY) / 2.0 ),
760 startingCol = std::max( 0, startingCol );
761 startingCol = std::min(
m_maxcolumns - 1, startingCol );
764 endingCol = std::max( 0, endingCol );
767 if( endingCol >= startingCol )
769 m_columns.push_back(std::pair<int, int>(startingCol, endingCol));
773 positionBegin = positionEnd;
780 while ( positionBegin < intersectionPoints.size() )
782 delete intersectionPoints[positionBegin];
833 values[b] = ((T) value);
890 throw te::rst::Exception(
TE_TR(
"This operation is not supported!"));
1016 m_currentpixelindex(0),
1029 throw te::rst::Exception(
TE_TR(
"Invalid line SRID") );
1038 if (inter->isEmpty())
1049 double startingcolumn;
1051 std::unique_ptr<te::gm::Point> startpoint = inrasterline->
getStartPoint();
1053 startingcolumn, startingrow);
1055 double endingcolumn;
1057 std::unique_ptr<te::gm::Point> endpoint = inrasterline->
getEndPoint();
1059 endingcolumn, endingrow);
1064 double x1, x2, y1, y2, geoX, geoY;
1065 for(
int r = (
int)startingrow; r <= (int)endingrow; r++)
1066 for(
int c = (
int)startingcolumn; c <= (int)endingcolumn; c++)
1070 x1 = geoX - resXdiv2; y1 = geoY - resYdiv2;
1071 x2 = geoX + resXdiv2; y2 = geoY + resYdiv2;
1104 values[b] = ((T) value);
1164 template<
typename T>
1195 template<
typename T>
1205 m_pixelsinpointset(0),
1221 std::vector<te::gm::Point*> inside_points;
1228 throw te::rst::Exception(
TE_TR(
"Invalid point SRID") );
1266 values[b] = ((T) value);
1325 template<
typename T>
1356 template<
typename T>
1366 #endif // __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H unsigned int getNumberOfRows() const
Returns the grid number of rows.
int m_row
The current row of the iterator.
void setEnd()
Sets the iterator position to the end of the current band.
virtual T operator[](const unsigned int i) const =0
Returns the real value in current position (column, row, band) from iterator.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
int m_startingcolumn
The starting column (in current line) to initialize the iteration.
int m_startingrow
The starting row of the iteration.
Polygon tile indexing class for optmized geometrical relational tests.
A Line is LineString with 2 points.
It describes one band (or dimension) of a raster.
Coord2D getLowerLeft() const
It returns the lower left coordinate of the envelope.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
void setX(std::size_t i, const double &x)
It sets the n-th x coordinate value.
virtual bool operator!=(const AbstractPositionIterator< T > &rhs) const =0
Difference operator.
const te::gm::Line * m_line
The spatial restriction to be applied in the iterator.
int m_nintersections
The number number of intersected lines in current line of the iterator.
void setEnd()
Sets the iterator position to the end of the current band.
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
te::gm::Line * m_currline
The current line in the iterator.
double m_operatorBrackets_value
Used by the operator[] method.
virtual void operator--()=0
Returns to the previous position.
int m_maxcolumns
The number of columns in band.
bool operator!=(const PolygonIterator< T > &rhs) const
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
unsigned int getColumn() const
Returns the current column in iterator.
int m_currentpixelindex
The index of the current pixel location.
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...
double m_urx
Upper right corner x-coordinate.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
double m_operatorBrackets_value
Used by the operator[] method.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
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.
bool StdSortPointPointerComparison(te::gm::Point *p1, te::gm::Point *p2)
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.
bool operator!=(const PointSetIterator< T > &rhs) const
void operator++()
Advances to the next position.
int m_actualintersection
The actual line of the iterator.
const te::gm::Polygon * m_polygon
The spatial restriction to be applied in the iterator.
bool operator!=(const LineIterator< T > &rhs) const
#define TE_TR(message)
It marks a string in order to get translated.
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
virtual std::complex< T > operator()(const unsigned int i) const =0
Returns the complex value in current position (column, row, band) from iterator.
PolygonIterator & operator=(const PolygonIterator &rhs)
PointSetIterator & operator=(const PointSetIterator &rhs)
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 raster data.
int m_endingrow
The ending row of the iteration.
Grid * getGrid()
It returns the raster grid.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
int m_endingcolumn
The column (in current line) to finalize the iteration.
AbstractPositionIterator()
Constructor.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
Utility functions for dealing with raster data blocks.
void setNextLine(bool updatecurrline=true)
virtual void operator++()=0
Advances to the next position.
void operator++()
Advances to the next position.
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
std::unique_ptr< Point > getStartPoint() const
The length of this Curve in its associated spatial reference.
A LinearRing is a LineString that is both closed and simple.
An exception class for the Raster module.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
Coord2D getUpperRight() const
It returns the upper right coordinate of the envelope.
std::vector< te::gm::Point * > m_pixelsinline
A vector of pixel locations that intersects the line.
double m_llx
Lower left corner x-coordinate.
LineString is a curve with linear interpolation between points.
const te::rst::Raster * m_raster
The band from where to get the values.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
const te::rst::Raster * m_raster
The band from where to get the values.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
const te::rst::Raster * m_raster
The band from where to get the values.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
int m_currentpixelindex
The index of the current pixel location.
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
int m_maxrows
The number of rows in band.
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
void setEnd()
Sets the iterator position to the end of the current band.
It gives access to values in one band (dimension) of a raster.
void clear()
Clear all internal allocated objects and reset back to the initial state.
virtual void setEnd()=0
Sets the iterator position to the end of the current band.
virtual const std::vector< T > operator*() const =0
Returns a vector of the values in current position (column, row) from iterator.
double m_operatorBrackets_value
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void operator--()
Returns to the previous position.
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.
double m_lly
Lower left corner y-coordinate.
te::dt::AbstractData * clone() const
It clones the line.
int getSRID() const
Returns the raster spatial reference system identifier.
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...
std::vector< te::gm::Point * > m_pixelsinpointset
The spatial restriction to be applied in the iterator.
virtual ~AbstractPositionIterator()
Destructor.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
void operator--()
Returns to the previous position.
A rectified grid is the spatial support for raster data.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
double m_ury
Upper right corner y-coordinate.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
int m_column
The current column of the iterator.
unsigned int getColumn() const
Returns the current column in iterator.
std::complex< double > m_operatorParenthesis_value
static LineIterator end(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to after the end of the iterator.
T operator[](const unsigned int i) const
Returns the real value in current position (column, row, band) from iterator.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
unsigned int getRow() const
Returns the current row in iterator.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
std::vector< std::pair< int, int > > m_columns
Coordinates of the columns to be transversed.
virtual unsigned int getRow() const =0
Returns the current row in iterator.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
#define TE_LOG_WARN(message)
Use this tag in order to log a message to the TerraLib default logger with the WARN level...
std::complex< T > operator()(const unsigned int i) const
Returns the complex value in current position (column, row, band) from iterator.
void operator++()
Advances to the next position.
virtual unsigned int getColumn() const =0
Returns the current column in iterator.
void operator--()
Returns to the previous position.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
std::unique_ptr< Point > getEndPoint() const
It returns the curve end point.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
virtual AbstractPositionIterator< T > & operator=(const AbstractPositionIterator< T > &rhs)
Assignment operator.
LineIterator & operator=(const LineIterator &rhs)
unsigned int getRow() const
Returns the current row in iterator.
std::unique_ptr< te::rst::TileIndexer > m_tileIndexer
Tile indexer used to optimize the geometric operations.
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 LineIterator begin(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to the first value of the band.