29 #include "../../common/Exception.h"
30 #include "../../common/Translator.h"
31 #include "../../common/STLUtils.h"
32 #include "../../common/progress/TaskProgress.h"
33 #include "../../dataaccess/utils/Utils.h"
34 #include "../../datatype/SimpleProperty.h"
35 #include "../../geometry/Geometry.h"
36 #include "../../geometry/GeometryProperty.h"
37 #include "../../geometry/Polygon.h"
38 #include "../../memory/DataSet.h"
39 #include "../../memory/DataSetItem.h"
40 #include "../core/Utils.h"
51 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.begin();
53 while(it != m_classMap.end())
55 std::vector<te::gm::Geometry*> geomVec = it->second;
77 m_attrName = attrName;
82 m_propToArea = isProp;
87 std::vector<std::string> names;
89 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.begin();
91 while(it != m_classMap.end())
93 names.push_back(it->first);
107 dsType->add(idProperty);
111 dsType->add(classProperty);
115 dsType->add(geomProperty);
119 pkName+=
"_" + m_outputDataSetName;
133 std::map<std::string, int> nPointsPerClass;
138 std::map<std::string, double> areaPerClass;
140 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.begin();
143 std::vector<double> areas;
145 while(it != m_classMap.end())
147 std::vector<te::gm::Geometry*> geomVec = it->second;
151 for(std::size_t t = 0; t < geomVec.size(); ++t)
156 areaPerClass.insert(std::map<std::string, double>::value_type(it->first, totArea));
158 areas.push_back(totArea);
164 std::vector<double>::iterator minPos = std::min_element(areas.begin(), areas.end());
165 double minArea = *minPos;
167 it = m_classMap.begin();
169 while(it != m_classMap.end())
171 int nPoints = (int)((areaPerClass[it->first] * m_nPoints) / minArea);
173 nPointsPerClass.insert(std::map<std::string, int>::value_type(it->first, nPoints));
180 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.begin();
183 while(it != m_classMap.end())
185 nPointsPerClass.insert(std::map<std::string, int>::value_type(it->first, m_nPoints));
200 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.begin();
202 while(it != m_classMap.end())
204 std::string className = it->first;
206 std::vector<te::gm::Geometry*> geomVec = it->second;
208 m_distInt = boost::random::uniform_int_distribution<>(0, geomVec.size() - 1);
210 int nPoints = nPointsPerClass[className];
212 for(
int i = 0; i < nPoints; ++i)
248 m_dataSet->moveBeforeFirst();
252 while(m_dataSet->moveNext())
255 std::string className = m_dataSet->getString(m_attrName);
260 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it = m_classMap.find(className);
263 if(it == m_classMap.end())
265 std::vector<te::gm::Geometry*> geomVec;
266 geomVec.push_back(geom);
268 m_classMap.insert(std::map<std::string, std::vector<te::gm::Geometry*> >::value_type(className, geomVec));
272 it->second.push_back(geom);
283 while(within ==
false)
285 p = getPoint(g->
getMBR());
void setInputAttributeName(std::string attrName)
void setMessage(const std::string &message)
Set the task message.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
SamplePointsGeneratorStratified()
Default constructor.
An atomic property like an integer or double.
te::sa::SamplePointsGeneratorType m_type
Generator Type.
void isProportionalToArea(bool isProp)
A class that models the description of a dataset.
virtual std::auto_ptr< te::da::DataSetType > createDataSetType()
This file contains a class to generate samples points using stratified strategy.
This class can be used to inform the progress of a task.
#define TE_TR(message)
It marks a string in order to get translated.
bool isActive() const
Verify if the task is active.
void setNumberOfPoints(int nPoints)
void setTotalSteps(int value)
Set the task total stepes.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
TESAEXPORT double GetArea(te::gm::Geometry *geom)
Function used to get area of a geometry.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
te::gm::Point * getPointInGeometry(te::gm::Geometry *g)
A point with x and y coordinate values.
#define TE_SA_SPG_ATTR_GEOM_NAME
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
std::vector< std::string > getClassNames()
#define TE_SA_SPG_ATTR_PK_NAME
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Virtual class to generate samples points.
void setInputDataSet(std::auto_ptr< te::da::DataSet > dataSet)
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
It describes a primary key (pk) constraint.
virtual std::auto_ptr< te::mem::DataSet > generateSamples(te::da::DataSetType *dsType)
#define TE_SA_SPG_ATTR_ID_NAME
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
#define TE_SA_SPG_ATTR_CLASS_NAME
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual ~SamplePointsGeneratorStratified()
Virtual destructor.
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.