WMSGetFeatureInfoMaker.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2017 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/ws/ogc/wms/qt/WMSGetFeatureInfoMaker.cpp
22 
23  \brief WMSGetFeatureInfoMaker is a WMS implementation of AbstractFeatureInfoMaker
24  that could be used to fill a QTreeWidgetItem with GetFeatureInfo WMS operation based information.
25 */
26 
27 #include "WMSGetFeatureInfoMaker.h"
28 
29 //TerraLib
30 #include "../../../../qt/widgets/canvas/MapDisplay.h"
31 #include "../../../../maptools/WorldDeviceTransformer.h"
32 #include "../dataaccess/WMSLayer.h"
33 #include "../client/DataTypes.h"
34 
35 //QT
36 #include <QTreeWidget>
37 
39  default;
40 
42  default;
43 
45 {
46  if(layer->getVisibility() != te::map::VISIBLE)
47  return;
48 
49  te::ws::ogc::wms::WMSLayer* wmsLayer = dynamic_cast<te::ws::ogc::wms::WMSLayer*>(layer.get());
50 
51  if(wmsLayer == nullptr)
52  return;
53 
54  te::gm::Envelope reprojectedEnvelope(e);
55 
56  if((layer->getSRID() != TE_UNKNOWN_SRS) &&
57  (display->getSRID() != TE_UNKNOWN_SRS) &&
58  (layer->getSRID() != display->getSRID()))
59  {
60  reprojectedEnvelope.transform(display->getSRID(), layer->getSRID());
61  }
62 
63  if(!reprojectedEnvelope.intersects(layer->getExtent()))
64  return;
65 
66  te::gm::Envelope displayExtent = display->getExtent();
67 
68  te::map::WorldDeviceTransformer transformer (displayExtent.getLowerLeftX(), displayExtent.getLowerLeftY(),
69  displayExtent.getUpperRightX(), displayExtent.getUpperRightY(),
70  display->width(), display->height());
71 
72  double x1, y1, x2, y2;
73 
74  transformer.world2Device(e.getLowerLeftX(), e.getLowerLeftY(), x1, y1);
75  transformer.world2Device(e.getUpperRightX(), e.getUpperRightY(), x2, y2);
76 
77  te::gm::Envelope auxEnv (x1, y1, x2, y2);
78 
79  te::gm::Coord2D center = auxEnv.getCenter();
80 
82 
84  infoRequest.m_queryLayers.push_back(wmsLayer->getDataSetName());
85  infoRequest.m_getMap = getMap;
86  infoRequest.m_i = static_cast<int>(center.getX());
87  infoRequest.m_j = static_cast<int>(center.getY());
88 
89  te::ws::ogc::wms::WMSGetFeatureInfoResponse response = wmsLayer->getFeatureInfo(infoRequest);
90 
91  QTreeWidgetItem* getFeatureInfoItem = new QTreeWidgetItem(layerItem);
92  getFeatureInfoItem->setText(0, QString("GetFeatureInfo"));
93 
94  getFeatureInfoItem->setText(1, response.m_featureInfoContent.c_str());
95 
96  QTreeWidget* treeWidget = layerItem->treeWidget();
97 
98  if(treeWidget != nullptr)
99  {
100  treeWidget->expandAll();
101  treeWidget->resizeColumnToContents(1);
102  }
103 
104 }
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
void getInfo(QTreeWidgetItem *layerItem, te::qt::widgets::MapDisplay *display, const te::map::AbstractLayerPtr &layer, const te::gm::Envelope &e)
This function is an implementation to get feature information. The information based on WMS GetFeatur...
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
double getY() const
It returns the y-coordinate.
Definition: Coord2D.h:108
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
const te::ws::ogc::wms::WMSGetFeatureInfoResponse getFeatureInfo(const te::ws::ogc::wms::WMSGetFeatureInfoRequest &request)
This class implements the logic for transforming from device coordinate to world coordinate and vice-...
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
The WMSGetFeatureInfoRequest WMS 1.3.0 struct.
The WMSGetMapResponse WMS 1.3.0 struct.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
A layer with reference to a WMS Layer.
te::ws::ogc::wms::WMSGetMapRequest getRequest() const
double getX() const
It returns the x-coordinate.
Definition: Coord2D.h:102
const std::string & getDataSetName() const
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
void world2Device(double &wx, double &wy) const
It transforms the coordinate wx and wy from world coordinates to device (canvas) coordinates without ...
WMSGetFeatureInfoMaker is a WMS implementation of AbstractFeatureInfoMaker that could be used to fill...
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
The WMSGetMapRequest WMS 1.3.0 struct.