27 #ifndef __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
28 #define __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
31 #include "../common/STLUtils.h"
32 #include "../geometry.h"
82 virtual const std::vector<T>
operator*()
const = 0;
93 virtual T
operator[](
const unsigned int i)
const = 0;
104 virtual std::complex< T >
operator()(
const unsigned int i)
const = 0;
107 virtual unsigned int getRow()
const = 0;
110 virtual unsigned int getColumn()
const = 0;
141 virtual void setEnd() = 0;
187 std::complex< T >
operator()(
const unsigned int i)
const;
189 unsigned int getRow()
const;
237 std::vector<te::gm::LineString*>& decomposedGeoms )
const;
279 std::complex< T >
operator()(
const unsigned int i)
const;
281 unsigned int getRow()
const;
347 std::complex< T >
operator()(
const unsigned int i)
const;
349 unsigned int getRow()
const;
390 : m_raster(rhs.m_raster)
424 m_actualintersection(-1),
439 m_maxcolumns(r->getNumberOfColumns()),
440 m_maxrows(r->getNumberOfRows()),
441 m_actualintersection(-1),
446 throw te::rst::Exception(
TE_TR(
"Invalid polygon SRID") );
499 m_actualintersection(-1),
513 std::vector<te::gm::LineString*>& decomposedGeoms )
const
530 decomposedGeoms.push_back(static_cast<te::gm::LineString*> (
550 lineinter->
setX(0, pointinter->getX());
551 lineinter->
setY(0, pointinter->getY());
552 lineinter->
setX(1, pointinter->getX());
553 lineinter->
setY(1, pointinter->getY());
555 decomposedGeoms.push_back(lineinter);
570 decomposedGeoms.push_back(lineinter);
583 throw te::rst::Exception(
TE_TR(
584 "An exception has occurred in Polygon Iterator, with geometry " +
594 if (m_actualintersection == -1 || m_actualintersection >= m_nintersections)
598 double nexty = this->m_raster->getGrid()->gridToGeo(0, m_row).y;
600 m_currline->setX(0, m_polygon->getMBR()->getLowerLeft().x);
601 m_currline->setX(1, m_polygon->getMBR()->getUpperRight().x);
602 m_currline->setY(0, nexty);
603 m_currline->setY(1, nexty);
617 if (m_row > m_endingrow)
629 catch(
const std::exception& e)
631 std::cout <<
"Unhandled exception, status:" << std::endl;
632 std::cout <<
" m_startingcolumn: " << m_startingcolumn <<
" m_endingcolumn: " << m_endingcolumn << std::endl;
633 std::cout <<
" m_startingrow: " << m_startingrow <<
" m_endingrow: " << m_endingrow<< std::endl;
634 std::cout <<
" m_column: " << m_column <<
" m_row: " << m_row << std::endl;
635 std::cout <<
" intersection line: " << m_currline->toString() << std::endl << std::endl;
636 std::cout <<
" current polygon: " << m_polygon->toString() << std::endl << std::endl;
637 std::cout <<
" exception message: " << e.what() << std::endl;
638 std::cout << std::endl;
647 intersections->
add(inter);
649 m_actualintersection = 0;
651 m_intersections.clear();
652 decompose(intersections,m_intersections);
654 delete intersections;
656 m_nintersections = m_intersections.size();
666 if (m_startingcolumn > m_endingcolumn)
668 tmp = m_startingcolumn;
669 m_startingcolumn = m_endingcolumn;
670 m_endingcolumn = tmp;
674 m_startingcolumn = m_startingcolumn < 0? 0: m_startingcolumn;
675 m_startingcolumn = m_startingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_startingcolumn;
677 m_endingcolumn = m_endingcolumn < 0? 0: m_endingcolumn;
678 m_endingcolumn = m_endingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_endingcolumn;
683 std::vector<T> values(this->m_raster->getNumberOfBands());
686 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
688 this->m_raster->getValue(getColumn(), getRow(), value, b);
689 values[b] = ((T) value);
697 this->m_raster->getValue(m_column, m_row, m_operatorBrackets_value, i);
699 return (T) m_operatorBrackets_value;
704 this->m_raster->getValue(m_column, m_row, m_operatorParenthesis_value, i);
706 return (std::complex< T >) m_operatorParenthesis_value;
723 if (m_column > m_endingcolumn)
725 m_actualintersection++;
727 if (m_actualintersection >= m_nintersections)
730 if (m_row > m_endingrow)
739 m_column = m_startingcolumn;
747 if (m_column < m_startingcolumn)
749 m_actualintersection--;
751 if (m_actualintersection < 0)
754 if (m_row < m_startingrow)
763 m_column = m_endingcolumn;
779 for(
unsigned int intersectionsIdx = 0 ; intersectionsIdx <
829 return ( (this->m_row != rhs.
m_row) && (this->m_column != rhs.
m_column));
836 for(
unsigned int intersectionsIdx = 0 ; intersectionsIdx <
837 m_intersections.size() ; ++intersectionsIdx )
839 delete m_intersections[ intersectionsIdx ];
841 m_intersections.clear();
851 m_startingcolumn = 0;
857 m_actualintersection = -1;
858 m_nintersections = 0;
865 m_currentpixelindex(0),
873 m_currentpixelindex(0),
878 throw te::rst::Exception(
TE_TR(
"Invalid line SRID") );
887 if (inter->isEmpty())
898 double startingcolumn;
902 startingcolumn, startingrow);
908 endingcolumn, endingrow);
913 double x1, x2, y1, y2, geoX, geoY;
914 for(
int r = (
int)startingrow; r <= (int)endingrow; r++)
915 for(
int c = (
int)startingcolumn; c <= (int)endingcolumn; c++)
919 x1 = geoX - resXdiv2; y1 = geoY - resYdiv2;
920 x2 = geoX + resXdiv2; y2 = geoY + resYdiv2;
935 m_currentpixelindex(rhs.m_currentpixelindex),
936 m_pixelsinline(rhs.m_pixelsinline)
942 m_pixelsinline.clear();
947 std::vector<T> values(this->m_raster->getNumberOfBands());
950 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
952 this->m_raster->getValue(getColumn(), getRow(), value, b);
953 values[b] = ((T) value);
961 this->m_raster->getValue(getColumn(), getRow(), m_operatorBrackets_value, i);
963 return (T) m_operatorBrackets_value;
968 this->m_raster->getValue(getColumn(), getRow(), m_operatorParenthesis_value, i);
970 return (std::complex< T >) m_operatorParenthesis_value;
975 return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getY());
980 return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getX());
985 m_currentpixelindex++;
987 if (m_currentpixelindex >= (
int)(m_pixelsinline.size()))
993 m_currentpixelindex--;
995 if (m_currentpixelindex < 0)
1015 this->m_currentpixelindex = -1;
1040 m_pixelsinpointset(0),
1041 m_currentpixelindex(0)
1047 m_pixelsinpointset(p),
1048 m_currentpixelindex(0)
1056 std::vector<te::gm::Point*> inside_points;
1063 throw te::rst::Exception(
TE_TR(
"Invalid point SRID") );
1083 m_pixelsinpointset(rhs.m_pixelsinpointset),
1084 m_currentpixelindex(rhs.m_currentpixelindex)
1090 m_pixelsinpointset.clear();
1095 std::vector<T> values(this->m_raster->getNumberOfBands());
1098 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
1100 this->m_raster->getValue(getColumn(), getRow(), value, b);
1101 values[b] = ((T) value);
1109 this->m_raster->getValue(getColumn(), getRow(), m_operatorBrackets_value, i);
1111 return (T) m_operatorBrackets_value;
1116 this->m_raster->getValue(getColumn(), getRow(), m_operatorParenthesis_value, i);
1118 return (std::complex< T >) m_operatorParenthesis_value;
1123 return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getY());
1128 return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getX());
1133 m_currentpixelindex++;
1135 if (m_currentpixelindex >= (
int) m_pixelsinpointset.size())
1141 m_currentpixelindex--;
1143 if (m_currentpixelindex < 0)
1162 this->m_currentpixelindex = -1;
1186 #endif // __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
virtual Geometry * intersection(const Geometry *const rhs) const
It returns a geometric object that represents the point set intersection with another geometry...
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
int m_row
The current row of the iterator.
void setEnd()
Sets the iterator position to the end of the current band.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
Point * getStartPoint() const
The length of this Curve in its associated spatial reference.
int m_startingcolumn
The starting column (in current line) to initialize the iteration.
int m_startingrow
The starting row of the iteration.
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.
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.
void decompose(te::gm::Geometry const *const g, std::vector< te::gm::LineString * > &decomposedGeoms) const
Decomponse one geometry collection in a vector of basic components (line, point). ...
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
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...
virtual unsigned int getRow() const =0
Returns the current row in iterator.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
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.
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.
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.
virtual std::complex< T > operator()(const unsigned int i) const =0
Returns the complex value in current position (column, row, band) from iterator.
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.
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...
int m_endingcolumn
The column (in current line) to finalize the iteration.
AbstractPositionIterator()
Constructor.
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.
virtual bool isEmpty() const
It returns true if this geometric object is the empty Geometry.
An exception class for the Raster module.
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.
MultiPoint is a GeometryCollection whose elements are restricted to points.
LineString is a curve with linear interpolation between points.
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 double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
virtual unsigned int getColumn() const =0
Returns the current column in iterator.
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.
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.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
double m_operatorBrackets_value
Used by the operator[] method.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void operator--()
Returns to the previous position.
Point * getEndPoint() const
It returns the curve end point.
MultiLineString is a MultiCurve whose elements are LineStrings.
te::dt::AbstractData * clone() const
It clones the line.
int getSRID() const
Returns the raster spatial reference system identifier.
std::vector< te::gm::Point * > m_pixelsinpointset
The spatial restriction to be applied in the iterator.
~AbstractPositionIterator()
Destructor.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
void operator--()
Returns to the previous position.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
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.
const te::rst::Raster * m_raster
The band from where to get the values.
void add(Geometry *g)
It adds the geometry into the collection.
unsigned int getColumn() const
Returns the current column in iterator.
std::complex< double > m_operatorParenthesis_value
Used by the operator() method.
static LineIterator end(const te::rst::Raster *r, const te::gm::Line *l)
Returns an iterator referring to after the end of the iterator.
std::string toString() const
It returns the data value in a WKT representation.
virtual bool operator!=(const AbstractPositionIterator &rhs) const
Difference operator.
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.
A rectified grid is the spatial support for raster data.
unsigned int getRow() const
Returns the current row in iterator.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
AbstractPositionIterator & operator=(const AbstractPositionIterator &rhs)
Assignment operator.
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
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 T operator[](const unsigned int i) const =0
Returns the real value in current position (column, row, band) from iterator.
void operator--()
Returns to the previous position.
unsigned int getColumn() const
Returns the current column in iterator.
It is a collection of other geometric objects.
virtual AbstractData * clone() const =0
It returns a clone of this object.
std::vector< te::gm::LineString * > m_intersections
The points or lines of the intersection between the geometry and the current line.
const std::vector< T > operator*() const
Returns a vector of the values in current position (column, row) from iterator.
LineIterator & operator=(const LineIterator &rhs)
unsigned int getRow() const
Returns the current row in iterator.
const double & getX() const
It returns the Point x-coordinate value.
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.