46 #include "../../common/Exception.h" 47 #include "../../core/encoding/CharEncoding.h" 48 #include "../../core/translator/Translator.h" 49 #include "../../common/progress/TaskProgress.h" 50 #include "../../dataaccess/datasource/DataSource.h" 51 #include "../../dataaccess/utils/Utils.h" 52 #include "../../datatype/SimpleData.h" 53 #include "../../datatype/SimpleProperty.h" 54 #include "../../geometry/GeometryProperty.h" 55 #include "../../geometry/MultiPolygon.h" 56 #include "../../geometry/Point.h" 57 #include "../../geometry/Polygon.h" 58 #include "../../graph/core/AbstractGraph.h" 59 #include "../../graph/core/AbstractGraphFactory.h" 60 #include "../../graph/core/GraphMetadata.h" 61 #include "../../graph/core/Edge.h" 62 #include "../../graph/core/Vertex.h" 63 #include "../../graph/iterator/AbstractIterator.h" 64 #include "../../graph/iterator/SequenceIterator.h" 65 #include "../../graph/iterator/MemoryIterator.h" 66 #include "../../graph/Globals.h" 77 #include<boost/tokenizer.hpp> 88 std::unique_ptr<te::graph::AbstractIterator> it;
111 fprintf(fp,
"%d\n", (
int)it->getVertexInteratorCount());
121 task.
setTotalSteps(static_cast<int>(it->getVertexInteratorCount()));
122 task.setMessage(
TE_TR(
"Export to GAL Format."));
127 while(it->isVertexIteratorAfterEnd() ==
false)
131 std::set<int>::iterator itNeighbours = neighbours.begin();
133 if(!neighbours.empty())
135 fprintf(fp,
"%d %d\n",
id, (
int)neighbours.size());
137 while(itNeighbours != neighbours.end())
144 fprintf (fp,
"%d ", e->
getIdTo());
164 v = it->getNextVertex();
173 std::ifstream
file(pathFileName.c_str());
175 if(
file.is_open() ==
false)
178 int count = (
int)std::count(std::istreambuf_iterator<char>(
file), std::istreambuf_iterator<char>(),
'\n');
181 file.seekg(0, std::ios::beg);
190 const std::string connInfo(
"memory:");
193 std::map<std::string, std::string> graphInfo;
194 graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] =
"MEM";
195 graphInfo[
"GRAPH_NAME"] =
"gpm_gal_graph";
196 graphInfo[
"GRAPH_DESCRIPTION"] =
"Generated by Spatial Weights Exchanger.";
205 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
206 boost::escaped_list_separator<char> sep(
'\\',
' ',
'\"');
208 std::vector<std::string>
line;
212 std::getline(
file, buffer);
213 Tokenizer tok(buffer, sep);
214 line.assign(tok.begin(), tok.end());
216 std::string dataSetName;
217 std::string attributeName;
218 bool associateGeom =
false;
220 if(line.size() == 4 &&
ds)
222 associateGeom =
true;
224 dataSetName = line[2];
225 attributeName = line[3];
240 while(std::getline(
file, buffer))
243 Tokenizer tok(buffer, sep);
244 line.assign(tok.begin(), tok.end());
246 std::string vertexIdStr, nNeighboursStr;
250 vertexIdStr = line[0];
251 nNeighboursStr = line[1];
261 int vId = atoi(vertexIdStr.c_str());
271 std::getline(
file, buffer);
273 Tokenizer tok2(buffer, sep);
274 line.assign(tok2.begin(), tok2.end());
277 int nNeighbours = atoi(nNeighboursStr.c_str());
281 for(
int i = 0; i < nNeighbours; ++i)
283 std::string vNeighbourStr = line[i];
284 int vNeighbourId = atoi(vNeighbourStr.c_str());
292 graph->
add(vNeighbour);
332 std::unique_ptr<te::graph::AbstractIterator> it;
353 fprintf(fp,
"%d\n", (
int)it->getEdgeInteratorCount());
363 task.
setTotalSteps(static_cast<int>(it->getVertexInteratorCount()));
364 task.setMessage(
TE_TR(
"Export to GWT Format."));
369 while(it->isEdgeIteratorAfterEnd() ==
false)
378 fprintf(fp,
"%d %d %3.7f\n", idFrom, idTo, distance);
389 e = it->getNextEdge();
398 std::ifstream
file(pathFileName.c_str());
400 if(
file.is_open() ==
false)
403 int count = (
int)std::count(std::istreambuf_iterator<char>(
file), std::istreambuf_iterator<char>(),
'\n');
406 file.seekg(0, std::ios::beg);
415 const std::string connInfo(
"memory:");
418 std::map<std::string, std::string> graphInfo;
419 graphInfo[
"GRAPH_DATA_SOURCE_TYPE"] =
"MEM";
420 graphInfo[
"GRAPH_NAME"] =
"gpm_gwt_graph";
421 graphInfo[
"GRAPH_DESCRIPTION"] =
"Generated by Spatial Weights Exchanger.";
437 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
438 boost::escaped_list_separator<char> sep(
'\\',
' ',
'\"');
440 std::vector<std::string>
line;
444 std::getline(
file, buffer);
445 Tokenizer tok(buffer, sep);
446 line.assign(tok.begin(), tok.end());
448 std::string dataSetName;
449 std::string attributeName;
450 bool associateGeom =
false;
452 if(line.size() == 4 &&
ds)
454 associateGeom =
true;
456 dataSetName = line[2];
457 attributeName = line[3];
472 while(std::getline(
file, buffer))
476 Tokenizer tok(buffer, sep);
478 line.assign(tok.begin(), tok.end());
480 std::string fromStr, toStr, distanceStr;
486 distanceStr = line[2];
496 int from = atoi(fromStr.c_str());
507 int to = atoi(toStr.c_str());
519 double distance = atof(distanceStr.c_str());
522 e->setAttributeVecSize(1);
548 std::ifstream
file(pathFileName.c_str());
550 if(
file.is_open() ==
false)
554 typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
555 boost::escaped_list_separator<char> sep(
'\\',
' ',
'\"');
557 std::vector<std::string>
line;
561 std::getline(
file, buffer);
562 Tokenizer tok(buffer, sep);
563 line.assign(tok.begin(), tok.end());
567 dataSetName = line[2];
606 task.setMessage(
TE_TR(
"Associating Geometry to graph."));
608 dataSet->moveBeforeFirst();
610 while(dataSet->moveNext())
614 int id = atoi(strId.c_str());
622 std::unique_ptr<te::gm::Geometry> g = dataSet->getGeometry(geomPos);
649 v->addAttribute(0, ad);
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 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.
void setSRID(int srid) _NOEXCEPT_OP(true)
It sets the Spatial Reference System ID of the Point.
An atomic property like an integer or double.
#define TE_SA_GEOMETRY_ATTR_NAME
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.
#define TE_SA_WEIGHT_ATTR_NAME
static te::dt::Date ds(2010, 01, 01)
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.
static std::string fromUTF8(const std::string &src)
Convert a string in UTF-8 to the current locale encoding.
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.
int m_edgeId
Attribute used as a index counter for edge objects.
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 AbstractData * clone() const =0
It returns a clone of this object.
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.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
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.
virtual std::unique_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...
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 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.
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
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.