CreateIsolinesDialog.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/mnt/qt/CreateISolinesDialog.cpp
22 
23 \brief A dialog for ISolines generation
24 */
25 
26 // terralib
27 #include "../../core/filesystem/FileSystem.h"
28 #include "../../core/translator/Translator.h"
29 #include "../../common/Exception.h"
30 #include "../../common/progress/ProgressManager.h"
31 #include "../../dataaccess/datasource/DataSourceFactory.h"
32 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
33 #include "../../dataaccess/datasource/DataSourceManager.h"
34 #include "../../dataaccess/utils/Utils.h"
35 #include "../../geometry/GeometryProperty.h"
36 #include "../../mnt/core/CreateIsolinesCore.h"
37 #include "../../mnt/core/TINCreateIsolines.h"
38 #include "../../mnt/core/Utils.h"
39 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
40 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
41 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
42 #include "../../qt/widgets/srs/SRSManagerDialog.h"
43 #include "../../qt/widgets/utils/FileDialog.h"
44 #include "../../raster.h"
45 #include "../../srs/SpatialReferenceSystemManager.h"
46 #include "../../statistics/core/Utils.h"
47 #include "../../mnt/core/Utils.h"
48 
49 #include "CreateIsolinesDialog.h"
50 #include "LayerSearchDialog.h"
51 #include "ui_CreateIsolinesDialogForm.h"
52 
53 // Qt
54 #include <QFileDialog>
55 #include <QMessageBox>
56 
57 // BOOST
58 #include <boost/algorithm/string.hpp>
59 #include <boost/filesystem.hpp>
60 #include <boost/lexical_cast.hpp>
61 #include <boost/uuid/random_generator.hpp>
62 #include <boost/uuid/uuid_io.hpp>
63 
65  : QDialog(parent, f),
66  m_ui(new Ui::CreateIsolinesDialogForm),
67  m_layers(std::list<te::map::AbstractLayerPtr>()),
68  m_min(0.),
69  m_max(0.),
70  m_toFile(false),
71  m_hasDummy(false)
72 {
73  m_ui->setupUi(this);
74 
75  // add icons
76  m_ui->m_insertpushButton->setIcon(QIcon::fromTheme("mnt-isolines-right"));
77  m_ui->m_deletepushButton->setIcon(QIcon::fromTheme("mnt-isolines-left"));
78  m_ui->m_deleteallpushButton->setIcon(QIcon::fromTheme("mnt-isolines-left_all"));
79 
80  //signals
81  connect(m_ui->m_layerSearchToolButton, SIGNAL(clicked()), this, SLOT(onInputLayerToolButtonClicked()));
82  connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onInputComboBoxChanged(int)));
83 
84  connect(m_ui->m_dummycheckBox, SIGNAL(toggled(bool)), m_ui->m_dummylineEdit, SLOT(setEnabled(bool)));
85  connect(m_ui->m_dummylineEdit, SIGNAL(editingFinished()), this, SLOT(onDummyLineEditEditingFinished()));
86 
87  connect(m_ui->m_stepFixedradioButton, SIGNAL(toggled(bool)), this, SLOT(onStepFixeEnabled(bool)));
88  connect(m_ui->m_stepVariableradioButton, SIGNAL(toggled(bool)), this, SLOT(on_stepVariableraEnabled(bool)));
89 
90  connect(m_ui->m_insertpushButton, SIGNAL(clicked()), this, SLOT(oninsertpushButtonClicked()));
91  connect(m_ui->m_deletepushButton, SIGNAL(clicked()), this, SLOT(ondeletepushButtonClicked()));
92  connect(m_ui->m_deleteallpushButton, SIGNAL(clicked()), this, SLOT(ondeleteallpushButtonClicked()));
93 
94  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
95  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
96  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
97 
98  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
99  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
100 
101  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
102  m_ui->m_helpPushButton->setPageReference("plugins/mnt/DTM_MainIsolines.html");
103 
104  m_ui->m_srsToolButton->setIcon(QIcon::fromTheme("srs"));
105  connect(m_ui->m_srsToolButton, SIGNAL(clicked()), this, SLOT(onSrsToolButtonClicked()));
106 
107  m_ui->m_stepFixedradioButton->click();
108  onStepFixeEnabled(true);
109 
110  m_outsrid = 0;
111 }
112 
114 
115 void te::mnt::CreateIsolinesDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
116 {
117  m_layers = layers;
118 
119  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
120 
121  while (it != m_layers.end())
122  {
123  if (it->get())
124  {
125  if (it->get()->isValid())
126  {
127  std::unique_ptr<te::da::DataSetType> dsType(it->get()->getSchema());
128  if (dsType.get())
129  {
130  mntType type = getMNTType(dsType.get());
131 
132  if (type == TIN)
133  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
134  if (type == GRID)
135  {
136  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
137  if (rasterProp->getBandProperties().size() == 1)
138  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
139  }
140  }
141  }
142  }
143  ++it;
144  }
145 }
146 
147 std::vector<double> GetNumericData(te::da::DataSet* dataSet, std::vector<std::string>& propName)
148 {
149  std::vector<double> result;
150  double numval;
151 
152  size_t index = 0;
153  std::vector<size_t> index_selected;
154  std::vector<std::size_t> type;
155  for (index = 0; index < dataSet->getNumProperties(); ++index)
156  for (size_t p = 0; p < propName.size(); ++p)
157  if (dataSet->getPropertyName(index) == propName[p])
158  {
159  index_selected.push_back(index);
160  type.push_back((unsigned)dataSet->getPropertyDataType(index));
161  }
162 
163  dataSet->moveFirst();
164  do
165  {
166  for (size_t i = 0; i < index_selected.size(); ++i)
167  {
168  index = index_selected[i];
169  if (!dataSet->isNull(propName[i]))
170  {
171  if (type[i] == te::dt::INT16_TYPE)
172  numval = dataSet->getInt16(index);
173  else if (type[i] == te::dt::INT32_TYPE)
174  numval = dataSet->getInt32(index);
175  else if (type[i] == te::dt::INT64_TYPE)
176  numval = (double)dataSet->getInt64(index);
177  else if (type[i] == te::dt::FLOAT_TYPE)
178  numval = dataSet->getFloat(index);
179  else if (type[i] == te::dt::DOUBLE_TYPE)
180  numval = dataSet->getDouble(index);
181  else if (type[i] == te::dt::NUMERIC_TYPE)
182  numval = boost::lexical_cast<double>(dataSet->getNumeric(index));
183  result.push_back(numval);
184  }
185  }
186  } while (dataSet->moveNext());
187 
188  return result;
189 }
190 
191 void te::mnt::CreateIsolinesDialog::getMinMax(te::map::AbstractLayerPtr inputLayer, double &vmin, double &vmax)
192 {
193  std::unique_ptr<te::da::DataSet> dataquery;
194  std::vector<te::gm::Polygon *> vp;
195  te::da::DataSourcePtr ds = te::da::GetDataSource(inputLayer->getDataSourceId());
196  vmin = std::numeric_limits<double>::max();
197  vmax = -vmin;
198 
199  std::unique_ptr<te::da::DataSetType> dsType = m_inputLayer->getSchema();
200  std::vector<te::dt::Property*> props = dsType->getProperties();
201 
202  std::unique_ptr<te::da::DataSet> inDset = ds->getDataSet(m_inputLayer->getDataSetName());
203  try
204  {
205  std::size_t geo_pos = te::da::GetFirstPropertyPos(inDset.get(), te::dt::GEOMETRY_TYPE);
206  inDset->moveBeforeFirst();
207  while (inDset->moveNext())
208  {
209  std::unique_ptr<te::gm::Geometry> gin = inDset->getGeometry(geo_pos);
210  if (!gin->is3D())
211  throw te::common::Exception(TE_TR("Data without 3D information!"));
212 
213  switch (gin->getGeomTypeId())
214  {
215  case te::gm::PolygonType:
219  {
220  vp.push_back(dynamic_cast<te::gm::Polygon*>(gin->clone()));
221  break;
222  }
227  {
228  te::gm::MultiPolygon *mg = dynamic_cast<te::gm::MultiPolygon*>(gin.get());
229  if (!mg)
230  throw te::common::Exception(TE_TR("Isn't possible to read data!"));
231 
232  std::size_t np = dynamic_cast<te::gm::GeometryCollection*>(mg)->getNumGeometries();
233  for (std::size_t i = 0; i < np; i++)
234  vp.push_back(dynamic_cast<te::gm::Polygon*>(dynamic_cast<te::gm::GeometryCollection*>(mg)->getGeometryN(i)->clone()));
235  break;
236  }
241  break;
246  break;
247  case te::gm::TINType:
248  case te::gm::TINZType:
249  case te::gm::TINMType:
250  case te::gm::TINZMType:
251  break;
256  break;
257 
258  default:
259  break;
260  }
261  }
262 
263  for (std::size_t i = 0; i < vp.size(); ++i)
264  {
265  te::gm::Polygon *pol = vp[i];
266  te::gm::Curve* c = dynamic_cast<te::gm::CurvePolygon*>(pol)->getRingN(0);
267  te::gm::LinearRing* lr = dynamic_cast<te::gm::LinearRing*>(c);
268  if (lr->getZ(0) < std::numeric_limits<double>::max())
269  {
270  if (vmin > lr->getZ(0))
271  vmin = lr->getZ(0);
272  if (vmax < lr->getZ(0))
273  vmax = lr->getZ(0);
274  }
275  if (lr->getZ(1) < std::numeric_limits<double>::max())
276  {
277  if (vmin > lr->getZ(1))
278  vmin = lr->getZ(1);
279  if (vmax < lr->getZ(1))
280  vmax = lr->getZ(1);
281  }
282  if (lr->getZ(2) < std::numeric_limits<double>::max())
283  {
284  if (vmin > lr->getZ(2))
285  vmin = lr->getZ(2);
286  if (vmax < lr->getZ(2))
287  vmax = lr->getZ(2);
288  }
289  }
290  }
291  catch (te::common::Exception& e)
292  {
293  std::cerr << "CreateIsolinesDialog::getMinMax: " << e.what() << '\n';
294  QMessageBox::information(this, "CreateIsolines", e.what());
295  vmax = vmin = 0;
296  }
297 
298  for (size_t i = 0; i < vp.size(); ++i)
299  delete vp[i];
300  vp.clear();
301 }
302 
304 {
305  LayerSearchDialog search(this->parentWidget());
306  search.setLayers(m_layers);
307  QList<mntType> types;
308  types << TIN << GRID;
309  search.setActive(types);
310 
311  if (search.exec() != QDialog::Accepted)
312  {
313  return;
314  }
315 
316  int index = m_ui->m_layersComboBox->findText(search.getLayer().get()->getTitle().c_str());
317  m_ui->m_layersComboBox->setCurrentIndex(index);
318 }
319 
321 {
322  try{
323  QApplication::setOverrideCursor(Qt::WaitCursor);
324  m_inputLayer = nullptr;
325  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
326  std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
327  while (it != m_layers.end())
328  {
329  if(layerID == it->get()->getId())
330  {
331  m_inputLayer = it->get();
332 
333  setSRID(m_inputLayer->getSRID());
334 
335  std::unique_ptr<te::da::DataSetType> dsType = m_inputLayer->getSchema();
336  std::unique_ptr<te::da::DataSet> inds = m_inputLayer->getData();
337  if (dsType->hasGeom())
338  {
339  m_inputType = TIN;
341  m_ui->m_dummycheckBox->setVisible(false);
342  m_ui->m_dummylineEdit->setVisible(false);
343  }
344  if (dsType->hasRaster())
345  {
346  m_inputType = GRID;
347  std::size_t rpos = te::da::GetFirstPropertyPos(inds.get(), te::dt::RASTER_TYPE);
348  std::unique_ptr<te::rst::Raster> inputRst(inds->getRaster(rpos).release());
349 
350  te::mnt::getMinMax(inputRst.get(), m_min, m_max);
351  m_ui->m_dummycheckBox->setVisible(true);
352  m_ui->m_dummylineEdit->setVisible(true);
353  m_ui->m_dummylineEdit->setText(QString::number(inputRst->getBand(0)->getProperty()->m_noDataValue));
354  m_dummy = inputRst->getBand(0)->getProperty()->m_noDataValue;
355  }
356 
357  break;
358  }
359  it++;
360  }
361  m_ui->m_vminrasterlineEdit->setText(QString::number(m_min));
362  m_ui->m_vmaxrasterlineEdit->setText(QString::number(m_max));
363 
364  QApplication::restoreOverrideCursor();
365  }
366  catch (te::common::Exception& e)
367  {
368  QApplication::restoreOverrideCursor();
369  std::cerr << "CreateIsolines: " << e.what() << '\n';
370  QMessageBox::information(this, "CreateIsolines", e.what());
371  }
372 }
373 
375 {
376  m_dummy = m_ui->m_dummylineEdit->text().toDouble();
377  if (m_inputType == GRID)
378  {
379  std::unique_ptr<te::da::DataSet> inds = m_inputLayer->getData();
380  std::size_t rpos = te::da::GetFirstPropertyPos(inds.get(), te::dt::RASTER_TYPE);
381  std::unique_ptr<te::rst::Raster> inputRst(inds->getRaster(rpos).release());
382  inputRst->getBand(0)->getProperty()->m_noDataValue = m_dummy;
383  m_min = inputRst.get()->getBand(0)->getMinValue(true, 0, 0, inputRst->getNumberOfRows() - 1, inputRst->getNumberOfColumns() - 1).real();
384  m_max = inputRst.get()->getBand(0)->getMaxValue(true, 0, 0, inputRst->getNumberOfRows() - 1, inputRst->getNumberOfColumns() - 1).real();
385  m_ui->m_vminrasterlineEdit->setText(QString::number(m_min));
386  m_ui->m_vmaxrasterlineEdit->setText(QString::number(m_max));
387  }
388  m_hasDummy = true;
389 }
390 
392 {
393  m_ui->m_vmaxlineEdit->setEnabled(true);
394  m_ui->m_vminlineEdit->setEnabled(true);
395  m_ui->m_steplineEdit->setEnabled(true);
396  m_ui->m_valuelineEdit->setEnabled(false);
397  m_ui->m_vmaxlabel->setEnabled(true);
398  m_ui->m_vminlabel->setEnabled(true);
399  m_ui->m_steplabel->setEnabled(true);
400  m_ui->m_valuelabel->setEnabled(false);
401  m_ui->m_guidelinescheckBox->setEnabled(true);
402 }
403 
405 {
406  m_ui->m_vmaxlineEdit->setEnabled(false);
407  m_ui->m_vminlineEdit->setEnabled(false);
408  m_ui->m_steplineEdit->setEnabled(false);
409  m_ui->m_valuelineEdit->setEnabled(true);
410  m_ui->m_vmaxlabel->setEnabled(false);
411  m_ui->m_vminlabel->setEnabled(false);
412  m_ui->m_steplabel->setEnabled(false);
413  m_ui->m_valuelabel->setEnabled(true);
414  m_ui->m_guidelinescheckBox->setChecked(false);
415  m_ui->m_guidelinescheckBox->setEnabled(false);
416 }
417 
419 {
420  if (m_ui->m_stepFixedradioButton->isChecked())
421  {
422  double min = m_ui->m_vminlineEdit->text().toDouble();
423  double max = m_ui->m_vmaxlineEdit->text().toDouble();
424  double step = m_ui->m_steplineEdit->text().toDouble();
425  if (step <= 0)
426  {
427  QMessageBox::information(this, tr("Create Isolines"), tr("Step value is invalid!"));
428  return;
429  }
430 
431  for (double val = min; val <= max; val += step)
432  {
433  QListWidgetItem *item = new QListWidgetItem();
434  item->setData(Qt::DisplayRole, val);
435  m_ui->m_isolineslistWidget->addItem(item);
436  }
437  }
438  else
439  {
440  double val = m_ui->m_valuelineEdit->text().toDouble();
441  if (val < m_min || val > m_max)
442  {
443  QMessageBox::information(this, tr("Create Isolines"), tr("Value is invalid!"));
444  return;
445  }
446  QListWidgetItem *item = new QListWidgetItem();
447  item->setData(Qt::DisplayRole, val);
448  m_ui->m_isolineslistWidget->addItem(item);
449  }
450 }
451 
453 {
454  QListWidgetItem *rem = m_ui->m_isolineslistWidget->takeItem(m_ui->m_isolineslistWidget->currentRow());
455  if (rem)
456  delete rem;
457 }
458 
460 {
461  m_ui->m_isolineslistWidget->clear();
462 }
463 
465 {
466  reject();
467 }
468 
470 {
471  return m_outputLayer;
472 }
473 
474 
476 {
477  m_ui->m_newLayerNameLineEdit->clear();
478  m_ui->m_newLayerNameLineEdit->setEnabled(true);
480  dlg.exec();
481 
482  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
483 
484  if (dsPtrList.empty())
485  return;
486 
487  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
488 
489  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
490 
491  m_outputDatasource = *it;
492 
493  m_toFile = false;
494 }
495 
497 {
498  m_ui->m_newLayerNameLineEdit->clear();
499  m_ui->m_repositoryLineEdit->clear();
500 
502 
503  try {
504  fileDialog.exec();
505  }
506  catch (const std::exception& e)
507  {
508  QMessageBox::information(this, tr("Create Isolines"), e.what());
509  return;
510  }
511 
512  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
513  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
514 
515  m_toFile = true;
516  m_ui->m_newLayerNameLineEdit->setEnabled(false);
517 }
518 
520 {
521  //progress
523 
524  try
525  {
526  QApplication::setOverrideCursor(Qt::WaitCursor);
527 
528  if (!m_inputLayer.get())
529  throw te::common::Exception(TE_TR("Select an input layer!"));
530 
531  te::map::DataSetLayer* indsLayer = dynamic_cast<te::map::DataSetLayer*>(m_inputLayer.get());
532  if (!indsLayer)
533  throw te::common::Exception(TE_TR("Can not execute this operation on this type of layer!"));
534 
535  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(indsLayer->getDataSourceId(), true);
536  if (!inDataSource.get())
537  throw te::common::Exception(TE_TR("The selected input data source can not be accessed!"));
538 
539  std::string inDsetName = indsLayer->getDataSetName();
540  std::unique_ptr<te::da::DataSetType> inDsetType(inDataSource->getDataSetType(inDsetName));
541 
542  // Checking consistency of output paramenters
543  if (m_ui->m_repositoryLineEdit->text().isEmpty())
544  throw te::common::Exception(TE_TR("Select a repository for the resulting layer."));
545 
546  if (m_ui->m_newLayerNameLineEdit->text().isEmpty())
547  throw te::common::Exception(TE_TR("Define a name for the resulting layer."));
548 
549  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
550  std::string outdsinfo("file://");
551  boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toUtf8().data());
552 
553  bool result = false;
554 
555  if (m_toFile)
556  {
557  if (te::core::FileSystem::exists(uri.string()))
558  throw te::common::Exception(TE_TR("Output file already exists! Remove it or select a new name and try again."));
559 
560  std::size_t idx = outputdataset.find(".");
561  if (idx != std::string::npos)
562  outputdataset = outputdataset.substr(0, idx);
563 
564  outdsinfo += uri.string();
565  }
566 
567  std::vector<double> val;
568  std::vector<double> guideval;
569  bool ok;
570  double step = m_ui->m_steplineEdit->text().toDouble(&ok);
571  if (!ok)
572  step = 0;
573 
574  double gLineValue = m_ui->m_isolineslistWidget->item(0)->text().toDouble() + step * 5;
575 
576  for (int i = 0; i < m_ui->m_isolineslistWidget->count(); i++)
577  {
578  val.push_back(m_ui->m_isolineslistWidget->item(i)->text().toDouble());
579  if (m_ui->m_guidelinescheckBox->isChecked())
580  {
581  if (val[(unsigned)i] == gLineValue)
582  {
583  guideval.push_back(gLineValue);
584  gLineValue += (step * 5);
585  }
586  }
587  }
588 
589  if (m_inputType == GRID)
590  {
591  CreateIsolines* ci = new CreateIsolines();
592  ci->setInput(inDataSource, inDsetName, std::move(inDsetType));
593  if (m_toFile)
594  {
595  te::da::DataSourcePtr dsOGR(te::da::DataSourceFactory::make("OGR", outdsinfo).release());
596  dsOGR->open();
597 
598  if (dsOGR->dataSetExists(outputdataset))
599  throw te::common::Exception(TE_TR("There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again."));
600 
601  ci->setOutput(dsOGR, outputdataset);
602  }
603  else
604  {
606  if (!aux)
607  throw te::common::Exception(TE_TR("The selected output datasource can not be accessed."));
608 
609  if (aux->dataSetExists(outputdataset))
610  throw te::common::Exception(TE_TR("Dataset already exists. Remove it or select a new name and try again. "));
611  ci->setOutput(aux, outputdataset);
612  }
613 
614  if (m_ui->m_dummycheckBox->isChecked() == true)
615  {
616  m_hasDummy = true;
617  }
618 
619  ci->setParams(val, guideval, m_max, m_min, m_dummy, m_hasDummy);
620  std::unique_ptr<te::rst::Raster> raster = ci->getPrepareRaster();
621  result = ci->run(std::move(raster));
622 
623  delete ci;
624  }
625  else //TIN
626  {
627  double tol = m_inputLayer->getExtent().getHeight() / 1.e9;
628 
630 
631  Tin->setInput(inDataSource, inDsetName, std::move(inDsetType));
632 
633  if (m_toFile)
634  {
635  te::da::DataSourcePtr dsOGR(te::da::DataSourceFactory::make("OGR", outdsinfo).release());
636  dsOGR->open();
637 
638  if (dsOGR->dataSetExists(outputdataset))
639  throw te::common::Exception(TE_TR("There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again."));
640 
641  Tin->setOutput(dsOGR, outputdataset);
642  }
643  else
644  {
646  if (!aux)
647  throw te::common::Exception(TE_TR("The selected output datasource can not be accessed."));
648  if (aux->dataSetExists(outputdataset))
649  throw te::common::Exception(TE_TR("Dataset already exists. Remove it or select a new name and try again. "));
650 
651  Tin->setOutput(aux, outputdataset);
652  }
653 
654  Tin->setSRID(m_outsrid);
655  Tin->setParams(val, guideval, tol);
656 
657  result = Tin->run();
658  delete Tin;
659  }
660 
661  if (result)
662  {
663  if (m_toFile)
664  {
665  // let's include the new datasource in the managers
666  boost::uuids::basic_random_generator<boost::mt19937> gen;
667  boost::uuids::uuid u = gen();
668  std::string id = boost::uuids::to_string(u);
669 
671  ds->setConnInfo(outdsinfo);
672  ds->setTitle(uri.stem().string());
673  ds->setAccessDriver("OGR");
674  ds->setType("OGR");
675  ds->setDescription(uri.string());
676  ds->setId(id);
677 
678  te::da::DataSourcePtr newds = te::da::DataSourceManager::getInstance().get(id, "OGR", ds->getConnInfo());
679  newds->open();
682  }
683 
684  // creating a layer for the result
686 
688 
689  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
690  m_outputLayer = converter(dt);
691  }
692  }
693  catch (const std::exception& e)
694  {
695  QApplication::restoreOverrideCursor();
696  QMessageBox::information(this, tr("Create Isolines "), e.what());
697  return;
698  }
699 
700  QApplication::restoreOverrideCursor();
701  accept();
702 }
703 
705 {
706  te::qt::widgets::SRSManagerDialog srsDialog(this);
707  srsDialog.setWindowTitle(tr("Choose the SRS"));
708 
709  if (srsDialog.exec() == QDialog::Rejected)
710  return;
711 
712  int newSRID = srsDialog.getSelectedSRS().first;
713 
714  setSRID(newSRID);
715 
716 }
717 
719 {
720  if (newSRID <= 0)
721  {
722  m_ui->m_resSRIDLabel->setText("No SRS defined");
723  }
724  else
725  {
726  std::string name = te::srs::SpatialReferenceSystemManager::getInstance().getName(newSRID);
727  if (name.size())
728  m_ui->m_resSRIDLabel->setText(name.c_str());
729  else
730  m_ui->m_resSRIDLabel->setText(QString("%1").arg(newSRID));
731  }
732  m_outsrid = newSRID;
733 }
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType)
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
std::vector< double > GetNumericData(te::da::DataSet *dataSet, std::vector< std::string > &propName)
void setParams(std::vector< double > &val, std::vector< double > &gval, double tol)
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Class to generate isolines from TIN.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
void CreateIsolines()
Defines a component for choose a file.
Definition: FileDialog.h:52
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
mntType m_inputType
Input type (TIN, GRID)
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
Definition: FileSystem.cpp:142
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
A dialog ISolines generation.
boost::shared_ptr< DataSource > DataSourcePtr
CreateIsolinesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
virtual const char * what() const
It outputs the exception message.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
A dialog Layer Search.
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Raster property.
void setSRID(int srid)
Definition: Tin.cpp:177
void getMinMax(te::map::AbstractLayerPtr inputLayer, double &min, double &max)
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
void setParams(std::vector< double > &nval, std::vector< double > &gval, double vmax, double vmin, double dummy, bool hasDummy)
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
te::map::AbstractLayerPtr getLayer()
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
URI C++ Library.
Definition: Attributes.h:37
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
static te::dt::TimeDuration dt(20, 30, 50, 11)
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
te::gm::Polygon * p
CurvePolygon is a planar surface defined by 1 exterior boundary and 0 or more interior boundaries...
Definition: CurvePolygon.h:57
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A dataset is the unit of information manipulated by the data access module of TerraLib.
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
const std::string & getDataSetName() const
Class to define TIN strutures.
Definition: Tin.h:276
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
bool run(std::unique_ptr< te::rst::Raster > raster)
void setActive(const QList< mntType > &types)
A dialog for selecting a data source.
A class that represents a data source component.
std::unique_ptr< te::rst::Raster > getPrepareRaster()
const double & getZ(std::size_t i) const
It returns the n-th z coordinate value.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
TEMNTEXPORT te::mnt::mntType getMNTType(const te::da::DataSetType *dt)
void setInput(te::da::DataSourcePtr inRasterDsrc, std::string inRasterName, std::unique_ptr< te::da::DataSetType > inDsetType)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
TEMNTEXPORT void getMinMax(te::rst::Raster *inputRst, double &vmin, double &vmax)
A dialog used to build a SRSManagerDialog element.
It is a collection of other geometric objects.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::unique_ptr< Ui::CreateIsolinesDialogForm > m_ui
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
te::map::AbstractLayerPtr getLayer()
virtual const std::string & getDataSourceId() const
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
te::map::AbstractLayerPtr m_inputLayer
Input layer.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr