GPMConstructorAbstractStrategy.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 GPMConstructorAbstractStrategy.cpp
22 
23  \brief This class defines a an Abstract class for a GPM constructor.
24 */
25 
26 // Terralib Includes
27 #include "../../common/Exception.h"
28 #include "../../core/translator/Translator.h"
29 #include "../../common/progress/TaskProgress.h"
30 #include "../../dataaccess/dataset/DataSet.h"
31 #include "../../dataaccess/datasource/DataSource.h"
32 #include "../../dataaccess/utils/Utils.h"
33 #include "../../geometry/GeometryProperty.h"
34 #include "../../geometry/MultiPolygon.h"
35 #include "../../geometry/Point.h"
36 #include "../../geometry/Polygon.h"
37 #include "../../graph/core/Vertex.h"
38 #include "../../graph/core/AbstractGraph.h"
39 #include "../../graph/graphs/DirectedGraph.h"
42 #include "Utils.h"
43 
44 // STL Includes
45 #include <cassert>
46 
48 {
49  m_edgeId = 0;
50 }
51 
53  default;
54 
56 {
57  return m_type;
58 }
59 
61 {
62  assert(ds);
63  m_ds = ds;
64 
65  assert(gpm);
66  m_gpm = gpm;
67 
68  //build vertex
70 
71  // build edges using specific strategy
73 }
74 
76 {
77  //get input data information
78  std::unique_ptr<te::da::DataSet> dataSet = m_ds->getDataSet(m_gpm->getDataSetName());
79 
80  std::unique_ptr<te::da::DataSetType> dataSetType = m_ds->getDataSetType(m_gpm->getDataSetName());
81 
83 
84  int srid = gp->getSRID();
85 
86  std::size_t geomPos = te::da::GetFirstSpatialPropertyPos(dataSet.get());
87 
88  //create graph vertex attrs
90  gProp->setId(0);
91  gProp->setGeometryType(te::gm::PointType);
92  gProp->setSRID(srid);
93 
94  m_gpm->getGraph()->addVertexProperty(gProp);
95 
96  //create task
98 
99  t.setTotalSteps(static_cast<int>(dataSet->size()));
100  t.setMessage(TE_TR("Creating Vertex Objects."));
101 
102  //create graph vertex
103  dataSet->moveBeforeFirst();
104 
105  while(dataSet->moveNext())
106  {
107  std::string strId = dataSet->getAsString(m_gpm->getAttributeName());
108 
109  int id = atoi(strId.c_str());
110 
112 
113  v->setAttributeVecSize(1);
114 
115  std::unique_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
116 
117  te::gm::Coord2D coord = g->getCentroid();
118 
119  te::gm::Point* p = new te::gm::Point(coord.x, coord.y, g->getSRID());
120 
121  v->addAttribute(0, p);
122 
123  m_gpm->getGraph()->add(v);
124 
125  if(!t.isActive())
126  {
127  throw te::common::Exception(TE_TR("Operation canceled by the user."));
128  }
129 
130  t.pulse();
131  }
132 }
133 
135 {
136  assert(gpm);
137 
139  p->setParent(nullptr);
140  p->setId(0);
141 
142  gpm->getGraph()->addEdgeProperty(p);
143 }
144 
146 {
147  int id = m_edgeId;
148 
149  m_edgeId++;
150 
151  return id;
152 }
Geometric property.
void setMessage(const std::string &message)
Set the task message.
double y
y-coordinate.
Definition: Coord2D.h:114
An atomic property like an integer or double.
This class defines a an Abstract class for a GPM constructor.
#define TE_SA_GEOMETRY_ATTR_NAME
double x
x-coordinate.
Definition: Coord2D.h:113
void construct(te::da::DataSource *ds, GeneralizedProximityMatrix *gpm)
This class defines a Generalized Proximity Matrix.
void createVertexObjects()
Function used to create all vertex object based on data set.
virtual void addEdgeProperty(te::dt::Property *p)=0
Add a new property associated to the edge element.
virtual ~GPMConstructorAbstractStrategy()
Virtual destructor.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
te::da::DataSource * m_ds
Data Source pointer.
virtual void add(Vertex *v)=0
Add a new vertex element to a graph.
bool isActive() const
Verify if the task is active.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
void setTotalSteps(int value)
Set the task total stepes.
void setId(unsigned int id)
It sets the property identifier.
Definition: Property.h:118
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
A point with x and y coordinate values.
Definition: Point.h:50
int getEdgeId()
Function used to generated the edge id.
virtual void addVertexProperty(te::dt::Property *p)=0
Add a new property associated to the vertex element.
GeneralizedProximityMatrix * m_gpm
GPM Pointer.
te::gm::Polygon * p
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
Utility functions for the data access module.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
GPMConstructorStrategyType m_type
Constructor Type.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
#define TE_SA_DISTANCE_ATTR_NAME
virtual void constructStrategy()=0
Build the edges using specific strategy.
void createDistanceAttribute(GeneralizedProximityMatrix *gpm)
Added to the edge a new attribute for distance information.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
int m_edgeId
Attribute used as a index counter for edge objects.
GPMConstructorStrategyType
Strategies to construc a GPM.
This class defines the GPM class.
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:177