27 #ifndef __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
28 #define __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
31 #include "../common/STLUtils.h"
32 #include "../geometry.h"
33 #include "../raster/Band.h"
34 #include "../raster/BandProperty.h"
35 #include "../raster/BlockUtils.h"
36 #include "../raster/Grid.h"
81 virtual const std::vector<T>
operator*()
const = 0;
90 virtual T
operator[](
const unsigned int i)
const = 0;
93 virtual unsigned int getRow()
const = 0;
96 virtual unsigned int getColumn()
const = 0;
127 virtual void setEnd() = 0;
181 unsigned int getRow()
const;
254 unsigned int getRow()
const;
317 unsigned int getRow()
const;
355 : m_raster(rhs.m_raster)
390 m_actualintersection(-1),
400 m_maxcolumns(r->getNumberOfColumns()),
401 m_maxrows(r->getNumberOfRows()),
402 m_actualintersection(-1),
445 m_polygon(rhs.m_polygon),
446 m_intersections(rhs.m_intersections),
447 m_currline(rhs.m_currline),
448 m_column(rhs.m_column),
450 m_startingcolumn(rhs.m_startingcolumn),
451 m_endingcolumn(rhs.m_endingcolumn),
452 m_startingrow(rhs.m_startingrow),
453 m_endingrow(rhs.m_endingrow),
454 m_maxcolumns(rhs.m_maxcolumns),
455 m_maxrows(rhs.m_maxrows),
456 m_actualintersection(rhs.m_actualintersection),
457 m_nintersections(rhs.m_nintersections)
463 m_intersections.clear();
468 std::vector<te::gm::LineString*> lines;
504 lineinter->
setX(0, pointinter->getX());
505 lineinter->
setY(0, pointinter->getY());
506 lineinter->
setX(1, pointinter->getX());
507 lineinter->
setY(1, pointinter->getY());
509 lines.push_back(lineinter);
524 lines.push_back(lineinter);
531 std::vector<te::gm::LineString*> vg = decompose(gc->
getGeometryN(i));
533 for (
unsigned int j = 0; j < vg.size(); j++)
534 lines.push_back(vg[j]);
540 std::string message =
"An exception has occurred in Polygon Iterator, with geometry " + g->
toString();
542 throw(message.c_str());
553 if (m_actualintersection == -1 || m_actualintersection >= m_nintersections)
557 double nexty = this->m_raster->getGrid()->gridToGeo(0, m_row).y;
559 m_currline->setX(0, m_polygon->getMBR()->getLowerLeft().x);
560 m_currline->setX(1, m_polygon->getMBR()->getUpperRight().x);
561 m_currline->setY(0, nexty);
562 m_currline->setY(1, nexty);
576 if (m_row > m_endingrow)
588 catch(
const std::exception& e)
590 std::cout <<
"Unhandled exception, status:" << std::endl;
591 std::cout <<
" m_startingcolumn: " << m_startingcolumn <<
" m_endingcolumn: " << m_endingcolumn << std::endl;
592 std::cout <<
" m_startingrow: " << m_startingrow <<
" m_endingrow: " << m_endingrow<< std::endl;
593 std::cout <<
" m_column: " << m_column <<
" m_row: " << m_row << std::endl;
594 std::cout <<
" intersection line: " << m_currline->toString() << std::endl << std::endl;
595 std::cout <<
" current polygon: " << m_polygon->toString() << std::endl << std::endl;
596 std::cout <<
" exception message: " << e.what() << std::endl;
597 std::cout << std::endl;
606 intersections->
add(inter);
608 m_actualintersection = 0;
610 m_intersections.clear();
612 m_intersections = decompose(intersections);
614 m_nintersections = m_intersections.size();
624 if (m_startingcolumn > m_endingcolumn)
626 tmp = m_startingcolumn;
627 m_startingcolumn = m_endingcolumn;
628 m_endingcolumn = tmp;
632 m_startingcolumn = m_startingcolumn < 0? 0: m_startingcolumn;
633 m_startingcolumn = m_startingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_startingcolumn;
635 m_endingcolumn = m_endingcolumn < 0? 0: m_endingcolumn;
636 m_endingcolumn = m_endingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_endingcolumn;
641 std::vector<T> values(this->m_raster->getNumberOfBands());
644 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
646 this->m_raster->getValue(getColumn(), getRow(), value, b);
647 values[b] = ((T) value);
657 this->m_raster->getValue(m_column, m_row, value, i);
676 if (m_column > m_endingcolumn)
678 m_actualintersection++;
680 if (m_actualintersection >= m_nintersections)
683 if (m_row > m_endingrow)
692 m_column = m_startingcolumn;
700 if (m_column < m_startingcolumn)
702 m_actualintersection--;
704 if (m_actualintersection < 0)
707 if (m_row < m_startingrow)
716 m_column = m_endingcolumn;
755 return ( (this->m_row != rhs.
m_row) && (this->m_column != rhs.
m_column));
762 m_currentpixelindex(0),
770 m_currentpixelindex(0),
779 if (inter->isEmpty())
790 double startingcolumn;
794 startingcolumn, startingrow);
800 endingcolumn, endingrow);
805 double x1, x2, y1, y2, geoX, geoY;
806 for(
int r = (
int)startingrow; r <= (int)endingrow; r++)
807 for(
int c = (
int)startingcolumn; c <= (int)endingcolumn; c++)
811 x1 = geoX - resXdiv2; y1 = geoY - resYdiv2;
812 x2 = geoX + resXdiv2; y2 = geoY + resYdiv2;
824 m_currentpixelindex(rhs.m_currentpixelindex),
825 m_pixelsinline(rhs.m_pixelsinline)
831 m_pixelsinline.clear();
836 std::vector<T> values(this->m_raster->getNumberOfBands());
839 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
841 this->m_raster->getValue(getColumn(), getRow(), value, b);
842 values[b] = ((T) value);
852 this->m_raster->getValue(getColumn(), getRow(), value, i);
858 return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getY());
863 return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getX());
868 m_currentpixelindex++;
870 if (m_currentpixelindex >= (
int)(m_pixelsinline.size()))
876 m_currentpixelindex--;
878 if (m_currentpixelindex < 0)
898 this->m_currentpixelindex = -1;
923 m_pixelsinpointset(0),
924 m_currentpixelindex(0)
930 m_pixelsinpointset(p),
931 m_currentpixelindex(0)
939 std::vector<te::gm::Point*> inside_points;
959 m_pixelsinpointset(rhs.m_pixelsinpointset),
960 m_currentpixelindex(rhs.m_currentpixelindex)
966 m_pixelsinpointset.clear();
971 std::vector<T> values(this->m_raster->getNumberOfBands());
974 for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
976 this->m_raster->getValue(getColumn(), getRow(), value, b);
977 values[b] = ((T) value);
987 this->m_raster->getValue(getColumn(), getRow(), value, i);
994 return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getY());
999 return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getX());
1004 m_currentpixelindex++;
1006 if (m_currentpixelindex >= (
int) m_pixelsinpointset.size())
1012 m_currentpixelindex--;
1014 if (m_currentpixelindex < 0)
1033 this->m_currentpixelindex = -1;
1057 #endif // __TERRALIB_RASTER_INTERNAL_POSITIONITERATOR_H
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
int m_row
The current row of the iterator.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
void setEnd()
Sets the iterator position to the end of the current band.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
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.
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.
Point * getEndPoint() const
It returns the curve end point.
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.
te::gm::Line * m_currline
The current line in the iterator.
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 value in current position (column, row, band) from iterator.
Point * getStartPoint() const
The length of this Curve in its associated spatial reference.
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...
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
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...
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.
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
T operator[](const unsigned int i) const
Returns the 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.
int m_endingrow
The ending row of the iteration.
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.
void setNextLine(bool updatecurrline=true)
virtual void operator++()=0
Advances to the next position.
void operator++()
Advances to the next position.
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.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
int m_maxrows
The number of rows in band.
void setEnd()
Sets the iterator position to the end of the current band.
std::vector< te::gm::LineString * > decompose(te::gm::Geometry *g)
Decomponse one geometry collection in a vector of basic components (line, point). ...
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.
Grid * getGrid()
It returns the raster grid.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void operator--()
Returns to the previous position.
virtual bool isEmpty() const
It returns true if this geometric object is the empty Geometry.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
MultiLineString is a MultiCurve whose elements are LineStrings.
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.
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 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.
Coord2D getUpperRight() const
It returns the upper right coordinate of the envelope.
AbstractPositionIterator & operator=(const AbstractPositionIterator &rhs)
Assignment operator.
void setY(std::size_t i, const double &y)
It sets the n-th y coordinate value.
virtual Geometry * intersection(const Geometry *const rhs) const
It returns a geometric object that represents the point set intersection with another geometry...
void operator++()
Advances to the next position.
virtual T operator[](const unsigned int i) const =0
Returns the 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.
Coord2D getLowerLeft() const
It returns the lower left coordinate of the envelope.
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.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
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.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
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.