All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SamplePointsGeneratorRandom.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/sa/core/SamplePointsGeneratorRandom.cpp
22 
23  \brief This file contains a class to generate samples points using random strategy.
24 
25  \reference Adapted from TerraLib4.
26 */
27 
28 // Terralib Includes
29 #include "../../common/Exception.h"
30 #include "../../common/Translator.h"
31 #include "../../common/progress/TaskProgress.h"
32 #include "../../datatype/SimpleProperty.h"
33 #include "../../geometry/Geometry.h"
34 #include "../../geometry/GeometryProperty.h"
35 #include "../../memory/DataSet.h"
36 #include "../../memory/DataSetItem.h"
37 #include "../Enums.h"
39 
41 {
43 }
44 
46 {
47 }
48 
50 {
51  m_nPoints = nPoints;
52 }
53 
54 std::auto_ptr<te::da::DataSetType> te::sa::SamplePointsGeneratorRandom::createDataSetType()
55 {
56  std::auto_ptr<te::da::DataSetType> dsType(new te::da::DataSetType(m_outputDataSetName));
57 
58  //create id property
60  dsType->add(idProperty);
61 
62  //create geometry property
64  dsType->add(geomProperty);
65 
66  //create primary key
67  std::string pkName = TE_SA_SPG_ATTR_PK_NAME;
68  pkName+= "_" + m_outputDataSetName;
69  te::da::PrimaryKey* pk = new te::da::PrimaryKey(pkName, dsType.get());
70  pk->add(idProperty);
71 
72  return dsType;
73 }
74 
76 {
77  std::auto_ptr<te::mem::DataSet> ds(new te::mem::DataSet(dsType));
78 
79  //create task
81 
82  task.setTotalSteps(m_nPoints);
83  task.setMessage(TE_TR("Creating Points."));
84 
85  for(int i = 0; i < m_nPoints; ++i)
86  {
87  //create dataset item
88  te::mem::DataSetItem* item = new te::mem::DataSetItem(ds.get());
89 
90  //set id
92 
93  //set geometry
94  item->setGeometry(TE_SA_SPG_ATTR_GEOM_NAME, getPoint(&m_env));
95 
96  ds->add(item);
97 
98  if(!task.isActive())
99  {
100  throw te::common::Exception(TE_TR("Operation canceled by the user."));
101  }
102 
103  task.pulse();
104  }
105 
106  return ds;
107 }
Geometric property.
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.
Definition: PrimaryKey.h:123
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
virtual ~SamplePointsGeneratorRandom()
Virtual destructor.
An atomic property like an integer or double.
te::sa::SamplePointsGeneratorType m_type
Generator Type.
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual std::auto_ptr< te::mem::DataSet > generateSamples(te::da::DataSetType *dsType)
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
This file contains a class to generate samples points using random strategy.
bool isActive() const
Verify if the task is active.
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.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
#define TE_SA_SPG_ATTR_GEOM_NAME
Definition: Config.h:95
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
#define TE_SA_SPG_ATTR_PK_NAME
Definition: Config.h:98
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Virtual class to generate samples points.
virtual std::auto_ptr< te::da::DataSetType > createDataSetType()
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
#define TE_SA_SPG_ATTR_ID_NAME
Definition: Config.h:89