ShowVauesTool.cpp
Go to the documentation of this file.
1 /*!
2 \file terralib/qt/plugins/mnt/ShowValuesTool.cpp
3 
4 \brief This file contains a class to Show MNT Values Tool.
5 
6 */
7 
8 #include "Config.h"
9 
10 //terralib
11 #include "../../widgets/tools/CoordTracking.h"
12 #include "../../widgets/Utils.h"
13 #include "../../../qt/widgets/canvas/MapDisplay.h"
14 #include "../../../dataaccess/utils/Utils.h"
15 #include "../../../maptools/AbstractLayer.h"
16 #include "../../../maptools/MapDisplay.h"
17 #include "../../../maptools/RasterTransform.h"
18 #include "../../../maptools/Utils.h"
19 #include "../../../raster.h"
20 
21 #include "ShowValuesAction.h"
22 #include "ShowValuesTool.h"
23 
24 // Qt
25 #include <QMessageBox>
26 #include <QMouseEvent>
27 
28 #include <iostream>
29 
31  : te::qt::widgets::AbstractTool(display, parent)
32 {
33  m_app = app;
34 }
35 
37 
39 {
40  QStatusBar* sb = m_app->statusBar();
41 
42  std::list<te::map::AbstractLayerPtr> layers = te::qt::widgets::GetSelectedLayersOnly(m_app->getLayerExplorer());
43  if (!layers.size())
44  {
45  QMessageBox::information(nullptr, tr("Show Values"), TE_TR("Select a layer!"));
46  sb->clearMessage();
47  m_action->trigger();
48  return false;
49  }
50 
51  m_layer = dynamic_cast<te::map::AbstractLayer*>((*layers.begin()).get());
52 
53  std::unique_ptr<te::da::DataSetType> dsType = m_layer->getSchema();
54  if (!dsType->hasRaster())
55  {
56  QMessageBox::information(nullptr, tr("Show Values"), TE_TR("Select a raster layer!"));
57  sb->clearMessage();
58  m_action->trigger();
59  return false;
60  }
61 
62  if (m_layer->getSRID() != m_display->getSRID())
63  {
64  QMessageBox::information(nullptr, tr("Show Values"), TE_TR("SRID layer is different SRID display!"));
65  sb->clearMessage();
66  m_action->trigger();
67  return false;
68  }
69 
70  // Converts clicked point to world coordinates
71 #if QT_VERSION >= 0x050000
72  QPointF qpoint = m_display->transform(e->localPos());
73 #else
74  QPointF qpoint = m_display->transform(e->posF());
75 #endif
76 
77  //std::unique_ptr<te::da::DataSet> inds = m_layer->getData();
78  //std::size_t rpos = te::da::GetFirstPropertyPos(inds.get(), te::dt::RASTER_TYPE);
79  //std::unique_ptr<te::rst::Raster> raster(inds->getRaster(rpos).release());
80  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer));
81 
82  //create the raster transform
83  te::map::RasterTransform rt(raster.get(), nullptr);
84 
85  te::gm::Coord2D coord = raster->getGrid()->geoToGrid(qpoint.x(), qpoint.y());
86 
87  int x = te::rst::Round(coord.x);
88  int y = te::rst::Round(coord.y);
89 
90  if (x >= 0 && y >= 0 && x < (int)raster->getNumberOfColumns() && y < (int)raster->getNumberOfRows())
91  {
92  double val;
93  raster->getValue(x, y, val, 0);
94 
95  QString information;
96  if (val != raster->getBand(0)->getProperty()->m_noDataValue)
97  information = QString(tr("Coord: %1, %2 Value: %3")).arg(qpoint.x(), 0, 'f').arg(qpoint.y(), 0, 'f').arg(val);
98  else
99  information = QString(tr("Coord: %1, %2 NODATA")).arg(qpoint.x(), 0, 'f').arg(qpoint.y(), 0, 'f');
100 
101  sb->showMessage(information);
102  }
103  else
104  sb->showMessage("");
105 
106  //raster.release();
107  //inds.release();
108  // dsType.release();
109 
110  return true;
111 }
This is the base class for layers.
Definition: AbstractLayer.h:77
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
Configuration flags for the MNT Qt Widget plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
ShowValuesTool(te::qt::widgets::MapDisplay *display, te::qt::af::BaseApplication *app, QObject *parent=0)
te::map::AbstractLayer * m_layer
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
This file defines the Show MNT Values Proccess.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
virtual std::unique_ptr< LayerSchema > getSchema() const =0
It returns the layer schema.
URI C++ Library.
Definition: Attributes.h:37
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
te::qt::widgets::LayerItemView * getLayerExplorer()
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
TEQTWIDGETSEXPORT std::list< te::map::AbstractLayerPtr > GetSelectedLayersOnly(te::qt::widgets::LayerItemView *view, const bool getFolder=false)
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
A Raster Transform is a class that defines functions to transform a styled raster.
te::qt::af::BaseApplication * m_app