27 #include "../core/translator/Translator.h" 28 #include "../geometry/Envelope.h" 29 #include "../geometry/MultiPolygon.h" 30 #include "../geometry/Polygon.h" 31 #include "../geometry/Utils.h" 32 #include "../raster/Band.h" 33 #include "../raster/BandProperty.h" 47 return "Minimum value";
49 return "Maximum value";
53 return "Sum of values";
55 return "Total number of values";
57 return "Total not null values";
59 return "Total number of distinct values";
61 return "Standard deviation";
73 return "Coefficient variation";
77 return "Class with highest occurrence";
79 return "Class with highest intersection area";
81 return "Percentage per Class";
83 return "Minimum Distance";
85 return "Minimum Distance From Centroid";
89 return "Weighted by Area";
91 return "Weighted Sum by Area";
93 return "Percentage of each Class by Area";
95 return "Percentage of Total Area";
103 double colD=-1, rowD=-1;
105 int col =
static_cast<int>(std::round(colD));
106 int row =
static_cast<int>(std::round(rowD));
109 col = std::numeric_limits<uint32_t>::max();
111 row = std::numeric_limits<uint32_t>::max();
113 return std::make_pair(col, row);
118 uint32_t &minimumRow, uint32_t &minimumColumn,
119 uint32_t &maximumRow, uint32_t &maximumColumn)
121 std::unique_ptr<te::gm::Polygon> polygonTemp(
122 dynamic_cast<te::gm::Polygon*>(polygon.
clone()));
124 if (polygonTemp->getSRID() != raster.
getSRID())
125 polygonTemp->transform(raster.
getSRID());
127 auto polygonEnvelope = polygonTemp->getMBR();
129 auto lowerLeftCoord2D = polygonEnvelope->getLowerLeft();
130 auto upperRightCoord2D = polygonEnvelope->getUpperRight();
134 std::tie(minimumColumn, maximumRow) =
GeoToGrid(lowerLeftCoord2D, *grid);
135 if(minimumColumn == std::numeric_limits<uint32_t>::max())
138 if(maximumRow == std::numeric_limits<uint32_t>::max())
139 maximumRow = grid->getNumberOfRows()-1;
141 std::tie(maximumColumn, minimumRow) =
GeoToGrid(upperRightCoord2D, *grid);
142 if(minimumRow == std::numeric_limits<uint32_t>::max())
145 if(maximumColumn == std::numeric_limits<uint32_t>::max())
146 maximumColumn = grid->getNumberOfColumns()-1;
150 const unsigned int &
band,
152 const uint32_t &minimumRow,
153 const uint32_t &minimumColumn,
154 const uint32_t &maximumRow,
155 const uint32_t &maximumColumn,
156 std::map<double, int> &values)
162 std::unique_ptr<te::gm::Geometry> polygonTemp(
163 dynamic_cast<te::gm::Geometry*>(polygon.
clone()));
165 if (polygonTemp->getSRID() != raster.
getSRID())
166 polygonTemp->transform(raster.
getSRID());
171 auto yResolution = grid->getResolutionY();
173 for(uint32_t row = minimumRow; row <= maximumRow; ++row)
175 for(uint32_t
col = minimumColumn;
col <= maximumColumn; ++
col)
177 auto pixelCenter = grid->gridToGeo(
col, row);
179 std::unique_ptr<te::gm::Envelope> pixelEnvelope(
new te::gm::Envelope(pixelCenter.getX()-(xResolution/2.),
180 pixelCenter.getY()-(yResolution/2.),
181 pixelCenter.getX()+(xResolution/2.),
182 pixelCenter.getY()+(yResolution/2.)));
184 std::unique_ptr<te::gm::Geometry> pixelEnvelopeAsGeometry(
187 if(pixelEnvelopeAsGeometry->intersects(polygonTemp.get()) ==
false)
193 if(value == noDataValue)
202 const unsigned int &
band,
204 const uint32_t &minimumRow,
205 const uint32_t &minimumColumn,
206 const uint32_t &maximumRow,
207 const uint32_t &maximumColumn,
208 std::map<double, double> &percentOfEachClassByArea)
212 double polygonArea = polygon.
getArea();
214 std::unique_ptr<te::gm::Geometry> polygonTemp(
215 dynamic_cast<te::gm::Geometry*>(polygon.
clone()));
217 if (polygonTemp->getSRID() != raster.
getSRID())
218 polygonTemp->transform(raster.
getSRID());
223 auto yResolution = grid->getResolutionY();
225 for(uint32_t row = minimumRow; row <= maximumRow; ++row)
227 for(uint32_t
col = minimumColumn;
col <= maximumColumn; ++
col)
229 auto pixelCenter = grid->gridToGeo(
col, row);
231 std::unique_ptr<te::gm::Envelope> pixelEnvelope(
new te::gm::Envelope(pixelCenter.getX()-(xResolution/2.),
232 pixelCenter.getY()-(yResolution/2.),
233 pixelCenter.getX()+(xResolution/2.),
234 pixelCenter.getY()+(yResolution/2.)));
236 std::unique_ptr<te::gm::Geometry> pixelEnvelopeAsGeometry(
239 std::unique_ptr<te::gm::Geometry> pixelIntersectedGeometry(
240 pixelEnvelopeAsGeometry->intersection(polygonTemp.get()));
242 if(pixelIntersectedGeometry ==
nullptr)
245 double currentPixelArea;
247 switch (pixelIntersectedGeometry->getGeomTypeId()) {
251 currentPixelArea = polygon.
getArea()/polygonArea;
257 currentPixelArea = multiPolygon.
getArea()/polygonArea;
261 currentPixelArea = 0;
268 std::map<double, double>::iterator it = percentOfEachClassByArea.find(value);
269 if(it != percentOfEachClassByArea.end())
270 percentOfEachClassByArea[it->first] += currentPixelArea;
272 percentOfEachClassByArea.insert(std::pair<double, double>(value, currentPixelArea));
unsigned int getNumberOfRows() const
Returns the grid number of rows.
MultiPolygon is a MultiSurface whose elements are Polygons.
TEATTRIBUTEFILLEXPORT void GetValuesFromBand(const te::rst::Raster &raster, const unsigned int &band, const gm::Polygon &polygon, const uint32_t &minimumRow, const uint32_t &minimumColumn, const uint32_t &maximumRow, const uint32_t &maximumColumn, std::map< double, int > &values)
Gets the pixel values for a specific band that intersects the polygon.
TEATTRIBUTEFILLEXPORT std::pair< uint32_t, uint32_t > GeoToGrid(const te::gm::Coord2D &coord, const rst::Grid &grid)
Convert the coordinate to the grid col/row postion of the pixel .
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
TEATTRIBUTEFILLEXPORT void GetMinMaxLineAndColumn(const te::rst::Raster &raster, const te::gm::Polygon &polygon, uint32_t &minimumRow, uint32_t &minimumColumn, uint32_t &maximumRow, uint32_t &maximumColumn)
Gets the minimum and maximum row and column values of the raster based on polygon.
virtual te::dt::AbstractData * clone() const
It clones the linestring.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
BandProperty * getProperty()
Returns the band property.
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
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 getArea() const
It returns the area of this surface, as measured in the spatial reference system of this surface...
int getSRID() const
Returns the raster spatial reference system identifier.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getX() const
It returns the x-coordinate.
double getArea() const
It returns the area of this MultiSurface, as measured in the spatial reference system of this multisu...
TEATTRIBUTEFILLEXPORT void GetPercentOfEachClassByArea(const te::rst::Raster &raster, const unsigned int &band, const gm::Polygon &polygon, const uint32_t &minimumRow, const uint32_t &minimumColumn, const uint32_t &maximumRow, const uint32_t &maximumColumn, std::map< double, double > &percentOfEachClassByArea)
Gets the pixel percentage for a specific band that intersects the polygon.
TEATTRIBUTEFILLEXPORT std::string GetOperationFullName(const int &e)
Gets the full name of the operation as string.
A rectified grid is the spatial support for raster data.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.