All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GPMConstructorNearestNeighborStrategy.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 GPMConstructorAdjacencyStrategy.cpp
22 
23  \brief This class defines a an adjacency strategy class for a GPM constructor.
24 */
25 
26 // TerraLib Includes
27 #include "../../common/Exception.h"
28 #include "../../common/Translator.h"
29 #include "../../common/STLUtils.h"
30 #include "../../common/progress/TaskProgress.h"
31 #include "../../dataaccess/datasource/DataSource.h"
32 #include "../../dataaccess/utils/Utils.h"
33 #include "../../datatype/SimpleData.h"
34 #include "../../datatype/SimpleProperty.h"
35 #include "../../geometry/GeometryProperty.h"
36 #include "../../geometry/Point.h"
37 #include "../../graph/core/Edge.h"
38 #include "../../graph/core/Vertex.h"
39 #include "../../sam/kdtree.h"
42 #include "Utils.h"
43 
45 {
47  m_nNeighbors = 0;
48 }
49 
51  m_nNeighbors(nNeighbors)
52 {
54 }
55 
57 {
58 }
59 
61 {
62  ////get input information
63  //std::auto_ptr<te::da::DataSet> dataSet = m_ds->getDataSet(m_gpm->getDataSetName());
64 
65  //std::size_t geomPos = te::da::GetFirstSpatialPropertyPos(dataSet.get());
66 
67  //std::auto_ptr<te::da::DataSetType> dsType = m_ds->getDataSetType(m_gpm->getDataSetName());
68 
69  //te::gm::GeometryProperty* gmProp = dynamic_cast<te::gm::GeometryProperty*>(dsType->getProperty(geomPos));
70 
71  ////create distance attribute
72  //createDistanceAttribute(m_gpm);
73 
74  ////create dataset of points
75  //te::gm::Envelope e;
76  //std::vector<std::pair<te::gm::Coord2D, te::gm::Point> > dataset;
77  //std::map<int, te::gm::Geometry*> geomMap;
78 
79  //dataSet->moveBeforeFirst();
80 
81  //while(dataSet->moveNext())
82  //{
83  // std::string strId = dataSet->getAsString(m_gpm->getAttributeName());
84 
85  // int id = atoi(strId.c_str());
86 
87  // te::gm::Geometry* g = dataSet->getGeometry(geomPos).release();
88 
89  // te::gm::Coord2D coord = te::sa::GetCentroidCoord(g);
90  // te::gm::Point point = te::gm::Point(coord.x, coord.y, gmProp->getSRID());
91 
92  // e.Union(*point.getMBR());
93 
94  // dataset.push_back(std::pair<te::gm::Coord2D, te::gm::Point>(coord, point));
95 
96  // geomMap.insert(std::map<int, te::gm::Geometry*>::value_type(id, g));
97  //}
98 
99  //// K-d Tree
100  //typedef te::sam::kdtree::AdaptativeNode<te::gm::Coord2D, std::vector<te::gm::Point>, te::gm::Point> kdNode;
101  //typedef te::sam::kdtree::AdaptativeIndex<kdNode> kdTree;
102 
103  //kdTree tree(e, m_nNeighbors);
104  //tree.build(dataset);
105 
106  ////create task
107  //te::common::TaskProgress task;
108 
109  //task.setTotalSteps(dataSet->size());
110  //task.setMessage(TE_TR("Creating Edge Objects."));
111 
112  ////create edges objects
113  //dataSet->moveBeforeFirst();
114 
115  //while(dataSet->moveNext())
116  //{
117  // std::string strIdFrom = dataSet->getAsString(m_gpm->getAttributeName());
118 
119  // int vFromId = atoi(strIdFrom.c_str());
120 
121  // std::auto_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
122 
123  // te::gm::Coord2D coord = te::sa::GetCentroidCoord(g.get());
124 
125  // std::vector<double> distances;
126 
127  // std::vector<te::gm::Point> points;
128 
129  // for(std::size_t t = 0; t < m_nNeighbors; ++t)
130  // points.push_back(te::gm::Point(std::numeric_limits<double>::max(), std::numeric_limits<double>::max()));
131 
132  // tree.nearestNeighborSearch(coord, points, distances, m_nNeighbors);
133 
134  // for(size_t t = 0; t < points.size(); ++t)
135  // {
136  // int id;
137 
138  // std::map<int, te::gm::Geometry*>::iterator it = geomMap.find(id);
139 
140  // if(it != geomMap.end())
141  // {
142 
143  // int edgeId = getEdgeId();
144 
145  // int vToId = id;
146 
147  // te::graph::Edge* e = new te::graph::Edge(edgeId, vFromId, vToId);
148 
149  // //caculate distance
150  // te::graph::Vertex* vFrom = m_gpm->getGraph()->getVertex(vFromId);
151  // te::gm::Point* pFrom = dynamic_cast<te::gm::Point*>(vFrom->getAttributes()[0]);
152 
153  // te::graph::Vertex* vTo = m_gpm->getGraph()->getVertex(vToId);
154  // te::gm::Point* pTo = dynamic_cast<te::gm::Point*>(vTo->getAttributes()[0]);
155 
156  // double dist = pFrom->distance(pTo);
157 
158  // te::dt::SimpleData<double, te::dt::DOUBLE_TYPE>* sd = new te::dt::SimpleData<double, te::dt::DOUBLE_TYPE>(dist);
159  //
160  // e->setAttributeVecSize(1);
161  // e->addAttribute(0, sd);
162 
163  // m_gpm->getGraph()->add(e);
164  // }
165  // }
166 
167  // if(!task.isActive())
168  // {
169  // te::common::FreeContents(geomMap);
170  // geomMap.clear();
171 
172  // throw te::common::Exception(TE_TR("Operation canceled by the user."));
173  // }
174  //
175 
176  // task.pulse();
177  //}
178 
179  //te::common::FreeContents(geomMap);
180  //geomMap.clear();
181 }
Utility functions for the data access module.
virtual void constructStrategy()
Build the edges using specific strategy.
GPMConstructorStrategyType m_type
Constructor Type.
This class defines a nearest neighbor strategy class for a GPM constructor.
This class defines a an Abstract class for a GPM constructor.
This class defines the GPM class.