BuilderLDDGraph.cpp
Go to the documentation of this file.
1 //TerraLib
2 #include "../Config.h"
6 #include <terralib/se.h>
7 #include "GraphExamples.h"
8 #include "DisplayWindow.h"
9 
10 // STL Includes
11 #include <iostream>
12 
13 // BOOST Includes
14 #include <boost/shared_ptr.hpp>
15 
16 // Qt
17 #include <QApplication>
18 
20 
21 void CreateLDDGraph(bool draw)
22 {
23  std::cout << std::endl << "Create LDD Graph..." << std::endl;
24 
25 // graph name
26  std::string graphName = "graphAsu";
27 
28 // open raster
29  std::string data_dir = TERRALIB_DATA_DIR;
30  std::unique_ptr<te::rst::Raster> lddRaster = OpenRaster(data_dir + "/graph/asu30_dem.tif", 29193);
31 
32 // graph type
34 
35 // connection info
36  std::string connInfo("memory:");
37 
38 // graph information
39  std::map<std::string, std::string> graphInfo;
40  graphInfo["GRAPH_DATA_SOURCE_TYPE"] = "MEM";
41  graphInfo["GRAPH_NAME"] = graphName;
42  graphInfo["GRAPH_DESCRIPTION"] = "Generated by LDD Builder.";
43 
44  boost::shared_ptr<te::graph::AbstractGraph> graph;
45 
46 // create graph
47  try
48  {
50 
51  if(!builder.build(lddRaster.get(), connInfo, graphType, graphInfo))
52  {
53  std::cout << std::endl << "An exception has occurred in Graph Example - CreateLDDGraph: " << builder.getErrorMessage() << std::endl;
54  }
55 
56  graph = builder.getGraph();
57  }
58  catch(const std::exception& e)
59  {
60  std::cout << std::endl << "An exception has occurred in Graph Example - CreateLDDGraph: " << e.what() << std::endl;
61  }
62  catch(...)
63  {
64  std::cout << std::endl << "An unexpected exception has occurred in Graph Example - CreateLDDGraph!" << std::endl;
65  }
66 
67  if(draw)
68  {
69  // set visual
71 
72  //start qApp
73  int argc = 0;
74  QApplication app(argc, 0);
75 
76  DisplayWindow* w = new DisplayWindow();
77  w->addGraph(graph.get(), *lddRaster->getExtent(), style);
78  w->show();
79 
80  app.exec();
81  }
82 }
83 
85 {
86  te::se::Stroke* stroke = te::se::CreateStroke("#FFFF00", "1.0");
87  te::se::LineSymbolizer* lineSymbolizer = te::se::CreateLineSymbolizer(stroke);
88 
89  te::se::Fill* markFill = te::se::CreateFill("#009900", "1.0");
90  te::se::Stroke* markStroke = te::se::CreateStroke("#000000", "1");
91  te::se::Mark* mark = te::se::CreateMark("circle", markStroke, markFill);
92  te::se::Graphic* graphic = te::se::CreateGraphic(mark, "4", "", "");
93  te::se::PointSymbolizer* pointSymbolizer = te::se::CreatePointSymbolizer(graphic);
94 
95  te::se::Rule* rule = new te::se::Rule;
96  rule->push_back(lineSymbolizer);
97  rule->push_back(pointSymbolizer);
98 
100  style->push_back(rule);
101 
102  return style;
103 }
std::unique_ptr< te::rst::Raster > OpenRaster(const std::string &pathName, const int &srid)
Auxiliar functions for load a raster.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
An static class with global definitions for the TerraLib Graph Module.
void CreateLDDGraph(bool draw)
Creates a LDD GRAPH.
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
This file contains include headers for TerraLib Symbology Encoding module.
void push_back(const std::string &semanticTypeIdentifier)
Definition: Style.cpp:75
te::se::Style * getLDDGraphStyle()
static const std::string sm_graphFactoryDefaultObject
This definition is used to set the default graph type.
TESEEXPORT LineSymbolizer * CreateLineSymbolizer(Stroke *stroke)
Creates a line symbolizer.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
void push_back(Symbolizer *s)
Definition: Rule.cpp:138
std::string getErrorMessage()
Get error message.
Abstract class used to define the main functions of graph struct. All graph implementations must used...
boost::shared_ptr< AbstractGraph > getGraph()
Get generated graph.
This strategy is based on Serio Rosim method, using this "mask" is possible extract a graph from a LD...
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
A simple main window to show example of TerraLib Qt Tools.
Definition: DisplayWindow.h:80
void addGraph(te::graph::AbstractGraph *graph, te::gm::Envelope extent, te::se::Style *s=0)
bool build(te::rst::Raster *raster, const 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.
TESEEXPORT Graphic * CreateGraphic(Mark *mark, const std::string &size, const std::string &rotation, const std::string &opacity)
Creates a graphic.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
This class defines the LDD strategy to build a graph.
A simple main window to show example of TerraLib Graph.
These routines show how to use the Graph module.
TESEEXPORT PointSymbolizer * CreatePointSymbolizer(Graphic *graphic)
Creates a point symbolizer.
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.