46 #include "../../dataaccess/datasource/DataSource.h"
47 #include "../../dataaccess/utils/Utils.h"
48 #include "../../datatype/SimpleData.h"
49 #include "../../datatype/SimpleProperty.h"
50 #include "../../geometry/GeometryProperty.h"
51 #include "../../geometry/MultiPolygon.h"
52 #include "../../geometry/Point.h"
53 #include "../../geometry/Polygon.h"
54 #include "../core/AbstractGraph.h"
55 #include "../core/AbstractGraphFactory.h"
56 #include "../core/GraphMetadata.h"
57 #include "../core/Edge.h"
58 #include "../core/Vertex.h"
59 #include "../iterator/AbstractIterator.h"
60 #include "../iterator/SequenceIterator.h"
61 #include "../iterator/MemoryIterator.h"
71 #include<boost/tokenizer.hpp>
84 std::auto_ptr<te::graph::AbstractIterator> it;
98 FILE* fp = fopen(pathFileName.c_str(),
"w");
103 if(dataSetName.empty())
105 fprintf(fp,
"%d\n", (
int)it->getVertexInteratorCount());
109 fprintf(fp,
"0 %d %s %s\n", (
int)it->getVertexInteratorCount(), dataSetName.c_str(), propertyName.c_str());
115 while(it->isVertexIteratorAfterEnd() ==
false)
119 std::set<int>::iterator itNeighbours = neighbours.begin();
121 if(!neighbours.empty())
123 fprintf(fp,
"%d %d\n",
id, (
int)neighbours.size());
125 while(itNeighbours != neighbours.end())
132 fprintf (fp,
"%d ", e->
getIdTo());
143 v = it->getNextVertex();
150 std::string graphType, std::map<std::string, std::string> gInfo,
te::da::DataSource* ds)
153 std::ifstream file(pathFileName.c_str());
155 if(file.is_open() ==
false)
165 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
166 boost::escaped_list_separator<char> sep(
'\\',
' ',
'\"');
168 std::vector<std::string> line;
172 std::getline(file, buffer);
173 Tokenizer tok(buffer, sep);
174 line.assign(tok.begin(), tok.end());
176 std::string dataSetName =
"";
177 std::string attributeName =
"";
178 bool associateGeom =
false;
180 if(line.size() == 4 && ds)
182 associateGeom =
true;
184 dataSetName = line[2];
185 attributeName = line[3];
191 while(std::getline(file, buffer))
194 Tokenizer tok(buffer, sep);
195 line.assign(tok.begin(), tok.end());
197 std::string vertexIdStr, nNeighboursStr;
201 vertexIdStr = line[0];
202 nNeighboursStr = line[1];
212 int vId = atoi(vertexIdStr.c_str());
222 std::getline(file, buffer);
224 Tokenizer tok2(buffer, sep);
225 line.assign(tok2.begin(), tok2.end());
228 int nNeighbours = atoi(nNeighboursStr.c_str());
232 for(
int i = 0; i < nNeighbours; ++i)
234 std::string vNeighbourStr = line[i];
235 int vNeighbourId = atoi(vNeighbourStr.c_str());
242 vNeighbour =
new Vertex(vNeighbourId);
243 graph->
add(vNeighbour);
247 int id = getEdgeId();
249 Edge* e =
new Edge(
id, vId, vNeighbourId);
264 associateGeometry(graph, ds, dataSetName, attributeName);
272 std::auto_ptr<te::graph::AbstractIterator> it;
286 FILE* fp = fopen(pathFileName.c_str(),
"w");
291 if(dataSetName.empty())
293 fprintf(fp,
"%d\n", (
int)it->getEdgeInteratorCount());
297 fprintf(fp,
"0 %d %s %s\n", (
int)it->getEdgeInteratorCount(), dataSetName.c_str(), propertyName.c_str());
303 while(it->isEdgeIteratorAfterEnd() ==
false)
312 fprintf(fp,
"%d %d %3.7f\n", idFrom, idTo, distance);
314 e = it->getNextEdge();
321 std::string graphType, std::map<std::string, std::string> gInfo,
te::da::DataSource* ds)
324 std::ifstream file(pathFileName.c_str());
326 if(file.is_open() ==
false)
343 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
344 boost::escaped_list_separator<char> sep(
'\\',
' ',
'\"');
346 std::vector<std::string> line;
350 std::getline(file, buffer);
351 Tokenizer tok(buffer, sep);
352 line.assign(tok.begin(), tok.end());
354 std::string dataSetName =
"";
355 std::string attributeName =
"";
356 bool associateGeom =
false;
358 if(line.size() == 4 && ds)
360 associateGeom =
true;
362 dataSetName = line[2];
363 attributeName = line[3];
369 while(std::getline(file, buffer))
373 Tokenizer tok(buffer, sep);
375 line.assign(tok.begin(), tok.end());
377 std::string fromStr, toStr, distanceStr;
383 distanceStr = line[2];
393 int from = atoi(fromStr.c_str());
404 int to = atoi(toStr.c_str());
415 int id = getEdgeId();
416 double distance = atof(distanceStr.c_str());
419 e->setAttributeVecSize(1);
428 associateGeometry(graph, ds, dataSetName, attributeName);
443 std::string dataSetName, std::string propertyName)
446 std::auto_ptr<te::da::DataSetType> dataSetType = ds->
getDataSetType(dataSetName);
458 std::auto_ptr<te::da::DataSet> dataSet = ds->
getDataSet(dataSetName);
462 dataSet->moveBeforeFirst();
464 while(dataSet->moveNext())
466 int id = dataSet->getInt32(propertyName);
474 std::auto_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
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.
An atomic property like an integer or double.
virtual te::graph::Edge * getEdge(int id)=0
It returns the edge element if it's exist.
virtual void addEdgeProperty(te::dt::Property *p)=0
Add a new property associated to the edge element.
int getEdgeId()
Function used to generated the edge id.
T getValue() const
It returns the associated value.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void exportToGAL(te::graph::AbstractGraph *g, std::string pathFileName, std::string dataSetName="", std::string propertyName="")
Function used to export a graph to Spatial Weights File GAL Format.
This class defines functions used to load and save graphs using GAL and GWT formats, both formats use a ' ' as separator.
virtual void add(Vertex *v)=0
Add a new vertex element to a graph.
te::graph::AbstractGraph * importFromGAL(std::string pathFileName, std::map< std::string, std::string > dsInfo, std::string graphType, std::map< std::string, std::string > gInfo, te::da::DataSource *ds=0)
Function used to import a graph from a Spatial Weights File GAL Format.
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.
virtual te::graph::GraphMetadata * getMetadata()=0
Function used to access the graph metadata.
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
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.
void setSRID(int srid)
It sets the Spatial Reference System ID of the Point.
virtual void addVertexProperty(te::dt::Property *p)=0
Add a new property associated to the vertex element.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
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...
void associateGeometry(te::graph::AbstractGraph *g, te::da::DataSource *ds, std::string dataSetName, std::string propertyName)
Function used to associate the geometry coord attribute to vertex objects.
void setDirty(bool flag)
Flag used to indicate that this element was changed.
A base class for values that can be retrieved from the data access module.
void exportToGWT(te::graph::AbstractGraph *g, std::string pathFileName, int distAttrIdx, std::string dataSetName="", std::string propertyName="")
Function used to export a graph to Spatial Weights File GWT Format.
int getIdFrom()
It returns the vertex origin identification.
std::set< int > & getNeighborhood()
Returns the Neighborhood vector.
~SpatialWeightsExchanger()
Virtual destructor.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Point * getCentroid() const
It returns the mathematical centroid for this surface as a point.
te::graph::AbstractGraph * importFromGWT(std::string pathFileName, std::map< std::string, std::string > dsInfo, std::string graphType, std::map< std::string, std::string > gInfo, te::da::DataSource *ds=0)
Function used to import a graph from a Spatial Weights File GWT Format.
int getId()
It returns the vertex 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.
virtual te::graph::Vertex * getVertex(int id)=0
It returns the vertex element if it's exist.
std::vector< te::dt::AbstractData * > & getAttributes()
It returns the vector of attributes associated with this element.
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
int getIdTo()
It returns the vertex destiny identification.
SpatialWeightsExchanger()
Default constructor.
void setParent(Property *p)
It associate this property to the informed parent.