All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ClippingWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/qt/widgets/rp/ClippingWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a clipping operation defined by RP module.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../geometry/Envelope.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../raster/Raster.h"
32 #include "../../../raster/Interpolator.h"
33 #include "../help/HelpPushButton.h"
34 #include "../layer/search/LayerSearchWidget.h"
35 #include "../layer/search/LayerSearchWizardPage.h"
36 #include "../progress/ProgressViewerDialog.h"
37 #include "ClippingWizard.h"
38 #include "ClippingWizardPage.h"
39 #include "RasterInfoWidget.h"
40 #include "RasterInfoWizardPage.h"
41 #include "Utils.h"
42 
43 // STL
44 #include <cassert>
45 
46 // Qt
47 #include <QMessageBox>
48 
49 
51  : QWizard(parent)
52 {
53  //configure the wizard
54  this->setWizardStyle(QWizard::ModernStyle);
55  this->setWindowTitle(tr("Clipping"));
56  //this->setFixedSize(640, 580);
57 
58  this->setOption(QWizard::HaveHelpButton, true);
59  this->setOption(QWizard::HelpButtonOnRight, false);
60 
62 
63  this->setButton(QWizard::HelpButton, helpButton);
64 
65  helpButton->setPageReference("plugins/rp/rp_clipping.html");
66 
67  addPages();
68 }
69 
71 {
72 
73 }
74 
76 {
77  if(currentPage() == m_layerSearchPage.get())
78  {
79  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
80 
81  if(list.empty() == false)
82  {
83  te::map::AbstractLayerPtr l = *list.begin();
84 
85  m_clippingPage->set(l);
86  }
87 
88  return m_layerSearchPage->isComplete();
89  }
90  else if(currentPage() == m_clippingPage.get())
91  {
92  bool res = m_clippingPage->isComplete();
93 
94  if(!res)
95  QMessageBox::warning(this, tr("Warning"), tr("Select at least one band."));
96 
97  return res;
98  }
99  else if(currentPage() == m_rasterInfoPage.get())
100  {
101  return execute();
102  }
103 
104  return true;
105 }
106 
107 void te::qt::widgets::ClippingWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
108 {
109  m_layerSearchPage->getSearchWidget()->setList(layerList);
110  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
111 
112  m_clippingPage->setList(layerList);
113 }
114 
116 {
117  m_clippingPage->set(layer);
118 }
119 
121 {
122  return m_outputLayer;
123 }
124 
126 {
127  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
128  m_clippingPage.reset(new te::qt::widgets::ClippingWizardPage(this));
129  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
130 
131  addPage(m_layerSearchPage.get());
132  addPage(m_clippingPage.get());
133  addPage(m_rasterInfoPage.get());
134 
135  //for contrast only one layer can be selected
136  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
137 }
138 
140 {
141  if(m_rasterInfoPage->getWidget()->fileExists())
142  {
143  QMessageBox::warning(this, tr("Clipping"), tr("File already exists."));
144  return false;
145  }
146 
147  if(m_clippingPage->isExtentClipping())
148  return executeExtentClipping();
149  else if(m_clippingPage->isDimensionClipping())
150  return executeDimensionClipping();
151  else if(m_clippingPage->isLayerClipping())
152  return executeLayerClipping();
153 
154  return false;
155 }
156 
158 {
159  //get raster
160  te::map::AbstractLayerPtr layer = m_clippingPage->get();
161  std::auto_ptr<te::da::DataSet> ds = layer->getData();
162 
163  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
164  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
165 
166  //get parameters
167  te::gm::Envelope env;
168 
169  m_clippingPage->getExtentClipping(env);
170 
171  if(!env.intersects(*inputRst->getExtent()))
172  {
173  QMessageBox::warning(this, tr("Clipping"), tr("Selected area do not intersects the raster extent."));
174  return false;
175  }
176 
177  std::map<std::string, std::string> info = m_rasterInfoPage->getWidget()->getInfo();
178 
179  //execute clipping
180  te::rst::Raster* outputRst = inputRst->trim(&env, info);
181 
182  if(outputRst)
183  {
184  delete outputRst;
185 
186  //set output layer
187  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
188  m_rasterInfoPage->getWidget()->getInfo());
189  }
190  return true;
191 }
192 
194 {
195  //get raster
196  te::map::AbstractLayerPtr layer = m_clippingPage->get();
197  std::auto_ptr<te::da::DataSet> ds = layer->getData();
198 
199  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
200  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
201 
202  //get parameters
203  int x, y, width, height;
204 
205  m_clippingPage->getDimensionClipping(x, y, width, height);
206 
207  std::map<std::string, std::string> info = m_rasterInfoPage->getWidget()->getInfo();
208 
209  //execute clipping
210  te::rst::Raster* outputRst = inputRst->resample(te::rst::Interpolator::NearestNeighbor, y, x, height, width, height, width, info);
211 
212  if(outputRst)
213  {
214  delete outputRst;
215 
216  //set output layer
217  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
218  m_rasterInfoPage->getWidget()->getInfo());
219  }
220 
221  return true;
222 }
223 
225 {
226  return false;
227 }
228 
Utility functions for the data access module.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
Definition: Envelope.h:493
void setPageReference(const QString &ref)
Sets the documentation page reference.
virtual Raster * resample(int method, unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, unsigned int newheight, unsigned int newwidth, const std::map< std::string, std::string > &rinfo) const
Resample a subset of the raster, given a box.
Definition: Raster.cpp:516
te::map::AbstractLayerPtr getOutputLayer()
A Qt dialog that allows users to run a clipping operation defined by RP module.
This file defines a class for a Raster Info Wizard page.
This file defines a class for a Clipping Wizard page.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
An abstract class for raster data strucutures.
Definition: Raster.h:71
This class is GUI used to define the raster info parameters for raster factory.
This file has the RasterInfoWidget class.
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo)
Subsetting operation for trimming (cropping) the raster.
Definition: Raster.cpp:422
void setLayer(te::map::AbstractLayerPtr layer)
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:432
Near neighborhood interpolation method.
Definition: Interpolator.h:63
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
This class is GUI used to define the clipping parameters for the RP constast operation.