29 #include "../../common/Exception.h" 30 #include "../../core/translator/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" 45 : m_nPoints(0), m_attrName(
""), m_propToArea(false)
52 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.begin();
56 std::vector<te::gm::Geometry*> geomVec = it->second;
88 std::vector<std::string> names;
90 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.begin();
94 names.push_back(it->first);
108 dsType->add(idProperty);
112 dsType->add(classProperty);
116 dsType->add(geomProperty);
134 std::map<std::string, int> nPointsPerClass;
139 std::map<std::string, double> areaPerClass;
141 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.begin();
144 std::vector<double> areas;
148 std::vector<te::gm::Geometry*> geomVec = it->second;
152 for(std::size_t t = 0; t < geomVec.size(); ++t)
157 areaPerClass.insert(std::map<std::string, double>::value_type(it->first, totArea));
159 areas.push_back(totArea);
165 std::vector<double>::iterator minPos = std::min_element(areas.begin(), areas.end());
166 double minArea = *minPos;
172 int nPoints = (
int)((areaPerClass[it->first] *
m_nPoints) / minArea);
174 nPointsPerClass.insert(std::map<std::string, int>::value_type(it->first, nPoints));
181 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.begin();
186 nPointsPerClass.insert(std::map<std::string, int>::value_type(it->first,
m_nPoints));
201 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.begin();
205 std::string className = it->first;
207 std::vector<te::gm::Geometry*> geomVec = it->second;
209 m_distInt = boost::random::uniform_int_distribution<>(0,
static_cast<int>(geomVec.size() - 1));
211 int nPoints = nPointsPerClass[className];
213 for(
int i = 0; i < nPoints; ++i)
261 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator it =
m_classMap.find(className);
266 std::vector<te::gm::Geometry*> geomVec;
267 geomVec.push_back(geom);
269 m_classMap.insert(std::map<std::string, std::vector<te::gm::Geometry*> >::value_type(className, geomVec));
273 it->second.push_back(geom);
284 while(within ==
false)
std::unique_ptr< te::da::DataSet > m_dataSet
Attribute with input data.
void setInputAttributeName(std::string attrName)
std::string m_attrName
Attribute used to get from input data the selected attribute.
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.
bool m_propToArea
Attribute used to indicate if the number of samples has to be proportional to the area...
SamplePointsGeneratorStratified()
Default constructor.
An atomic property like an integer or double.
boost::random::uniform_int_distribution m_distInt
te::sa::SamplePointsGeneratorType m_type
Generator Type.
#define TE_SA_SPG_ATTR_PK_NAME
void isProportionalToArea(bool isProp)
A class that models the description of a dataset.
boost::random::mt19937 m_gen
This file contains a class to generate samples points using stratified strategy.
This class can be used to inform the progress of a task.
static te::dt::Date ds(2010, 01, 01)
#define TE_SA_SPG_ATTR_GEOM_NAME
#define TE_TR(message)
It marks a string in order to get translated.
std::map< std::string, std::vector< te::gm::Geometry * > > m_classMap
Attribute with polygons for each class from input dataset.
bool isActive() const
Verify if the task is active.
void setNumberOfPoints(int nPoints)
std::string m_outputDataSetName
Attribute that defines the output dataset name.
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.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual bool within(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially within rhs geometry.
#define TE_SA_SPG_ATTR_ID_NAME
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
std::vector< std::string > getClassNames()
te::gm::Point * getPoint(const te::gm::Envelope *env)
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.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
int m_nPoints
Attribute used to define the number of points to be generated.
It describes a primary key (pk) constraint.
virtual std::unique_ptr< te::da::DataSetType > createDataSetType()
void setInputDataSet(std::unique_ptr< te::da::DataSet > dataSet)
#define TE_SA_SPG_ATTR_CLASS_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.
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...
virtual std::unique_ptr< te::mem::DataSet > generateSamples(te::da::DataSetType *dsType)
virtual ~SamplePointsGeneratorStratified()
Virtual destructor.
int m_srid
Attribute with spatial reference information.