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 "../../core/translator/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  : m_nPoints(0)
42 {
44 }
45 
47 
49 {
50  m_nPoints = nPoints;
51 }
52 
53 std::unique_ptr<te::da::DataSetType> te::sa::SamplePointsGeneratorRandom::createDataSetType()
54 {
55  std::unique_ptr<te::da::DataSetType> dsType(new te::da::DataSetType(m_outputDataSetName));
56 
57  //create id property
59  dsType->add(idProperty);
60 
61  //create geometry property
63  dsType->add(geomProperty);
64 
65  //create primary key
66  std::string pkName = TE_SA_SPG_ATTR_PK_NAME;
67  pkName+= "_" + m_outputDataSetName;
68  te::da::PrimaryKey* pk = new te::da::PrimaryKey(pkName, dsType.get());
69  pk->add(idProperty);
70 
71  return dsType;
72 }
73 
75 {
76  std::unique_ptr<te::mem::DataSet> ds(new te::mem::DataSet(dsType));
77 
78  //create task
80 
82  task.setMessage(TE_TR("Creating Points."));
83 
84  for(int i = 0; i < m_nPoints; ++i)
85  {
86  //create dataset item
87  te::mem::DataSetItem* item = new te::mem::DataSetItem(ds.get());
88 
89  //set id
91 
92  //set geometry
94 
95  ds->add(item);
96 
97  if(!task.isActive())
98  {
99  throw te::common::Exception(TE_TR("Operation canceled by the user."));
100  }
101 
102  task.pulse();
103  }
104 
105  return ds;
106 }
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.
#define TE_SA_SPG_ATTR_PK_NAME
A class that models the description of a dataset.
Definition: DataSetType.h:72
int m_nPoints
Attribute used to define the number of points to be generated.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
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.
Definition: Translator.h:242
This file contains a class to generate samples points using random strategy.
bool isActive() const
Verify if the task is active.
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.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
#define TE_SA_SPG_ATTR_ID_NAME
virtual std::unique_ptr< te::da::DataSetType > createDataSetType()
te::gm::Envelope m_env
Attribute used to restrict the area to generate the samples.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
te::gm::Point * getPoint(const te::gm::Envelope *env)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
virtual std::unique_ptr< te::mem::DataSet > generateSamples(te::da::DataSetType *dsType)
int m_srid
Attribute with spatial reference information.