46 #include "../../common/Exception.h" 
   47 #include "../../common/Translator.h" 
   48 #include "../../common/progress/TaskProgress.h" 
   49 #include "../../dataaccess/datasource/DataSource.h" 
   50 #include "../../dataaccess/utils/Utils.h" 
   51 #include "../../datatype/SimpleData.h" 
   52 #include "../../datatype/SimpleProperty.h" 
   53 #include "../../geometry/GeometryProperty.h" 
   54 #include "../../geometry/MultiPolygon.h" 
   55 #include "../../geometry/Point.h" 
   56 #include "../../geometry/Polygon.h" 
   57 #include "../../graph/core/AbstractGraph.h" 
   58 #include "../../graph/core/AbstractGraphFactory.h" 
   59 #include "../../graph/core/GraphMetadata.h" 
   60 #include "../../graph/core/Edge.h" 
   61 #include "../../graph/core/Vertex.h" 
   62 #include "../../graph/iterator/AbstractIterator.h" 
   63 #include "../../graph/iterator/SequenceIterator.h" 
   64 #include "../../graph/iterator/MemoryIterator.h" 
   65 #include "../../graph/Globals.h" 
   76 #include<boost/tokenizer.hpp> 
   89   std::auto_ptr<te::graph::AbstractIterator> it;
 
  105   FILE* fp = fopen(pathFileName.c_str(), 
"w");
 
  112     fprintf(fp, 
"%d\n", (
int)it->getVertexInteratorCount());
 
  128   while(it->isVertexIteratorAfterEnd() == 
false)
 
  132     std::set<int>::iterator itNeighbours = neighbours.begin();
 
  134     if(!neighbours.empty())
 
  136       fprintf(fp, 
"%d %d\n", 
id, (
int)neighbours.size());
 
  138       while(itNeighbours != neighbours.end())
 
  145             fprintf (fp, 
"%d ", e->
getIdTo());
 
  165     v = it->getNextVertex();
 
  174   std::ifstream file(pathFileName.c_str());
 
  176   if(file.is_open() == 
false)
 
  179   int count = (int)std::count(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), 
'\n');
 
  182   file.seekg(0, std::ios::beg);
 
  191   std::map<std::string, std::string> connInfo;
 
  194   std::map<std::string, std::string> graphInfo;
 
  195   graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] = 
"MEM";
 
  196   graphInfo[
"GRAPH_NAME"] = 
"gpm_gal_graph";
 
  197   graphInfo[
"GRAPH_DESCRIPTION"] = 
"Generated by Spatial Weights Exchanger.";
 
  206   typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
 
  207   boost::escaped_list_separator<char> sep(
'\\', 
' ', 
'\"');
 
  209   std::vector<std::string> line;
 
  213   std::getline(file, buffer);
 
  214   Tokenizer tok(buffer, sep);
 
  215   line.assign(tok.begin(), tok.end());
 
  217   std::string dataSetName = 
"";
 
  218   std::string attributeName = 
"";
 
  219   bool associateGeom = 
false;
 
  221   if(line.size() == 4 && ds) 
 
  223     associateGeom = 
true;
 
  225     dataSetName = line[2];
 
  226     attributeName = line[3];
 
  241   while(std::getline(file, buffer))
 
  244     Tokenizer tok(buffer, sep);
 
  245     line.assign(tok.begin(), tok.end());
 
  247     std::string vertexIdStr, nNeighboursStr;
 
  251       vertexIdStr = line[0];
 
  252       nNeighboursStr = line[1];
 
  262     int vId = atoi(vertexIdStr.c_str());
 
  272     std::getline(file, buffer);
 
  274     Tokenizer tok2(buffer, sep);
 
  275     line.assign(tok2.begin(), tok2.end());
 
  278     int nNeighbours = atoi(nNeighboursStr.c_str());
 
  282       for(
int i = 0; i < nNeighbours; ++i)
 
  284         std::string vNeighbourStr = line[i];
 
  285         int  vNeighbourId = atoi(vNeighbourStr.c_str());
 
  293           graph->
add(vNeighbour);
 
  297         int id = getEdgeId();
 
  323     associateGeometry(gpm, ds);
 
  333   std::auto_ptr<te::graph::AbstractIterator> it;
 
  347   FILE* fp = fopen(pathFileName.c_str(), 
"w");
 
  354     fprintf(fp, 
"%d\n", (
int)it->getEdgeInteratorCount());
 
  370   while(it->isEdgeIteratorAfterEnd() == 
false)
 
  379     fprintf(fp, 
"%d %d %3.7f\n", idFrom, idTo, distance);
 
  390     e = it->getNextEdge();
 
  399   std::ifstream file(pathFileName.c_str());
 
  401   if(file.is_open() == 
false)
 
  404   int count = (int)std::count(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), 
'\n');
 
  407   file.seekg(0, std::ios::beg);
 
  416   std::map<std::string, std::string> connInfo;
 
  419   std::map<std::string, std::string> graphInfo;
 
  420   graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] = 
