31 #include "../../common/progress/TaskProgress.h"
32 #include "../../common/StringUtils.h"
33 #include "../../common/STLUtils.h"
34 #include "../../common/Translator.h"
35 #include "../../dataaccess/datasource/DataSource.h"
36 #include "../../dataaccess/utils/Utils.h"
37 #include "../../datatype/AbstractData.h"
38 #include "../../datatype/SimpleData.h"
39 #include "../../datatype/SimpleProperty.h"
40 #include "../../geometry/GeometryProperty.h"
41 #include "../../geometry/MultiPolygon.h"
42 #include "../../geometry/Point.h"
43 #include "../../geometry/Polygon.h"
44 #include "../../sam/rtree.h"
45 #include "../core/AbstractGraphFactory.h"
46 #include "../core/Edge.h"
47 #include "../core/Vertex.h"
48 #include "../core/VertexProperty.h"
49 #include "../graphs/Graph.h"
50 #include "../Config.h"
51 #include "../Exception.h"
76 std::auto_ptr<te::da::DataSet> dataSet = ds->getDataSet(dataSetName);
78 std::auto_ptr<te::da::DataSetType> dataSetType = ds->getDataSetType(dataSetName);
82 createVertexObjects(dataSet.get(), columnId, gp->
getSRID());
84 createAdjacencyEdges(dataSet.get(), columnId, calcDist);
91 std::auto_ptr<te::da::DataSet> dataSet = ds->getDataSet(dataSetName);
93 std::auto_ptr<te::da::DataSetType> dataSetType = ds->getDataSetType(dataSetName);
97 createVertexObjects(dataSet.get(), columnId, gp->
getSRID());
99 createDistanceEdges(dataSet.get(), columnId, dist);
114 m_graph->addVertexProperty(gProp);
121 int id = dataSet->
getInt32(columnId);
127 std::auto_ptr<te::gm::Geometry> g = dataSet->
getGeometry(geomPos);
171 m_graph->addEdgeProperty(p);
176 std::map<int, te::gm::Geometry*> geomMap;
182 int id = dataSet->
getInt32(columnId);
188 geomMap.insert(std::map<int, te::gm::Geometry*>::value_type(
id, g));
194 task.
setMessage(
"GPM Builder - Extracting Edges");
201 int vFromId = dataSet->
getInt32(columnId);
203 std::auto_ptr<te::gm::Geometry> g = dataSet->
getGeometry(geomPos);
205 std::vector<int> results;
207 rtree.
search(*g->getMBR(), results);
209 for(
size_t t = 0; t < results.size(); ++t)
211 std::map<int, te::gm::Geometry*>::iterator it = geomMap.find(results[t]);
213 if(it != geomMap.end())
215 if(g->touches(it->second))
217 int edgeId = getEdgeId();
219 int vToId = results[t];
221 Edge* e =
new Edge(edgeId, vFromId, vToId);
225 Vertex* vFrom = m_graph->getVertex(vFromId);
228 Vertex* vTo = m_graph->getVertex(vToId);
260 m_graph->addEdgeProperty(p);
264 std::map<int, te::gm::Geometry*> geomMap;
270 int id = dataSet->
getInt32(columnId);
276 geomMap.insert(std::map<int, te::gm::Geometry*>::value_type(
id, g));
282 task.
setMessage(
"GPM Builder - Extracting Edges");
289 int vFromId = dataSet->
getInt32(columnId);
291 std::auto_ptr<te::gm::Geometry> g = dataSet->
getGeometry(geomPos);
293 std::vector<int> results;
297 ext.
m_llx -= distance;
298 ext.m_lly -= distance;
299 ext.m_urx += distance;
300 ext.m_ury += distance;
302 rtree.
search(ext, results);
304 for(
size_t t = 0; t < results.size(); ++t)
306 std::map<int, te::gm::Geometry*>::iterator it = geomMap.find(results[t]);
308 if(it != geomMap.end())
310 int vToId = results[t];
312 Vertex* vFrom = m_graph->getVertex(vFromId);
315 Vertex* vTo = m_graph->getVertex(vToId);
322 int edgeId = getEdgeId();
324 Edge* e =
new Edge(edgeId, vFromId, vToId);
bool buildDistance(std::auto_ptr< te::da::DataSource > ds, std::string dataSetName, std::string columnId, double dist)
Function used to generated a graph using the GPM Distance Strategy.
MultiPolygon is a MultiSurface whose elements are Polygons.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements.
bool setGraphInfo(const std::map< std::string, std::string > &dsInfo, const std::string &graphType, const std::map< std::string, std::string > &gInfo)
Function used to create a empty graph.
void setMessage(const std::string &message)
Set the task message.
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the edge elements.
void createVertexObjects(te::da::DataSet *dataSet, std::string columnId, int srid)
Function used to create all vertex object based on data set.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
An atomic property like an integer or double.
This class defines the GPM strategy to build a graph,.
A class that represents an R-tree.
virtual ~GPMGraphBuilder()
Virtual destructor.
GPMGraphBuilder()
Default constructor.
This class can be used to inform the progress of a task.
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
void setTotalSteps(int value)
Set the task total stepes.
void setId(unsigned int id)
It sets the property identifier.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
double m_llx
Lower left corner x-coordinate.
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.
An Envelope defines a 2D rectangular region.
void createDistanceEdges(te::da::DataSet *dataSet, std::string columnId, double distance)
Function used to create all edges object based on data set, using the distance strategy.
void setSRID(int srid)
It sets the Spatial Reference System ID of the Point.
virtual std::size_t size() const =0
It returns the collection size, if it is known.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
A base class for values that can be retrieved from the data access module.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
Point * getCentroid() const
It returns the mathematical centroid for this surface as a point.
int getEdgeId()
Function used to generated the edge id.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
A template for atomic data types (integers, floats, strings and others).
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
virtual AbstractData * clone() const =0
It returns a clone of this object.
void addAttribute(int idx, te::dt::AbstractData *ad)
Add a new attribute to this element.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
void createAdjacencyEdges(te::da::DataSet *dataSet, std::string columnId, bool calcDist)
Function used to create all edges object based on data set, using the adjacency strategy.
bool buildAdjacency(std::auto_ptr< te::da::DataSource > ds, std::string dataSetName, std::string columnId, bool calcDist)
Function used to generated a graph using the GPM Adjacency Strategy.
virtual double distance(const Geometry *const rhs) const
It returns the shortest distance between any two points in the two geometry objects.
This abstract class provides the common functions for graph builder classes. Each builder strategy ha...
int m_edgeId
Attribute used as a index counter for edge objects.
void setParent(Property *p)
It associate this property to the informed parent.