All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SamplePointsGeneratorAbstract.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/SamplePointsGeneratorAbstract.cpp
22 
23  \brief This file contains a virtual class to generate samples points.
24 
25  \reference Adapted from TerraLib4.
26 */
27 
28 // Terralib Includes
29 #include "../../geometry/Point.h"
30 #include "../../memory/DataSet.h"
31 #include "../../srs/Config.h"
33 
35 {
36  m_distReal = boost::random::uniform_real_distribution<>(0, 1);
37 }
38 
40 {
41 }
42 
44 {
45  std::auto_ptr<te::da::DataSetType> dsType = createDataSetType();
46 
47  std::auto_ptr<te::mem::DataSet> dsMem = generateSamples(dsType.get());
48 
49  saveDataSet(dsMem.get(), dsType.get());
50 }
51 
53 {
54  m_srid = srid;
55 }
56 
58 {
59  m_env = env;
60 }
61 
63 {
64  m_outputDataSetName = dataSetName;
65 }
66 
68 {
69  m_ds = ds;
70 }
71 
73 {
74  assert(dataSet);
75  assert(dsType);
76 
77  //save dataset
78  dataSet->moveBeforeFirst();
79 
80  std::map<std::string, std::string> options;
81 
82  m_ds->createDataSet(dsType, options);
83 
84  m_ds->add(m_outputDataSetName, dataSet, options);
85 }
86 
88 {
89  te::gm::Point* p = new te::gm::Point(m_srid);
90 
91  double diffX = env->getUpperRightX() - env->getLowerLeftX();
92  double randX = m_distReal(m_gen);
93  double x = randX * diffX + env->getLowerLeftX();
94  p->setX(x);
95 
96  double diffY = env->getUpperRightY() - env->getLowerLeftY();
97  double randY = m_distReal(m_gen);
98  double y = randY * diffY + env->getLowerLeftY();
99  p->setY(y);
100 
101  return p;
102 }
103 
void saveDataSet(te::mem::DataSet *dataSet, te::da::DataSetType *dsType)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual ~SamplePointsGeneratorAbstract()
Virtual destructor.
boost::random::uniform_real_distribution m_distReal
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
te::gm::Point * getPoint(const te::gm::Envelope *env)
void execute()
Function to execute the kernel operation.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: DataSet.cpp:328
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:143
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:157
This file contains a virtual class to generate samples points.