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;
 
   91         virtual T 
operator[](
const unsigned int i) 
const = 0;
 
   94         virtual unsigned int getRow() 
const = 0;
 
   97         virtual unsigned int getColumn() 
const = 0;
 
  128         virtual void setEnd() = 0;
 
  183         unsigned int getRow() 
const;
 
  256         unsigned int getRow() 
const;
 
  319         unsigned int getRow() 
const;
 
  357       : m_raster(rhs.m_raster)
 
  392         m_actualintersection(-1),
 
  402         m_maxcolumns(r->getNumberOfColumns()),
 
  403         m_maxrows(r->getNumberOfRows()),
 
  404         m_actualintersection(-1),
 
  409         throw Exception( 
TE_TR(
"Invalid polygon SRID") );
 
  452         m_polygon(rhs.m_polygon),
 
  453         m_intersections(rhs.m_intersections),
 
  454         m_currline(rhs.m_currline),
 
  455         m_column(rhs.m_column),
 
  457         m_startingcolumn(rhs.m_startingcolumn),
 
  458         m_endingcolumn(rhs.m_endingcolumn),
 
  459         m_startingrow(rhs.m_startingrow),
 
  460         m_endingrow(rhs.m_endingrow),
 
  461         m_maxcolumns(rhs.m_maxcolumns),
 
  462         m_maxrows(rhs.m_maxrows),
 
  463         m_actualintersection(rhs.m_actualintersection),
 
  464         m_nintersections(rhs.m_nintersections)
 
  470       m_intersections.clear();
 
  475       std::vector<te::gm::LineString*> lines;
 
  511           lineinter->
setX(0, pointinter->getX());
 
  512           lineinter->
setY(0, pointinter->getY());
 
  513           lineinter->
setX(1, pointinter->getX());
 
  514           lineinter->
setY(1, pointinter->getY());
 
  516           lines.push_back(lineinter);
 
  531         lines.push_back(lineinter);
 
  538           std::vector<te::gm::LineString*> vg = decompose(gc->
getGeometryN(i));
 
  540           for (
unsigned int j = 0; j < vg.size(); j++)
 
  541             lines.push_back(vg[j]);
 
  547         std::string message = 
"An exception has occurred in Polygon Iterator, with geometry " + g->
toString();
 
  549         throw(message.c_str());
 
  560       if (m_actualintersection == -1 || m_actualintersection >= m_nintersections)
 
  564           double nexty = this->m_raster->getGrid()->gridToGeo(0, m_row).y;
 
  566           m_currline->setX(0, m_polygon->getMBR()->getLowerLeft().x);
 
  567           m_currline->setX(1, m_polygon->getMBR()->getUpperRight().x);
 
  568           m_currline->setY(0, nexty);
 
  569           m_currline->setY(1, nexty);
 
  583             if (m_row > m_endingrow)
 
  595         catch(
const std::exception& e)
 
  597           std::cout << 
"Unhandled exception, status:" << std::endl;
 
  598           std::cout << 
"  m_startingcolumn: " << m_startingcolumn << 
" m_endingcolumn: " << m_endingcolumn << std::endl;
 
  599           std::cout << 
"  m_startingrow: " << m_startingrow << 
" m_endingrow: " << m_endingrow<< std::endl;
 
  600           std::cout << 
"  m_column: " << m_column << 
" m_row: " << m_row << std::endl;
 
  601           std::cout << 
"  intersection line: " << m_currline->toString() << std::endl << std::endl;
 
  602           std::cout << 
"  current polygon: " << m_polygon->toString() << std::endl << std::endl;
 
  603           std::cout << 
"  exception message: " << e.what() << std::endl;
 
  604           std::cout << std::endl;
 
  613         intersections->
