All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterManagerDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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/tools/rastermanager/qt/RasterManagerDialog.cpp
22 
23  \brief Raster Manager GUI
24  */
25 
26 // Raster Manager
27 #include "RasterManagerDialog.h"
28 #include "../core/Utils.h"
29 
30 // TerraLib
31 #include <terralib/common.h>
32 #include <terralib/raster.h>
33 
34 // Qt
35 #include <QtGui/QtGui>
36 
37 // Boost
38 #include <boost/filesystem.hpp>
39 
40 void setWaitCursor(QWidget* w)
41 {
42 
43  QCursor c(Qt::CursorShape::WaitCursor);
44  w->setCursor(c);
45 }
46 
47 void setReleaseCursor(QWidget* w)
48 {
49  QCursor c(Qt::CursorShape::ArrowCursor);
50  w->setCursor(c);
51 }
52 
54  : QDialog(parent, f)
55 {
56  setupUi(this);
57 
58  m_rm = new RasterManager();
59 
60  copyBandTypeComboBox->setEnabled(false);
61 
62  // Validators
63  sridLineEdit->setValidator(new QIntValidator());
64  llxLineEdit->setValidator(new QDoubleValidator());
65  llyLineEdit->setValidator(new QDoubleValidator());
66  urxLineEdit->setValidator(new QDoubleValidator());
67  uryLineEdit->setValidator(new QDoubleValidator());
68 
69  connect(functionsTabWidget, SIGNAL(currentChanged(int)), this, SLOT(functionsTabWidget_currentChanged(int)));
70 
71  connect(inputPushButton, SIGNAL(clicked()), this, SLOT(inputPushButton_clicked()));
72  connect(outputPushButton, SIGNAL(clicked()), this, SLOT(outputPushButton_clicked()));
73 
74  connect(copyPushButton, SIGNAL(clicked()), this, SLOT(copyPushButton_clicked()));
75  connect(reprojectPushButton, SIGNAL(clicked()), this, SLOT(reprojectPushButton_clicked()));
76  connect(convertPushButton, SIGNAL(clicked()), this, SLOT(convertPushButton_clicked()));
77  connect(resolutionPushButton, SIGNAL(clicked()), this, SLOT(resolutionPushButton_clicked()));
78  connect(trimPushButton, SIGNAL(clicked()), this, SLOT(trimPushButton_clicked()));
79 }
80 
82 {
83 }
84 
86 {
87  std::string file = QFileDialog::getOpenFileName(this, tr("Open Raster"), "", "").toStdString();
88 
89  if(file.empty())
90  return;
91 
92  inputLineEdit->setText(file.c_str());
93 
94  std::string errorMessage;
95  if(!m_rm->init(file, errorMessage))
96  {
97  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
98  return;
99  }
100 
101  std::ostringstream output;
102  if(!m_rm->getRasterInfo(output, errorMessage))
103  {
104  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
105  return;
106  }
107 
108  infoTextEdit->setText(output.str().c_str());
109 
110  te::rst::Raster* inputRaster;
111  if(!Utils::getRaster(file, inputRaster, errorMessage))
112  {
113  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
114  return;
115  }
116 
117  // Copy
118  {
119  copyBandsListWidget->clear();
120  for(size_t i = 0; i < inputRaster->getNumberOfBands(); i++)
121  copyBandsListWidget->addItem(te::common::Convert2String(i).c_str());
122  }
123 
124  // Convert
125  {
126  std::vector<std::string> extents;
127  m_rm->getSupportedExtensions(extents, errorMessage);
128  for(size_t i = 0; i < extents.size(); i++)
129  extensionComboBox->addItem(extents[i].c_str());
130  }
131 
132  // Resolution
133  {
134  methodComboBox->addItem("");
135  methodComboBox->addItem(tr("Nearest Neighbor"));
136  methodComboBox->addItem(tr("Bilinear method"));
137  methodComboBox->addItem(tr("Bicubic method"));
138  }
139 }
140 
141 // Copy
143 {
144 
145  std::string extension = boost::filesystem3::extension(inputLineEdit->text().toStdString());
146  std::string inName = boost::filesystem3::basename(inputLineEdit->text().toStdString());
147  inName += extension;
148 
149  std::string file = QFileDialog::getSaveFileName(this, tr("Save Raster"), inName.c_str(), "").toStdString();
150 
151  if(file.empty())
152  return;
153 
154  outputLineEdit->setText(file.c_str());
155 }
156 
158 {
159  if(outputLineEdit->text().isEmpty() || inputLineEdit->text().isEmpty())
160  return;
161 
162  setWaitCursor(this);
163 
164  std::string errorMessage;
165  if(!m_rm->init(inputLineEdit->text().toStdString(), errorMessage))
166  {
167  setReleaseCursor(this);
168  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
169  return;
170  }
171 
172  std::vector<int> bands;
173  size_t it = 0;
174  while(it != copyBandsListWidget->selectedItems().count())
175  {
176  bands.push_back(atoi(copyBandsListWidget->selectedItems()[it]->text().toLatin1()));
177 
178  ++it;
179  }
180 
181  if(!m_rm->copyRaster(outputLineEdit->text().toStdString(), bands, int(), errorMessage))
182  {
183  setReleaseCursor(this);
184  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
185  return;
186  }
187 
188  setReleaseCursor(this);
189  QMessageBox::information(this, tr("Copy Executed"), tr("Copy Executed Satisfactorily!"));
190 
191 }
192 
194 {
195  if(outputLineEdit->text().isEmpty() || inputLineEdit->text().isEmpty())
196  return;
197 
198  setWaitCursor(this);
199 
200  std::string errorMessage;
201  if(!m_rm->init(inputLineEdit->text().toStdString(), errorMessage))
202  {
203  setReleaseCursor(this);
204  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
205  return;
206  }
207 
208  if(!m_rm->reproject(outputLineEdit->text().toStdString(), atoi(sridLineEdit->text().toLatin1()), errorMessage))
209  {
210  setReleaseCursor(this);
211  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
212  return;
213  }
214 
215  setReleaseCursor(this);
216  QMessageBox::information(this, tr("Reproject Executed"), tr("Reproject Executed Satisfactorily!"));
217 }
218 
220 {
221  if(inputLineEdit->text().isEmpty())
222  return;
223 
224  setWaitCursor(this);
225 
226  std::string errorMessage;
227  if(!m_rm->init(inputLineEdit->text().toStdString(), errorMessage))
228  {
229  setReleaseCursor(this);
230  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
231  return;
232  }
233 
234  if(!m_rm->convert(outputLineEdit->text().toStdString(), extensionComboBox->currentText().toStdString(),
235  std::vector<int>(), errorMessage))
236  {
237  setReleaseCursor(this);
238  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
239  return;
240  }
241 
242  setReleaseCursor(this);
243  QMessageBox::information(this, tr("Conversion Executed"), tr("Conversion Executed Satisfactorily!"));
244 }
245 
247 {
248  if(outputLineEdit->text().isEmpty() || inputLineEdit->text().isEmpty())
249  return;
250 
251  setWaitCursor(this);
252 
253  if(methodComboBox->currentIndex() == 0)
254  {
255  setReleaseCursor(this);
256  QMessageBox::warning(this, tr("Warning"), tr("Select a Method!"));
257  return;
258  }
259 
260  std::string errorMessage;
261  if(!m_rm->init(inputLineEdit->text().toStdString(), errorMessage))
262  {
263  setReleaseCursor(this);
264  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
265  return;
266  }
267 
268  if(!m_rm->changeResolution(outputLineEdit->text().toStdString(), methodComboBox->currentIndex(),
269  scaleSpinBox->value(), errorMessage))
270  {
271  setReleaseCursor(this);
272  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
273  return;
274  }
275 
276  setReleaseCursor(this);
277  QMessageBox::information(this, tr("Change Resolution Executed"), tr("Resolution Changed Satisfactorily!"));
278 
279 }
280 
282 {
283  if(outputLineEdit->text().isEmpty() || inputLineEdit->text().isEmpty())
284  return;
285 
286  setWaitCursor(this);
287 
288  if(llxLineEdit->text().isEmpty() || llyLineEdit->text().isEmpty()
289  || urxLineEdit->text().isEmpty() || uryLineEdit->text().isEmpty())
290  {
291  setReleaseCursor(this);
292  QMessageBox::warning(this, tr("Warning"), tr("Complete the required parameters!"));
293  return;
294  }
295 
296  std::string errorMessage;
297  if(!m_rm->init(inputLineEdit->text().toStdString(), errorMessage))
298  {
299  setReleaseCursor(this);
300  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
301  return;
302  }
303 
304  std::vector<double> env;
305  env[0] = atof(llxLineEdit->text().toLatin1());
306  env[1] = atof(llyLineEdit->text().toLatin1());
307  env[2] = atof(urxLineEdit->text().toLatin1());
308  env[3] = atof(uryLineEdit->text().toLatin1());
309 
310  if(!m_rm->trim(outputLineEdit->text().toStdString(), env, errorMessage))
311  {
312  setReleaseCursor(this);
313  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
314  return;
315  }
316 
317  setReleaseCursor(this);
318  QMessageBox::information(this, tr("Trim Executed"), tr("Raster Trimmed Satisfactorily!"));
319 
320 }
321 
323 {
324  if(id == 3)
325  outputGroupBox->setEnabled(false);
326  else
327  if(!outputGroupBox->isEnabled())
328  outputGroupBox->setEnabled(true);
329 }
330 
332 {
333 }
Class with methods to manage and manipulate rasters.
Definition: RasterManager.h:44
Raster Manager GUI.
An abstract class for raster data strucutures.
Definition: Raster.h:71
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
RasterManagerDialog(QWidget *parent=0, Qt::WindowFlags f=0)
static bool getRaster(std::string path, te::rst::Raster *&raster, std::string &errorMessage)
Get a raster based in the path.
Definition: Utils.cpp:93
This file contains include headers for the TerraLib Common Runtime module.
void setWaitCursor(QWidget *w)
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
void setReleaseCursor(QWidget *w)