IntersectionDialog.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/vp/qt/IntersectionDialog.cpp
22 
23  \brief A dialog for intersection operation
24 */
25 
26 // TerraLib
27 #include "../../core/filesystem/FileSystem.h"
28 #include "../../core/logger/Logger.h"
29 #include "../../core/translator/Translator.h"
30 #include "../../common/progress/ProgressManager.h"
31 #include "../../common/StringUtils.h"
32 #include "../../dataaccess/dataset/DataSetType.h"
33 #include "../../dataaccess/dataset/ObjectIdSet.h"
34 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
35 #include "../../dataaccess/datasource/DataSourceInfo.h"
36 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
37 #include "../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../dataaccess/datasource/DataSourceFactory.h"
39 #include "../../dataaccess/query/And.h"
40 #include "../../dataaccess/query/Expression.h"
41 #include "../../dataaccess/query/In.h"
42 #include "../../dataaccess/query/Where.h"
43 #include "../../dataaccess/utils/Utils.h"
44 #include "../../datatype/Property.h"
45 #include "../../maptools/QueryLayer.h"
46 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
47 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
48 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
49 #include "../../qt/widgets/utils/DoubleListWidget.h"
50 #include "../../qt/widgets/utils/FileDialog.h"
51 #include "../../srs/Config.h"
52 #include "../Exception.h"
53 #include "../IntersectionMemory.h"
54 #include "../IntersectionOp.h"
55 #include "../IntersectionQuery.h"
56 #include "IntersectionDialog.h"
57 #include "ui_IntersectionDialogForm.h"
58 #include "Utils.h"
59 
60 // Qt
61 #include <QFileDialog>
62 #include <QGridLayout>
63 #include <QMessageBox>
64 #include <QTreeWidget>
65 
66 // BOOST
67 #include <boost/filesystem.hpp>
68 #include <boost/uuid/random_generator.hpp>
69 #include <boost/uuid/uuid_io.hpp>
70 
71 
73 
74 te::vp::IntersectionDialog::IntersectionDialog(QWidget* parent, Qt::WindowFlags f)
75  : QDialog(parent, f),
76  m_ui(new Ui::IntersectionDialogForm),
77  m_layers(std::list<te::map::AbstractLayerPtr>())
78 {
79 // add controls
80  m_ui->setupUi(this);
81 
82  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme("vp-intersection-hint").pixmap(48,48));
83  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
84 
85  //add double list widget to this form
86  m_doubleListWidget.reset(new te::qt::widgets::DoubleListWidget(m_ui->m_attrSelectionGroupBox));
87  m_doubleListWidget->setLeftLabel("");
88  m_doubleListWidget->setRightLabel("");
89 
90  QGridLayout* layout = new QGridLayout(m_ui->m_attrSelectionGroupBox);
91  layout->addWidget(m_doubleListWidget.get());
92  layout->setContentsMargins(0, 0, 0, 0);
93 
94  connect(m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFirstLayerComboBoxChanged(int)));
95  connect(m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSecondLayerComboBoxChanged(int)));
96  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
97  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
98  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
99 
100  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
101  m_ui->m_helpPushButton->setPageReference("plugins/vp/vp_intersection.html");
102 }
103 
105 
106 void te::vp::IntersectionDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
107 {
108  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
109 
110  while (it != layers.end())
111  {
112  std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
113  if (dsType->hasGeom())
114  {
115  m_layers.push_back(*it);
116  }
117 
118  ++it;
119  }
120 
122 
124 
126 }
127 
129 {
130  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
131 
132  disconnect(m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFirstLayerComboBoxChanged(int)));
133 
134  while (it != m_layers.end())
135  {
136  m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
137  ++it;
138  }
139 
140  connect(m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFirstLayerComboBoxChanged(int)));
141 
142  QVariant varLayer = m_ui->m_firstLayerComboBox->itemData(m_ui->m_firstLayerComboBox->currentIndex(), Qt::UserRole);
143  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
144 
145  m_firstSelectedLayer = layer;
146 }
147 
149 {
150  int currIndex = m_ui->m_firstLayerComboBox->currentIndex();
151 
152  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
153 
154  disconnect(m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSecondLayerComboBoxChanged(int)));
155 
156  while (it != m_layers.end())
157  {
158  m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
159  ++it;
160  }
161 
162  m_ui->m_secondLayerComboBox->removeItem(currIndex);
163 
164  connect(m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSecondLayerComboBoxChanged(int)));
165 
166  QVariant varLayer = m_ui->m_secondLayerComboBox->itemData(m_ui->m_secondLayerComboBox->currentIndex(), Qt::UserRole);
167  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
168 
169  m_secondSelectedLayer = layer;
170 }
171 
173 {
174  return m_layerResult;
175 }
176 
178 {
179  QVariant varLayer = m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole);
180  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
181 
182  m_ui->m_secondLayerComboBox->clear();
183 
184  m_firstSelectedLayer = layer;
185 
187 
189 }
190 
192 {
193  QVariant varLayer = m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole);
194  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
195 
196  m_secondSelectedLayer = layer;
197 
199 }
200 
202 {
203  std::vector<std::string> inputValues;
204  std::vector<int> inputIds;
205 
206  std::unique_ptr<te::da::DataSetType> firstSchema;
207  std::unique_ptr<te::da::DataSetType> secondSchema;
208 
210  firstSchema = m_firstSelectedLayer->getSchema();
211  else
212  return;
213 
215  secondSchema = m_secondSelectedLayer->getSchema();
216  else
217  return;
218 
219  std::vector<te::dt::Property*> firstProps = firstSchema->getProperties();
220  for (std::size_t i = 0; i < firstProps.size(); ++i)
221  {
222  if (firstProps[i]->getType() != te::dt::GEOMETRY_TYPE)
223  {
224  inputValues.push_back(m_firstSelectedLayer->getTitle() + ": " + firstProps[i]->getName());
225  inputIds.push_back(1);
226  }
227  }
228 
229  std::vector<te::dt::Property*> secondProps = secondSchema->getProperties();
230  for (std::size_t i = 0; i < secondProps.size(); ++i)
231  {
232  if (secondProps[i]->getType() != te::dt::GEOMETRY_TYPE)
233  {
234  inputValues.push_back(m_secondSelectedLayer->getTitle() + ": " + secondProps[i]->getName());
235  inputIds.push_back(2);
236  }
237  }
238 
239  m_doubleListWidget->setInputDataValues(inputValues, inputIds);
240 }
241 
242 std::vector<std::pair<int, std::string> > te::vp::IntersectionDialog::getSelectedProperties()
243 {
244  std::vector<std::string> outValues = m_doubleListWidget->getOutputValues();
245  std::vector<int> outIds = m_doubleListWidget->getOutputDataValues();
246  std::vector<std::pair<int, std::string> > attributes;
247 
248  for (std::size_t i = 0; i < outValues.size(); ++i)
249  {
250  std::vector<std::string> tok;
251  te::common::Tokenize(outValues[i], tok, ": ");
252 
253  std::pair<int, std::string> attribute;
254  attribute.first = outIds[i];
255  attribute.second = tok[1];
256 
257  attributes.push_back(attribute);
258  }
259 
260  return attributes;
261 }
262 
264 {
265  if(m_ui->m_firstLayerComboBox->currentText().isEmpty())
266  {
267  QMessageBox::warning(this, TE_TR("Intersection"), TE_TR("Select a first input layer."));
268  return;
269  }
270 
271  const te::da::ObjectIdSet* firstOidSet = nullptr;
272  if(m_ui->m_firstSelectedCheckBox->isChecked())
273  {
274  firstOidSet = m_firstSelectedLayer->getSelected();
275  if(!firstOidSet)
276  {
277  QMessageBox::information(this, "Intersection", "Select the layer objects to perform the intersection operation.");
278  return;
279  }
280  }
281 
282  te::da::DataSourcePtr firstDataSource = te::da::GetDataSource(m_firstSelectedLayer->getDataSourceId(), true);
283  if (!firstDataSource.get())
284  {
285  QMessageBox::information(this, "Intersection", "The selected first input data source can not be accessed.");
286  return;
287  }
288 
289  if(m_ui->m_secondLayerComboBox->currentText().isEmpty())
290  {
291  QMessageBox::warning(this, TE_TR("Intersection"), TE_TR("Select a second input layer."));
292  return;
293  }
294 
295  const te::da::ObjectIdSet* secondOidSet = nullptr;
296  if(m_ui->m_secondSelectedCheckBox->isChecked())
297  {
298  secondOidSet = m_secondSelectedLayer->getSelected();
299  if(!secondOidSet)
300  {
301  QMessageBox::information(this, "Intersection", "Select the layer objects to perform the intersection operation.");
302  return;
303  }
304  }
305 
306  te::da::DataSourcePtr secondDataSource = te::da::GetDataSource(m_secondSelectedLayer->getDataSourceId(), true);
307  if (!secondDataSource.get())
308  {
309  QMessageBox::information(this, "Intersection", "The selected second input data source can not be accessed.");
310  return;
311  }
312 
313  if(m_ui->m_repositoryLineEdit->text().isEmpty())
314  {
315  QMessageBox::warning(this, TE_TR("Intersection"), TE_TR("Select a repository for the resulting layer."));
316  return;
317  }
318 
319  if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
320  {
321  QMessageBox::warning(this, TE_TR("Intersection"), TE_TR("Define a name for the resulting layer."));
322  return;
323  }
324 
325  if ((m_firstSelectedLayer->getSRID() == TE_UNKNOWN_SRS && m_secondSelectedLayer->getSRID() != TE_UNKNOWN_SRS) ||
327  {
328  int ret = QMessageBox::question(this, "Intersection", "The two layers have incompatible SRS. The result might be incorrect. Do you wish to continue?", QMessageBox::No, QMessageBox::Yes);
329  if (ret == QMessageBox::No)
330  return;
331  }
332 
333  te::map::DataSetLayer* firstDataSetLayer = nullptr;
334  te::map::QueryLayer* firstQueryLayer = nullptr;
335 
336  te::map::DataSetLayer* secondDataSetLayer = nullptr;
337  te::map::QueryLayer* secondQueryLayer = nullptr;
338 
339  if (m_firstSelectedLayer->getType() == "DATASETLAYER")
340  {
341  firstDataSetLayer = dynamic_cast<te::map::DataSetLayer*>(m_firstSelectedLayer.get());
342  }
343  else if (m_firstSelectedLayer->getType() == "QUERYLAYER")
344  {
345  firstQueryLayer = dynamic_cast<te::map::QueryLayer*>(m_firstSelectedLayer.get());
346  }
347  else
348  {
349  QMessageBox::information(this, "Intersection", "Can not execute this operation on this type of first layer.");
350  return;
351  }
352 
353  if (m_secondSelectedLayer->getType() == "DATASETLAYER")
354  {
355  secondDataSetLayer = dynamic_cast<te::map::DataSetLayer*>(m_secondSelectedLayer.get());
356  }
357  else if (m_secondSelectedLayer->getType() == "QUERYLAYER")
358  {
359  secondQueryLayer = dynamic_cast<te::map::QueryLayer*>(m_secondSelectedLayer.get());
360  }
361  else
362  {
363  QMessageBox::information(this, "Intersection", "Can not execute this operation on this type of second layer.");
364  return;
365  }
366 
367  //progress
369 
370  try
371  {
372  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
373 
374  bool res;
375  if (m_toFile)
376  {
377  boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toUtf8().data());
378 
379  if (te::core::FileSystem::exists(uri.string()))
380  {
381  QMessageBox::information(this, "Intersection", "Output file already exists. Remove it and try again. ");
382  return;
383  }
384 
385  std::size_t idx = outputdataset.find(".");
386  if(idx != std::string::npos)
387  outputdataset = outputdataset.substr(0, idx);
388 
389  std::string dsinfo("file://");
390  dsinfo += uri.string();
391 
392  te::da::DataSourcePtr dsOGR(te::da::DataSourceFactory::make("OGR", dsinfo).release());
393  dsOGR->open();
394  if(dsOGR->dataSetExists(outputdataset))
395  {
396  QMessageBox::information(this, "Intersection", "Output file already exists. Remove it or select a new name and try again.");
397  return;
398  }
399 
400  std::unique_ptr<te::da::DataSetTypeConverter> firstConverter(new te::da::DataSetTypeConverter(m_firstSelectedLayer->getSchema().get(), dsOGR->getCapabilities(), dsOGR->getEncoding()));
401  te::da::AssociateDataSetTypeConverterSRID(firstConverter.get(), m_firstSelectedLayer->getSRID());
402 
403  std::unique_ptr<te::da::DataSetTypeConverter> secondConverter(new te::da::DataSetTypeConverter(m_secondSelectedLayer->getSchema().get(), dsOGR->getCapabilities(), dsOGR->getEncoding()));
404  te::da::AssociateDataSetTypeConverterSRID(secondConverter.get(), m_firstSelectedLayer->getSRID());
405 
406  this->setCursor(Qt::WaitCursor);
407 
408  te::vp::IntersectionOp* intersectionOp = nullptr;
409 
410  // select a strategy based on the capabilities of the input datasource
411  const te::da::DataSourceCapabilities firstDSCapabilities = firstDataSource->getCapabilities();
412  const te::da::DataSourceCapabilities secondDSCapabilities = secondDataSource->getCapabilities();
413 
414  if( (firstDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() &&
415  secondDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() ) &&
416  (firstDataSource->getId() == secondDataSource->getId()) &&
417  (m_firstSelectedLayer->getSRID() == m_secondSelectedLayer->getSRID()) && (firstDataSetLayer && secondDataSetLayer))
418  {
419  intersectionOp = new te::vp::IntersectionQuery();
420  }
421  else
422  {
423  intersectionOp = new te::vp::IntersectionMemory();
424  }
425 
426  /*intersectionOp->setInput( firstDataSource, firstDataSetLayer->getDataSetName(), firstConverter,
427  secondDataSource, secondDataSetLayer->getDataSetName(), secondConverter,
428  firstOidSet, secondOidSet);*/
429 
430  std::string firstName;
431  std::string secondName;
432 
433  if (firstDataSetLayer)
434  {
435  firstName = firstDataSetLayer->getDataSetName();
436  }
437  else if (firstQueryLayer)
438  {
439  firstName = firstQueryLayer->getTitle();
440  intersectionOp->setIsFirstQuery();
441  }
442 
443  if (secondDataSetLayer)
444  {
445  secondName = secondDataSetLayer->getDataSetName();
446  }
447  else if (secondQueryLayer)
448  {
449  secondName = secondQueryLayer->getTitle();
450  intersectionOp->setIsSecondQuery();
451  }
452 
453  if (firstQueryLayer && (firstOidSet != nullptr))
454  {
455  te::da::Select* query = firstQueryLayer->getQuery();
456  te::da::Where* where = query->getWhere();
457 
458  te::da::Expression* originalExp = where->getExp();
459 
460  te::da::Expression* in = firstOidSet->getExpressionByInClause();
461 
462  te::da::Expression* cloneWhere = originalExp->clone();
463 
464  te::da::And* newAnd = new te::da::And(cloneWhere, in);
465 
466  te::da::Where* newWhere = new te::da::Where(newAnd);
467 
468  query->setWhere(newWhere);
469  }
470 
471  if (secondQueryLayer && (secondOidSet != nullptr))
472  {
473  te::da::Select* query = secondQueryLayer->getQuery();
474  te::da::Where* where = query->getWhere();
475 
476  te::da::Expression* originalExp = where->getExp();
477 
478  te::da::Expression* in = secondOidSet->getExpressionByInClause();
479 
480  te::da::Expression* cloneWhere = originalExp->clone();
481 
482  te::da::And* newAnd = new te::da::And(cloneWhere, in);
483 
484  te::da::Where* newWhere = new te::da::Where(newAnd);
485 
486  query->setWhere(newWhere);
487  }
488 
489  intersectionOp->setInput(firstDataSource, firstName, m_firstSelectedLayer->getSchema(), m_firstSelectedLayer->getData(), std::move(firstConverter),
490  secondDataSource, secondName, m_secondSelectedLayer->getSchema(), m_secondSelectedLayer->getData(), std::move(secondConverter),
491  firstOidSet, secondOidSet);
492 
493  intersectionOp->setOutput(dsOGR, outputdataset);
494  intersectionOp->setParams(getSelectedProperties());
495 
496  if (!intersectionOp->paramsAreValid())
497  res = false;
498  else
499  res = intersectionOp->run();
500 
501  if(!res)
502  {
503  dsOGR->close();
504  QMessageBox::information(this, "Intersection", "Error: could not generate the intersection.");
505  reject();
506  }
507  dsOGR->close();
508 
509  delete intersectionOp;
510 
511  // let's include the new datasource in the managers
512  boost::uuids::basic_random_generator<boost::mt19937> gen;
513  boost::uuids::uuid u = gen();
514  std::string id = boost::uuids::to_string(u);
515 
517  ds->setConnInfo(dsinfo);
518  ds->setTitle(uri.stem().string());
519  ds->setAccessDriver("OGR");
520  ds->setType("OGR");
521  ds->setDescription(uri.string());
522  ds->setId(id);
523 
524  te::da::DataSourcePtr newds = te::da::DataSourceManager::getInstance().get(id, "OGR", ds->getConnInfo());
525  newds->open();
528  }
529  else
530  {
532  if (!aux.get())
533  {
534  QMessageBox::information(this, "Intersection", "The output data source can not be accessed.");
535  return;
536  }
537  if (aux->dataSetExists(outputdataset))
538  {
539  QMessageBox::information(this, "Intersection", "Dataset already exists. Remove it or select a new name and try again. ");
540  return;
541  }
542 
543  std::unique_ptr<te::da::DataSetTypeConverter> firstConverter(new te::da::DataSetTypeConverter(m_firstSelectedLayer->getSchema().get(), aux->getCapabilities(), aux->getEncoding()));
544  te::da::AssociateDataSetTypeConverterSRID(firstConverter.get(), m_firstSelectedLayer->getSRID());
545 
546  std::unique_ptr<te::da::DataSetTypeConverter> secondConverter(new te::da::DataSetTypeConverter(m_secondSelectedLayer->getSchema().get(), aux->getCapabilities(), aux->getEncoding()));
547  te::da::AssociateDataSetTypeConverterSRID(secondConverter.get(), m_firstSelectedLayer->getSRID());
548 
549  this->setCursor(Qt::WaitCursor);
550 
551  te::vp::IntersectionOp* intersectionOp = nullptr;
552 
553  // select a strategy based on the capabilities of the input datasource
554  const te::da::DataSourceCapabilities firstDSCapabilities = firstDataSource->getCapabilities();
555  const te::da::DataSourceCapabilities secondDSCapabilities = secondDataSource->getCapabilities();
556 
557  if( firstDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() &&
558  secondDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() &&
559  (firstDataSource->getId() == secondDataSource->getId()) &&
560  (m_firstSelectedLayer->getSRID() == m_secondSelectedLayer->getSRID()) && (firstDataSetLayer && secondDataSetLayer) )
561  {
562  intersectionOp = new te::vp::IntersectionQuery();
563  }
564  else
565  {
566  intersectionOp = new te::vp::IntersectionMemory();
567  }
568 
569  intersectionOp->setInput(firstDataSource,
570  firstDataSetLayer->getDataSetName(),
571  m_firstSelectedLayer->getSchema(),
572  m_firstSelectedLayer->getData(),
573  std::move(firstConverter),
574  secondDataSource,
575  secondDataSetLayer->getDataSetName(),
576  m_secondSelectedLayer->getSchema(),
577  m_secondSelectedLayer->getData(),
578  std::move(secondConverter),
579  firstOidSet,
580  secondOidSet);
581 
582  intersectionOp->setOutput(aux, outputdataset);
583  intersectionOp->setParams(getSelectedProperties());
584 
585  if (!intersectionOp->paramsAreValid())
586  res = false;
587  else
588  res = intersectionOp->run();
589 
590  delete intersectionOp;
591 
592  if(!res)
593  {
594  this->setCursor(Qt::ArrowCursor);
595  QMessageBox::information(this, "Intersection", "Error: could not generate the intersection.");
596  reject();
597  }
598  }
599 
600  // creating a layer for the result
602 
604 
605  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
606  m_layerResult = converter(dt);
607  }
608  catch(const std::exception& e)
609  {
610  this->setCursor(Qt::ArrowCursor);
611  QMessageBox::warning(this, TE_TR("Intersection"), e.what());
612 
613 #ifdef TERRALIB_LOGGER_ENABLED
614  std::string str = "Intersection - ";
615  str += e.what();
616  TE_CORE_LOG_DEBUG("vp", str);
617 #endif //TERRALIB_LOGGER_ENABLED
618 
619  return;
620  }
621 
622  this->setCursor(Qt::ArrowCursor);
623  accept();
624 }
625 
627 {
628  m_ui->m_newLayerNameLineEdit->clear();
629  m_ui->m_newLayerNameLineEdit->setEnabled(true);
631  dlg.exec();
632 
633  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
634 
635  if(dsPtrList.empty())
636  return;
637 
638  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
639 
640  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
641 
642  m_outputDatasource = *it;
643 
644  m_toFile = false;
645 }
646 
648 {
649  m_ui->m_newLayerNameLineEdit->clear();
650  m_ui->m_repositoryLineEdit->clear();
651 
653 
654  try {
655  fileDialog.exec();
656  }
657  catch (te::common::Exception& ex) {
658  QMessageBox::warning(this, tr("File information"), ex.what());
659  return;
660  }
661 
662  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
663  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
664 
665  m_toFile = true;
666  m_ui->m_newLayerNameLineEdit->setEnabled(false);
667 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
std::list< te::map::AbstractLayerPtr > m_layers
First layer selected.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Defines a component for choose a file.
Definition: FileDialog.h:52
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
std::vector< std::pair< int, std::string > > getSelectedProperties()
std::unique_ptr< te::qt::widgets::DoubleListWidget > m_doubleListWidget
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
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual const std::string & getTitle() const
It returns the layer title.
void setInput(te::da::DataSourcePtr inFirstDsrc, std::string inFirstDsetName, std::unique_ptr< te::da::DataSetTypeConverter > firstConverter, te::da::DataSourcePtr inSecondDsrc, std::string inSecondDsetName, std::unique_ptr< te::da::DataSetTypeConverter > secondConverter, const te::da::ObjectIdSet *firstOidSet=0, const te::da::ObjectIdSet *secondOidSet=0)
virtual const char * what() const
It outputs the exception message.
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
Definition: Logger.h:225
virtual Expression * clone() const =0
It creates a new copy of this expression.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
A layer resulting from a query.
Definition: QueryLayer.h:50
static te::dt::Date ds(2010, 01, 01)
virtual bool paramsAreValid()
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
const QueryCapabilities & getQueryCapabilities() const
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
Boolean logic operator: AND.
This is an abstract class that models a query expression.
An converter for DataSetType.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:221
void setWhere(Where *w)
It sets the filter codition.
Definition: Select.cpp:799
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void setParams(const std::vector< std::pair< int, std::string > > &attributeVec)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
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
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::map::AbstractLayerPtr getLayer()
virtual bool run()=0
te::map::AbstractLayerPtr m_secondSelectedLayer
Second layer selected.
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
Expression * getExp() const
Definition: Where.cpp:58
te::da::Select * getQuery() const
Definition: QueryLayer.cpp:363
bool supportsSpatialSQLDialect() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
A dialog intersection operation.
Utility functions for the data access module.
te::map::AbstractLayerPtr m_layerResult
Generated Layer.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
Where * getWhere() const
It returns the filter condition.
Definition: Select.cpp:804
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
const std::string & getDataSetName() const
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
A dialog for selecting a data source.
A class that represents a data source component.
Expression * getExpressionByInClause(const std::string source="") const
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
void onSecondLayerComboBoxChanged(int index)
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onFirstLayerComboBoxChanged(int index)
std::unique_ptr< Ui::IntersectionDialogForm > m_ui
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::map::AbstractLayerPtr m_firstSelectedLayer
First layer selected.