"MEM";
 
  421   graphInfo[
"GRAPH_NAME"] = 
"gpm_gwt_graph";
 
  422   graphInfo[
"GRAPH_DESCRIPTION"] = 
"Generated by Spatial Weights Exchanger.";
 
  438   typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
 
  439   boost::escaped_list_separator<char> sep(
'\\', 
' ', 
'\"');
 
  441   std::vector<std::string> line;
 
  445   std::getline(file, buffer);
 
  446   Tokenizer tok(buffer, sep);
 
  447   line.assign(tok.begin(), tok.end());
 
  449   std::string dataSetName = 
"";
 
  450   std::string attributeName = 
"";
 
  451   bool associateGeom = 
false;
 
  453   if(line.size() == 4 && ds) 
 
  455     associateGeom = 
true;
 
  457     dataSetName = line[2];
 
  458     attributeName = line[3];
 
  473   while(std::getline(file, buffer))
 
  477     Tokenizer tok(buffer, sep);
 
  479     line.assign(tok.begin(), tok.end());
 
  481     std::string fromStr, toStr, distanceStr;
 
  487       distanceStr = line[2];
 
  497     int from = atoi(fromStr.c_str());
 
  508     int to = atoi(toStr.c_str());
 
  519     int id = getEdgeId();
 
  520     double distance = atof(distanceStr.c_str());
 
  523     e->setAttributeVecSize(1); 
 
  541     associateGeometry(gpm, ds);
 
  549   std::ifstream file(pathFileName.c_str());
 
  551   if(file.is_open() == 
false)
 
  555   typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
 
  556   boost::escaped_list_separator<char> sep(
'\\', 
' ', 
'\"');
 
  558   std::vector<std::string> line;
 
  562   std::getline(file, buffer);
 
  563   Tokenizer tok(buffer, sep);
 
  564   line.assign(tok.begin(), tok.end());
 
  568     dataSetName = line[2];
 
  607   task.setMessage(
TE_TR(
"Associating Geometry to graph."));
 
  609   dataSet->moveBeforeFirst();
 
  611   while(dataSet->moveNext())
 
  615     int id = atoi(strId.c_str());
 
  623       std::auto_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
 
  650       v->addAttribute(0, ad);
 
MultiPolygon is a MultiSurface whose elements are Polygons. 
 
#define TE_SA_GEOMETRY_ATTR_NAME
 
void setAttributeVecSize(int size)
This function is used to set the number of attributes associated with the vertex elements. 
 
void exportToGWT(te::sa::GeneralizedProximityMatrix *gpm, std::string pathFileName, int distAttrIdx)
Function used to export a gpm to Spatial Weights File GWT Format. 
 
void setMessage(const std::string &message)
Set the task message. 
 
void associateGeometry(te::sa::GeneralizedProximityMatrix *gpm, te::da::DataSource *ds)
Function used to associate the geometry coord attribute to vertex objects. 
 
An atomic property like an integer or double. 
 
This class defines a Generalized Proximity Matrix. 
 
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. 
 
This class can be used to inform the progress of a task. 
 
int getEdgeId()
Function used to generated the edge id. 
 
T getValue() const 
It returns the associated value. 
 
te::sa::GeneralizedProximityMatrix * importFromGAL(std::string pathFileName, te::da::DataSource *ds=0)
Function used to import a gpm from a Spatial Weights File GAL Format. 
 
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
This class defines functions used to load and save gpm's using GAL and GWT formats, both formats use a ' ' as separator. 
 
te::sa::GeneralizedProximityMatrix * importFromGWT(std::string pathFileName, te::da::DataSource *ds=0)
Function used to import a gpm from a Spatial Weights File GWT Format. 
 
virtual void add(Vertex *v)=0
Add a new vertex element to a graph. 
 
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...
 
void setTotalSteps(int value)
Set the task total stepes. 
 
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...
 
void setDataSetName(const std::string &dataSetName)
 
SpatialWeightsExchanger()
Default constructor. 
 
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. 
 
#define TE_SA_WEIGHT_ATTR_NAME
 
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 pulse()
Calls setCurrentStep() function using getCurrentStep() + 1. 
 
A base class for values that can be retrieved from the data access module. 
 
std::set< int > & getSuccessors()
Returns the Successors vector. 
 
int getIdFrom()
It returns the vertex origin identification. 
 
static void getSpatialWeightsFileInfo(std::string pathFileName, std::string &dataSetName, std::string &attrName)
Function used to get information of how a Spatial Weights was generated. 
 
void exportToGAL(te::sa::GeneralizedProximityMatrix *gpm, std::string pathFileName)
Function used to export a gpm to Spatial Weights File GAL Format. 
 
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
 
~SpatialWeightsExchanger()
Virtual destructor. 
 
static const std::string sm_factoryGraphTypeDirectedGraph
Directed Graph Factory Name. 
 
std::string getDataSetName()
 
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings. 
 
std::string getAttributeName()
 
Point * getCentroid() const 
It returns the mathematical centroid for this surface as a point. 
 
int getId()
It returns the vertex id. 
 
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. 
 
void setAttributeName(const std::string &attrName)
 
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. 
 
void setGraph(te::graph::AbstractGraph *graph)
 
te::graph::AbstractGraph * getGraph()
 
int getIdTo()
It returns the vertex destiny identification. 
 
This class defines the GPM class. 
 
void setParent(Property *p)
It associate this property to the informed parent.