24 #include "../common/progress/TaskProgress.h"
25 #include "../common/Translator.h"
27 #include "../dataaccess/dataset/DataSet.h"
28 #include "../dataaccess/dataset/DataSetAdapter.h"
30 #include "../dataaccess/dataset/DataSetType.h"
31 #include "../dataaccess/dataset/DataSetTypeConverter.h"
32 #include "../dataaccess/dataset/ObjectIdSet.h"
33 #include "../dataaccess/datasource/DataSource.h"
34 #include "../dataaccess/datasource/DataSourceCapabilities.h"
35 #include "../dataaccess/utils/Utils.h"
37 #include "../datatype/Property.h"
38 #include "../datatype/StringProperty.h"
40 #include "../geometry.h"
42 #include "../memory/DataSetItem.h"
44 #include "../raster/RasterProperty.h"
45 #include "../raster/Utils.h"
47 #include "../rp/RasterAttributes.h"
48 #include "../rp/Texture.h"
50 #include "../statistics.h"
56 #include <boost/algorithm/string.hpp>
57 #include <boost/lexical_cast.hpp>
66 std::string inRasterName,
67 std::auto_ptr<te::da::DataSetType> inRasterDsType,
69 std::string inVectorName,
70 std::auto_ptr<te::da::DataSetType> inVectorDsType)
72 m_inRasterDsrc = inRasterDsrc;
73 m_inRasterName = inRasterName;
74 m_inRasterDsType = inRasterDsType;
75 m_inVectorDsrc = inVectorDsrc;
76 m_inVectorName = inVectorName;
77 m_inVectorDsType = inVectorDsType;
81 std::vector<te::stat::StatisticalSummary> statSum,
97 if (!m_inVectorDsType.get())
100 if (!m_inVectorDsType->hasGeom())
103 if (m_outDset.empty() || !m_outDsrc.get())
113 std::auto_ptr<te::da::DataSet> dsVector = m_inVectorDsrc->getDataSet(m_inVectorName);
118 std::auto_ptr<te::da::DataSet> dsRaster = m_inRasterDsrc->getDataSet(m_inRasterName);
119 std::auto_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->
getName());
120 double resX = raster->getResolutionX();
121 double resY = raster->getResolutionY();
130 bool percentByArea =
false;
131 std::vector<std::set<int> > pixelDistinct;
133 if (it != m_statSum.end())
135 pixelDistinct = getPixelDistinct(raster.get(), m_bands);
136 percentByArea =
true;
141 std::auto_ptr<te::da::DataSetType> outDsType;
143 outDsType = getDataSetType(pixelDistinct);
145 outDsType = getDataSetType();
147 std::auto_ptr<te::mem::DataSet> outDataset(
new te::mem::DataSet(outDsType.get()));
152 task.
setTotalSteps((
int)dsVector->size() * (int)m_statSum.size() * (int)m_bands.size());
156 dsVector->moveBeforeFirst();
157 while(dsVector->moveNext())
161 std::vector<te::dt::Property*> vecProp = m_inVectorDsType->getProperties();
162 for(std::size_t i = 0; i < vecProp.size(); ++i)
164 outDSetItem->
setValue(i, dsVector->getValue(i).release());
168 std::auto_ptr<te::gm::Geometry> geom = dsVector->getGeometry(vectorProp->
getName());
172 std::vector<std::vector<double> > valuesFromRaster;
173 valuesFromRaster.resize(m_bands.size());
176 bool contains =
true;
188 for(std::size_t n = 0; n < n_geom; ++n)
191 std::vector<std::vector<double> > tempValues = rasterAtt->
getValuesFromRaster(*raster, *polygon, m_bands);
193 for(std::size_t band = 0; band < tempValues.size(); ++band)
195 std::vector<double>::iterator it;
196 it = valuesFromRaster[band].end();
198 valuesFromRaster[band].insert(it,
199 tempValues[band].begin(),
200 tempValues[band].end());
220 std::size_t init_index = m_inVectorDsType->getProperties().size();
223 for(std::size_t band = 0; band < valuesFromRaster.size(); ++band)
231 std::size_t current_index = init_index + m_statSum.size();
233 for(std::size_t it = 0, i = init_index; i < current_index; ++it, ++i)
282 if (!summary.
m_mode.empty())
284 mode = boost::lexical_cast<std::string>(summary.
m_mode[0]);
285 for(std::size_t m=1; m<summary.
m_mode.size(); ++m)
288 mode += boost::lexical_cast<std::string>(summary.
m_mode[m]);
300 std::set<int>::iterator itPixelDistinct = pixelDistinct[band].begin();
303 while (itPixelDistinct != pixelDistinct[band].end())
308 std::vector<std::string> splitString;
309 boost::split(splitString, name, boost::is_any_of(
"_"));
310 if (splitString[1] == boost::lexical_cast<std::string>(itPercent->first))
312 outDSetItem->
setDouble(i, itPercent->second);
327 current_index += pixelDistinct[band].size() - 1;
337 std::vector<te::rp::Texture> metrics;
338 init_index = current_index;
340 if(m_texture ==
true)
342 metrics = getTexture(raster.get(), geom.get(), (int)m_bands.size());
344 for (std::size_t t = 0, i = init_index; i < current_index; ++t, ++i)
350 outDSetItem->
setDouble(i, metrics[band].m_contrast);
355 outDSetItem->
setDouble(i, metrics[band].m_dissimilarity);
360 outDSetItem->
setDouble(i, metrics[band].m_energy);
365 outDSetItem->
setDouble(i, metrics[band].m_entropy);
370 outDSetItem->
setDouble(i, metrics[band].m_homogeneity);
377 init_index = current_index;
380 outDataset->add(outDSetItem);
383 throw te::attributefill::Exception(
TE_TR(
"Operation canceled!"));
386 return save(outDataset,outDsType);
391 std::vector<std::set<int> > pixelDistinct;
395 for (std::size_t b = 0; b < bands.size(); ++b)
397 std::set<int> pixelBandDistinct;
399 for (
int i = 0; i < numRows; ++i)
401 for (
int j = 0; j < numCols; ++j)
404 rst->
getValue(j, i, value, bands[b]);
405 pixelBandDistinct.insert((
int)value);
409 pixelDistinct.push_back(pixelBandDistinct);
412 return pixelDistinct;
418 outdsType->setCompositeName(m_outDset);
419 outdsType->setName(m_outDset);
420 outdsType->setTitle(m_outDset);
424 std::string name = pk->
getName();
425 name +=
"_" + m_outDset;
428 for(std::size_t b = 0; b < m_bands.size(); ++b)
430 for(std::size_t i = 0; i < m_statSum.size(); ++i)
437 outdsType->add(prop);
441 outdsType->add(prop);
445 outdsType->add(prop);
449 outdsType->add(prop);
453 outdsType->add(prop);
457 outdsType->add(prop);
461 outdsType->add(prop);
465 outdsType->add(prop);
469 outdsType->add(prop);
473 outdsType->add(prop);
477 outdsType->add(prop);
481 outdsType->add(prop);
485 outdsType->add(prop);
489 outdsType->add(prop);
493 std::set<int>::iterator it = pixelDistinct[b].begin();
494 while (it != pixelDistinct[b].end())
497 outdsType->add(prop);
506 if(m_texture ==
true)
509 outdsType->add(propContrast);
512 outdsType->add(propDissimilarity);
515 outdsType->add(propEnergy);
518 outdsType->add(propEntropy);
521 outdsType->add(propHomogeneity);
533 std::vector<te::rp::Texture> textureVec;
547 for(
int i = 0; i < bands; ++i)
549 boost::numeric::ublas::matrix<double> glcm = rattributes.
getGLCM(*rst, i, 1, 1, *polygon);
551 textureVec.push_back(metrics);
564 std::map<std::string, std::string> options;
566 m_outDsrc->createDataSet(dsTypeResult, options);
569 result->moveBeforeFirst();
570 m_outDsrc->add(dsTypeResult->getName(),result.get(), options);
573 if (m_outDsrc->getCapabilities().getDataSetTypeCapabilities().supportsPrimaryKey())
575 std::string pk_name = dsTypeResult->getName() +
"_pkey";
577 pk->
add(dsTypeResult->getProperty(0));
578 m_outDsrc->addPrimaryKey(m_outDset,pk);
virtual void setName(const std::string &name)
It sets the constraint name.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
MultiPolygon is a MultiSurface whose elements are Polygons.
A structure to hold the set of statistics from a set of numerical values.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
std::vector< std::set< int > > getPixelDistinct(te::rst::Raster *rst, std::vector< unsigned int > bands)
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
An atomic property like an integer or double.
std::string getPropertyName(std::size_t pos) const
It returns the name of the pos-th property.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
void useTimer(bool flag)
Used to define if task use progress timer information.
std::auto_ptr< te::da::DataSetType > getDataSetType(std::vector< std::set< int > > pixelDistinct=std::vector< std::set< int > >())
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsName)
DataSetType * getResult() const
This class can be used to inform the progress of a task.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
std::vector< double > m_mode
An exception class for the Attribute Fill module.
void setParams(std::vector< unsigned int > bands, std::vector< te::stat::StatisticalSummary > statSum, bool texture)
boost::numeric::ublas::matrix< double > getGLCM(const te::rst::Raster &rin, unsigned int band, int dx, int dy)
Computes the Gray-Level CoOccurrence Matrix (GLCM) from a raster band.
#define TE_TR(message)
It marks a string in order to get translated.
Percente of each class by area.
bool isActive() const
Verify if the task is active.
std::map< double, double > m_percentEachClass
Extraction of attributes from Raster, Bands, and Polygons.
std::vector< te::rp::Texture > getTexture(te::rst::Raster *rst, te::gm::Geometry *geom, int bands)
void setTotalSteps(int value)
Set the task total stepes.
An converter for DataSetType.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
An Envelope defines a 2D rectangular region.
bool contains(const Envelope &rhs) const
It returns true if this envelope "spatially contains" the rhs envelope.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Raster to Vector processing.
std::vector< std::vector< double > > getValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the pixel values for all the bands in raster, inside the polygon.
te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix< double > glcm)
Compute texture metrics from GLCM matrix.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
void setInput(te::da::DataSourcePtr inRasterDsrc, std::string inRasterName, std::auto_ptr< te::da::DataSetType > inRasterDsType, te::da::DataSourcePtr inVectorDsrc, std::string inVectorName, std::auto_ptr< te::da::DataSetType > inVectorDsType)
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.
te::stat::NumericStatisticalSummary getStatistics(std::vector< double > &pixels)
Returns several statistics from a set of pixels.
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...
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getArea() const
It returns the area of this MultiSurface, as measured in the spatial reference system of this multisu...
bool save(std::auto_ptr< te::mem::DataSet > result, std::auto_ptr< te::da::DataSetType > outDsType)
It describes a primary key (pk) constraint.
A structure to hold the set of GLCM metrics.
StatisticalSummary
Define grouping functions type.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
virtual const std::string & getName() const
It returns the constraint name.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
TESTATEXPORT void GetPercentOfEachClassByArea(std::vector< double > &values, double &resolutionX, double &resolutionY, double &area, te::stat::NumericStatisticalSummary &ss, bool fullIntersection=true)
const std::string & getName() const
It returns the property name.