examples/ogc-wms/main.cpp
Go to the documentation of this file.
1 
2 // STL
3 #include <cstdlib>
4 #include <string>
5 #include <iostream>
6 
7 //TerraLib
8 #include "../../src/terralib/ws/ogc/wms/client/XMLParser.h"
9 #include "../../src/terralib/common/TerraLib.h"
10 #include "../../src/terralib/qt/af/ApplicationController.h"
11 #include "../../src/terralib/ws/ogc/wms/client/WMSClient.h"
12 
13 #include <QApplication>
14 
15 int main(int argc, char *argv[])
16 {
18 
19  QApplication app(argc, argv);
20 
22 
23  // Directory where temporary WMS data will be stored.
24  std::string usrDataDir = te::qt::af::AppCtrlSingleton::getInstance().getUserDataDir().toUtf8().data();
25 
26  // Version that will be used on WMS Requests.
27  std::string version = "1.3.0";
28 
29  // WMS server URL.
30  std::string url = "http://terrabrasilis.info/terraamazon/ows";
31 
32  {
33  std::cout << "GetCapabilities Example." << std::endl;
34 
35  te::ws::ogc::WMSClient client (usrDataDir, url, version);
36 
37  client.updateCapabilities();
38 
40 
41  te::ws::ogc::wms::Layer rootLayer = capabilities.m_capability.m_layer;
42 
43  std::vector<te::ws::ogc::wms::Layer> childLayers = rootLayer.m_layers;
44 
45  for(size_t i = 0; i < childLayers.size(); i++)
46  {
47  te::ws::ogc::wms::Layer childLayer = childLayers[i];
48 
49  std::cout << "Layer Info" << std::endl;
50 
51  std::cout << "Layer Name: " << childLayer.m_name << std::endl;
52  std::cout << "Layer Title: " << childLayer.m_title << std::endl;
53 
54  std::cout << "Layer Possible Bounding Boxes" << std::endl;
55 
56  for(size_t j = 0; j < childLayer.m_boundingBoxes.size(); j++)
57  {
59 
60  std::cout << "BoundingBox CRS: " << bbox.m_crs << std::endl;
61  std::cout << "minx: " << bbox.m_minX << std::endl;
62  std::cout << "maxx: " << bbox.m_maxX << std::endl;
63  std::cout << "minx: " << bbox.m_minX << std::endl;
64  std::cout << "maxy: " << bbox.m_maxY << std::endl;
65  }
66 
67  for(size_t j = 0; j < childLayer.m_styles.size(); j++)
68  {
69  te::ws::ogc::wms::Style style = childLayer.m_styles[j];
70 
71  std::cout << "Style: " << style.m_name << std::endl;
72  std::cout << "LegendURL: " << style.m_legendURL.m_onlineResource.m_href << std::endl;
73  }
74 
75  std::cout << "============================" << std::endl;
76  }
77  }
78 
79  {
80  std::cout << "GetMap Example." << std::endl;
81 
82  te::ws::ogc::WMSClient client (usrDataDir, url);
83 
84  client.updateCapabilities();
85 
87 
88  te::ws::ogc::wms::Layer rootLayer = capabilities.m_capability.m_layer;
89 
90  std::vector<te::ws::ogc::wms::Layer> childLayers = rootLayer.m_layers;
91 
92  te::ws::ogc::wms::Layer layer = childLayers[0];
93 
95 
96  // GetMap request parameters
98  request.m_layers.push_back(layer.m_name);
99  request.m_srs = bbox.m_crs;
100  request.m_boundingBox = bbox;
101  request.m_format = "image/png";
102  request.m_transparent = true;
103  request.m_width = 500;
104  request.m_height = 500;
105 
106  if(!layer.m_styles.empty())
107  {
108  request.m_styles.push_back(layer.m_styles[0].m_name);
109  }
110 
111  //GetMap response with image buffer
112  te::ws::ogc::wms::WMSGetMapResponse response = client.getMap(request);
113 
114  std::cout << "Buffer Size: " << response.m_size << std::endl;
115  std::cout << "Buffer Format: " << response.m_format << std::endl;
116  }
117 
118  std::cout << "============================" << std::endl;
119 
120  {
121  std::cout << "GetFeatureInfo Example." << std::endl;
122 
123  te::ws::ogc::WMSClient client (usrDataDir, url);
124 
125  client.updateCapabilities();
126 
128 
129  te::ws::ogc::wms::Layer rootLayer = capabilities.m_capability.m_layer;
130 
131  std::vector<te::ws::ogc::wms::Layer> childLayers = rootLayer.m_layers;
132 
133  te::ws::ogc::wms::Layer layer = childLayers[0];
134 
136 
137  // GetMap request parameters
139  getMap.m_layers.push_back(layer.m_name);
140  getMap.m_srs = bbox.m_crs;
141  getMap.m_boundingBox = bbox;
142  getMap.m_format = "image/png";
143  getMap.m_transparent = true;
144  getMap.m_width = 500;
145  getMap.m_height = 500;
146 
147  if(!layer.m_styles.empty())
148  {
149  getMap.m_styles.push_back(layer.m_styles[0].m_name);
150  }
151 
153  request.m_queryLayers.push_back(layer.m_name);
154  request.m_infoFormat = "text/plain";
155  request.m_featureCount = 1;
156  request.m_i = 250;
157  request.m_j = 250;
158  request.m_exceptions = "application/vnd.ogc.se_xml";
159  request.m_getMap = getMap;
160 
162 
163  std::cout << response.m_featureInfoContent << std::endl;
164  std::cout << "Feature Info Format: " << response.m_infoFormat << std::endl;
165  }
166 
168 
169  return EXIT_SUCCESS;
170 }
const te::ws::ogc::wms::WMSGetMapResponse getMap(const te::ws::ogc::wms::WMSGetMapRequest &request) const
Return the WMSGetMapResponse member.
Definition: WMSClient.cpp:118
const te::ws::ogc::wms::WMSCapabilities & getCapabilities() const
Return the WMSCapabilities member.
Definition: WMSClient.cpp:108
int main(int argc, char *argv[])
The Capability WMS 1.3.0 struct.
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
te::da::DataSourceCapabilities capabilities
The WMSGetFeatureInfoRequest WMS 1.3.0 struct.
The Layer WMS 1.3.0 struct.
The WMSGetMapResponse WMS 1.3.0 struct.
The WMSGetMapResponse WMS 1.3.0 struct.
const te::ws::ogc::wms::WMSGetFeatureInfoResponse getFeatureInfo(const te::ws::ogc::wms::WMSGetFeatureInfoRequest &request) const
It execute a WMS GetFeatureInfo and returns a WMSGetFeatureInfoResponse with the result.
Definition: WMSClient.cpp:147
void initialize()
It initializes the TerraLib Platform.
The Style WMS 1.3.0 struct.
void updateCapabilities()
Method to get the capabilities from a WMS server and store in m_capabilities member.
Definition: WMSClient.cpp:67
A class to retrieve information and data from a Web Map Service.
Definition: WMSClient.h:57
std::vector< BoundingBox > m_boundingBoxes
The WMSGetMapRequest WMS 1.3.0 struct.
The BoundingBox WMS 1.3.0 struct.