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  default;
41 
43 {
44  std::unique_ptr<te::da::DataSetType> dsType = createDataSetType();
45 
46  std::unique_ptr<te::mem::DataSet> dsMem = generateSamples(dsType.get());
47 
48  saveDataSet(dsMem.get(), dsType.get());
49 }
50 
52 {
53  m_srid = srid;
54 }
55 
57 {
58  m_env = env;
59 }
60 
62 {
63  m_outputDataSetName = dataSetName;
64 }
65 
67 {
68  m_ds = ds;
69 }
70 
72 {
73  assert(dataSet);
74  assert(dsType);
75 
76  //save dataset
77  dataSet->moveBeforeFirst();
78 
79  std::map<std::string, std::string> options;
80 
81  m_ds->createDataSet(dsType, options);
82 
83  m_ds->add(m_outputDataSetName, dataSet, options);
84 }
85 
87 {
89 
90  double diffX = env->getUpperRightX() - env->getLowerLeftX();
91  double randX = m_distReal(m_gen);
92  double x = randX * diffX + env->getLowerLeftX();
93  p->setX(x);
94 
95  double diffY = env->getUpperRightY() - env->getLowerLeftY();
96  double randY = m_distReal(m_gen);
97  double y = randY * diffY + env->getLowerLeftY();
98  p->setY(y);
99 
100  return p;
101 }
102 
void saveDataSet(te::mem::DataSet *dataSet, te::da::DataSetType *dsType)
boost::shared_ptr< DataSource > DataSourcePtr
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
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.
virtual std::unique_ptr< te::mem::DataSet > generateSamples(te::da::DataSetType *dsType)=0
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
static te::dt::Date ds(2010, 01, 01)
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
std::string m_outputDataSetName
Attribute that defines the output dataset name.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
te::gm::Envelope m_env
Attribute used to restrict the area to generate the samples.
te::gm::Polygon * p
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.
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:145
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:159
This file contains a virtual class to generate samples points.
virtual std::unique_ptr< te::da::DataSetType > createDataSetType()=0
te::da::DataSourcePtr m_ds
Pointer to the output datasource.
int m_srid
Attribute with spatial reference information.