add(inter);
 
  615         m_actualintersection = 0;
 
  617         m_intersections.clear();
 
  619         m_intersections = decompose(intersections);
 
  621         m_nintersections = m_intersections.size();
 
  631       if (m_startingcolumn > m_endingcolumn)
 
  633         tmp = m_startingcolumn;
 
  634         m_startingcolumn = m_endingcolumn;
 
  635         m_endingcolumn = tmp;
 
  639       m_startingcolumn = m_startingcolumn < 0? 0: m_startingcolumn;
 
  640       m_startingcolumn = m_startingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_startingcolumn;
 
  642       m_endingcolumn = m_endingcolumn < 0? 0: m_endingcolumn;
 
  643       m_endingcolumn = m_endingcolumn >= m_maxcolumns? m_maxcolumns - 1: m_endingcolumn;
 
  648       std::vector<T> values(this->m_raster->getNumberOfBands());
 
  651       for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
 
  653         this->m_raster->getValue(getColumn(), getRow(), value, b);
 
  654         values[b] = ((T) value);
 
  664       this->m_raster->getValue(m_column, m_row, value, i);
 
  683       if (m_column > m_endingcolumn)
 
  685         m_actualintersection++;
 
  687         if (m_actualintersection >= m_nintersections)
 
  690         if (m_row > m_endingrow)
 
  699         m_column = m_startingcolumn;
 
  707       if (m_column < m_startingcolumn)
 
  709         m_actualintersection--;
 
  711         if (m_actualintersection < 0)
 
  714         if (m_row < m_startingrow)
 
  723         m_column = m_endingcolumn;
 
  762       return ( (this->m_row != rhs.
m_row) && (this->m_column != rhs.
m_column));
 
  769         m_currentpixelindex(0),
 
  777         m_currentpixelindex(0),
 
  786       if (inter->isEmpty())
 
  797       double startingcolumn;
 
  801                                            startingcolumn, startingrow);
 
  807                                            endingcolumn, endingrow);
 
  812       double x1, x2, y1, y2, geoX, geoY;
 
  813       for(
int r = (
int)startingrow; r <= (int)endingrow; r++)
 
  814         for(
int c = (
int)startingcolumn; c <= (int)endingcolumn; c++)
 
  818           x1 = geoX - resXdiv2; y1 = geoY - resYdiv2;
 
  819           x2 = geoX + resXdiv2; y2 = geoY + resYdiv2;
 
  831         m_currentpixelindex(rhs.m_currentpixelindex),
 
  832         m_pixelsinline(rhs.m_pixelsinline)
 
  838       m_pixelsinline.clear();
 
  843       std::vector<T> values(this->m_raster->getNumberOfBands());
 
  846       for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
 
  848         this->m_raster->getValue(getColumn(), getRow(), value, b);
 
  849         values[b] = ((T) value);
 
  859       this->m_raster->getValue(getColumn(), getRow(), value, i);
 
  865       return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getY());
 
  870       return (
unsigned int)(m_pixelsinline[m_currentpixelindex]->getX());
 
  875       m_currentpixelindex++;
 
  877       if (m_currentpixelindex >= (
int)(m_pixelsinline.size()))
 
  883       m_currentpixelindex--;
 
  885       if (m_currentpixelindex < 0)
 
  905       this->m_currentpixelindex = -1;
 
  930         m_pixelsinpointset(0),
 
  931         m_currentpixelindex(0)
 
  937         m_pixelsinpointset(p),
 
  938         m_currentpixelindex(0)
 
  946       std::vector<te::gm::Point*> inside_points;
 
  966         m_pixelsinpointset(rhs.m_pixelsinpointset),
 
  967         m_currentpixelindex(rhs.m_currentpixelindex)
 
  973       m_pixelsinpointset.clear();
 
  978       std::vector<T> values(this->m_raster->getNumberOfBands());
 
  981       for (
unsigned int b = 0; b < this->m_raster->getNumberOfBands(); b++)
 
  983         this->m_raster->getValue(getColumn(), getRow(), value, b);
 
  984         values[b] = ((T) value);
 
  994       this->m_raster->getValue(getColumn(), getRow(), value, i);
 
 1001       return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getY());
 
 1006       return (
unsigned int)(m_pixelsinpointset[m_currentpixelindex]->getX());
 
 1011       m_currentpixelindex++;
 
 1013       if (m_currentpixelindex >= (
int) m_pixelsinpointset.size())
 
 1019       m_currentpixelindex--;
 
 1021       if (m_currentpixelindex < 0)
 
 1040       this->m_currentpixelindex = -1;
 
 1064 #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. 
 
It describes one band (or dimension) of a raster. 
 
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 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
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. 
 
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. 
 
An exception class for the Raster module. 
 
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). ...
 
It gives access to values in one band (dimension) of a raster. 
 
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. 
 
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. 
 
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.