31 #include "../../common/StringUtils.h"
32 #include "../../common/Translator.h"
33 #include "../../dataaccess/datasource/DataSource.h"
34 #include "../../dataaccess/datasource/DataSourceFactory.h"
35 #include "../../dataaccess/dataset/DataSet.h"
36 #include "../../datatype/AbstractData.h"
37 #include "../../datatype/SimpleData.h"
38 #include "../../datatype/SimpleProperty.h"
39 #include "../../geometry/GeometryProperty.h"
40 #include "../../geometry/MultiPolygon.h"
41 #include "../../geometry/Point.h"
42 #include "../../geometry/Polygon.h"
43 #include "../core/AbstractGraphFactory.h"
44 #include "../core/Edge.h"
45 #include "../core/Vertex.h"
46 #include "../core/VertexProperty.h"
47 #include "../graphs/Graph.h"
48 #include "../Config.h"
49 #include "../Exception.h"
57 #include<boost/tokenizer.hpp>
69 bool te::graph::FlowGraphBuilder::build(
const std::string& shapeFileName,
const std::string& linkColumn,
const int& srid,
const std::string& csvFileName,
const int& fromIdx,
const int& toIdx,
const int& weightIdx,
70 const std::map<std::string, std::string>& dsInfo,
const std::string& graphType,
const std::map<std::string, std::string>& gInfo)
77 if(createVertexObjects(shapeFileName, linkColumn, srid) ==
false)
82 if(createEdgeObjects(csvFileName, fromIdx, toIdx, weightIdx) ==
false)
102 std::map<std::string, std::string> connInfo;
103 connInfo[
"path"] = fileName;
105 ds->setConnectionInfo(connInfo);
115 std::string dsName = names[0];
117 std::auto_ptr<te::da::DataSet> dataset = ds->
getDataSet(dsName);
126 std::string dsName = names[0];
134 std::auto_ptr<te::da::DataSource> ds = getDataSource(shapeFileName);
142 std::auto_ptr<te::da::DataSet> dataSet = getDataSet(ds.get());
144 if(dataSet.get() == 0)
150 boost::ptr_vector<te::dt::Property> properties = getProperties(ds.get());
152 if(properties.empty())
158 boost::ptr_vector<te::dt::Property>::iterator it = properties.begin();
162 while(it != properties.end())
188 m_graph->addVertexProperty(p);
196 while(dataSet->moveNext())
198 int id = dataSet->getInt32(linkColumn);
206 it = properties.begin();
210 while(it != properties.end())
248 ad = dataSet->getValue(it->getName()).release();
267 std::ifstream in(csvFileName.c_str());
269 if(in.is_open() ==
false)
278 m_graph->addEdgeProperty(p);
281 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
282 boost::escaped_list_separator<char> sep(
'\\',
';',
'\"');
284 std::vector<std::string> line;
288 while(std::getline(in, buffer))
292 Tokenizer tok(buffer, sep);
294 line.assign(tok.begin(), tok.end());
296 std::string fromStr, toStr, weightStr;
299 fromStr = line[fromIdx];
301 weightStr = line[weightIdx];
309 int id = getEdgeId();
310 int from = atoi(fromStr.c_str());
311 int to = atoi(toStr.c_str());
312 int weight = atoi(weightStr.c_str());
316 e->setAttributeVecSize(1);
FlowGraphBuilder()
Default constructor.
bool build(const std::string &shapeFileName, const std::string &linkColumn, const int &srid, const std::string &csvFileName, const int &fromIdx, const int &toIdx, const int &weightIdx, const std::map< std::string, std::string > &dsInfo, const std::string &graphType, const std::map< std::string, std::string > &gInfo)
Function used to build the output graph based on input parameters.
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.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
An atomic property like an integer or double.
virtual boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
virtual ~FlowGraphBuilder()
Virtual destructor.
virtual Property * clone() const =0
It returns a clone of the object.
int m_edgeId
Attribute used as a index counter for edge objects.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
It models a property definition.
std::auto_ptr< te::da::DataSet > getDataSet(te::da::DataSource *ds)
Function used to get the data set with the vectorial data.
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
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...
A point with x and y coordinate values.
void setSRID(int srid)
It sets the Spatial Reference System ID of the Point.
static std::auto_ptr< DataSource > make(const std::string &dsType)
virtual std::auto_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...
A base class for values that can be retrieved from the data access module.
virtual std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::auto_ptr< te::da::DataSource > getDataSource(const std::string fileName)
Function used to get the data source with the vectorial data.
boost::ptr_vector< te::dt::Property > getProperties(te::da::DataSource *ds)
Function used to get the data source properties.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
bool createEdgeObjects(const std::string &csvFileName, const int &fromIdx, const int &toIdx, const int &weightIdx)
Function used to create all edges object based on flow table data.
Point * getCentroid() const
It returns the mathematical centroid for this surface as a point.
int getEdgeId()
Function used to generated the edge id.
bool createVertexObjects(const std::string &shapeFileName, const std::string &linkColumn, const int &srid)
Function used to create all vertex object based on vectorial data.
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).
static AbstractGraph * make()
It creates and returns an empty graph with default graph type.
This abstract class provides the common functions for graph builder classes. Each builder strategy ha...
virtual void setSRID(int srid)=0
It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollecti...
void setParent(Property *p)
It associate this property to the informed parent.