All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../../common/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 {
54 }
55 
57 {
58  return m_type;
59 }
60 
62 {
63  assert(ds);
64  m_ds = ds;
65 
66  assert(gpm);
67  m_gpm = gpm;
68 
69  //build vertex
70  createVertexObjects();
71 
72  // build edges using specific strategy
73  constructStrategy();
74 }
75 
77 {
78  //get input data information
79  std::auto_ptr<te::da::DataSet> dataSet = m_ds->getDataSet(m_gpm->getDataSetName());
80 
81  std::auto_ptr<te::da::DataSetType> dataSetType = m_ds->getDataSetType(m_gpm->getDataSetName());
82 
84 
85  int srid = gp->getSRID();
86 
87  std::size_t geomPos = te::da::GetFirstSpatialPropertyPos(dataSet.get());
88 
89  //create graph vertex attrs
91  gProp->setId(0);
92  gProp->setGeometryType(te::gm::PointType);
93  gProp->setSRID(srid);
94 
95  m_gpm->getGraph()->addVertexProperty(gProp);
96 
97  //create task
99 
100  t.setTotalSteps(dataSet->size());
101  t.setMessage(TE_TR("Creating Vertex Objects."));
102 
103  //create graph vertex
104  dataSet->moveBeforeFirst();
105 
106  while(dataSet->moveNext())
107  {
108  std::string strId = dataSet->getAsString(m_gpm->getAttributeName());
109 
110  int id = atoi(strId.c_str());
111 
113 
114  v->setAttributeVecSize(1);
115 
116  std::auto_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
117 
118  te::gm::Coord2D coord = te::sa::GetCentroidCoord(g.get());
119 
120  te::gm::Point* p = new te::gm::Point(coord.x, coord.y, g->getSRID());
121 
122  v->addAttribute(0, p);
123 
124  m_gpm->getGraph()->add(v);
125 
126  if(!t.isActive())
127  {
128  throw te::common::Exception(TE_TR("Operation canceled by the user."));
129  }
130 
131  t.pulse();
132  }
133 }
134 
136 {
137  assert(gpm);
138 
140  p->setParent(0);
141  p->setId(0);
142 
143  gpm->getGraph()->addEdgeProperty(p);
144 }
145 
147 {
148  int id = m_edgeId;
149 
150  m_edgeId++;
151 
152  return id;
153 }
#define TE_SA_GEOMETRY_ATTR_NAME
Definition: Config.h:44
Geometric property.
void setMessage(const std::string &message)
Set the task message.
Utility functions for the data access module.
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.
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
TESAEXPORT te::gm::Coord2D GetCentroidCoord(te::gm::Geometry *geom)
Function used to get centroid coord of a geometry.
Definition: Utils.cpp:243
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
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.
Definition: Utils.cpp:462
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.
#define TE_SA_DISTANCE_ATTR_NAME
Definition: Config.h:38
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
void createDistanceAttribute(GeneralizedProximityMatrix *gpm)
Added to the edge a new attribute for distance information.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:557
int m_edgeId
Attribute used as a index counter for edge objects.
GPMConstructorStrategyType
Strategies to construc a GPM.
Definition: Enums.h:39
This class defines the GPM class.
void setParent(Property *p)
It associate this property to the informed parent.
Definition: Property.h:177