BufferDialog.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/BufferDialog.cpp
22 
23  \brief A dialog for buffer 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/STLUtils.h"
32 #include "../../common/UnitsOfMeasureManager.h"
33 #include "../../dataaccess/dataset/DataSetType.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/utils/Utils.h"
40 #include "../../datatype/Enums.h"
41 #include "../../datatype/Property.h"
42 #include "../../geometry/Geometry.h"
43 #include "../../geometry/GeometryProperty.h"
44 #include "../../maptools/AbstractLayer.h"
45 #include "../../maptools/DataSetLayer.h"
46 #include "../../memory/DataSet.h"
47 #include "../../memory/DataSetItem.h"
48 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
49 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
50 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
51 #include "../../qt/widgets/srs/SRSManagerDialog.h"
52 #include "../../qt/widgets/utils/FileDialog.h"
53 #include "../../srs/SpatialReferenceSystemManager.h"
54 #include "../Exception.h"
55 #include "../BufferMemory.h"
56 #include "BufferDialog.h"
57 #include "../BufferOp.h"
58 #include "../BufferQuery.h"
59 #include "ui_BufferDialogForm.h"
60 #include "Utils.h"
61 
62 // Qt
63 #include <QFileDialog>
64 #include <QList>
65 #include <QListWidget>
66 #include <QListWidgetItem>
67 #include <QMessageBox>
68 #include <QSize>
69 
70 // STL
71 #include <map>
72 
73 // BOOST
74 #include <boost/algorithm/string.hpp>
75 #include <boost/filesystem.hpp>
76 #include <boost/lexical_cast.hpp>
77 #include <boost/uuid/random_generator.hpp>
78 #include <boost/uuid/uuid_io.hpp>
79 
80 te::vp::BufferDialog::BufferDialog(QWidget* parent, Qt::WindowFlags f)
81  : QDialog(parent, f),
82  m_ui(new Ui::BufferDialogForm),
83  m_layers(std::list<te::map::AbstractLayerPtr>()),
84  m_selectedLayer(nullptr)
85 {
86 // add controls
87  m_ui->setupUi(this);
88 
89 // add icons
90  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme("vp-buffer-hint").pixmap(112,48));
91 
92  QSize iconSize(96, 48);
93 
94  m_ui->m_withoutBoundRadioButton->setIconSize(iconSize);
95  m_ui->m_withoutBoundRadioButton->setIcon(QIcon::fromTheme("buffer-without-boundaries"));
96 
97  m_ui->m_withBoundRadioButton->setIconSize(iconSize);
98  m_ui->m_withBoundRadioButton->setIcon(QIcon::fromTheme("buffer-with-boundaries"));
99 
100  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer-inside-outside").pixmap(150,60));
101  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
102 
103 //add controls
104  m_ui->m_fixedDistanceLineEdit->setEnabled(true);
105  m_ui->m_fixedDistanceLineEdit->setValidator(new QDoubleValidator(this));
106 
108 
109 //signals
110  connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLayerComboBoxChanged(int)));
111  connect(m_ui->m_fixedAtRadioButton, SIGNAL(toggled(bool)), this, SLOT(onFixedDistanceToggled()));
112  connect(m_ui->m_srsToolButton, SIGNAL(clicked()), this, SLOT(onSrsToolButtonClicked()));
113  connect(m_ui->m_fromAttRadioButton, SIGNAL(toggled(bool)), this, SLOT(onAttDistanceToggled()));
114  connect(m_ui->m_ruleInOutRadioButton, SIGNAL(toggled(bool)), this, SLOT(onRuleInOutToggled()));
115  connect(m_ui->m_ruleOnlyOutRadioButton, SIGNAL(toggled(bool)), this, SLOT(onRuleOutToggled()));
116  connect(m_ui->m_ruleOnlyInRadioButton, SIGNAL(toggled(bool)), this, SLOT(onRuleInToggled()));
117  connect(m_ui->m_withoutBoundRadioButton, SIGNAL(toggled(bool)), this, SLOT(onWithoutBoundToggled()));
118  connect(m_ui->m_withBoundRadioButton, SIGNAL(toggled(bool)), this, SLOT(onWithBoundToggled()));
119 
120  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
121  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
122 
123  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
124  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
125 
126  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
127  m_ui->m_helpPushButton->setPageReference("plugins/vp/vp_buffer.html");
128 }
129 
131 
132 void te::vp::BufferDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
133 {
134  m_layers = layers;
135 
136  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
137 
138  while(it != m_layers.end())
139  {
140  std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
141  if(dsType.get() && dsType->hasGeom())
142  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
143  ++it;
144  }
145 }
146 
148 {
149  for(int i=1; i <= 10; ++i)
150  m_ui->m_levelsNumComboBox->addItem(QString::number(i));
151 }
152 
153 void te::vp::BufferDialog::setAttributesForDistance(std::vector<te::dt::Property*> properties)
154 {
155  m_ui->m_fromAttDistanceComboBox->clear();
156 
157  for(std::size_t i = 0; i < properties.size(); ++i)
158  {
159  if(properties[i]->getType() == te::dt::CDOUBLE_TYPE ||
160  properties[i]->getType() == te::dt::CFLOAT_TYPE ||
161  properties[i]->getType() == te::dt::CINT16_TYPE ||
162  properties[i]->getType() == te::dt::CINT32_TYPE ||
163  properties[i]->getType() == te::dt::DOUBLE_TYPE ||
164  properties[i]->getType() == te::dt::INT16_TYPE ||
165  properties[i]->getType() == te::dt::INT32_TYPE ||
166  properties[i]->getType() == te::dt::INT64_TYPE ||
167  properties[i]->getType() == te::dt::FLOAT_TYPE ||
168  properties[i]->getType() == te::dt::UINT16_TYPE ||
169  properties[i]->getType() == te::dt::UINT32_TYPE ||
170  properties[i]->getType() == te::dt::UINT64_TYPE)
171  m_ui->m_fromAttDistanceComboBox->addItem(properties[i]->getName().c_str());
172  }
173 
174  if(m_ui->m_fromAttDistanceComboBox->count() > 0)
175  {
176  m_ui->m_fromAttRadioButton->setEnabled(true);
177  }
178  else
179  m_ui->m_fromAttRadioButton->setEnabled(false);
180 }
181 
183 {
184  if(m_ui->m_ruleInOutRadioButton->isChecked())
185  return te::vp::INSIDE_OUTSIDE;
186  else if(m_ui->m_ruleOnlyOutRadioButton->isChecked())
187  return te::vp::ONLY_OUTSIDE;
188  else
189  return te::vp::ONLY_INSIDE;
190 }
191 
193 {
194  if(m_ui->m_withoutBoundRadioButton->isChecked())
195  return te::vp::DISSOLVE;
196  else
197  return te::vp::NOT_DISSOLVE;
198 }
199 
201 {
202  return m_outputLayer;
203 }
204 
206 {
207  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
208  std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
209 
210  while(it != m_layers.end())
211  {
212  if(layerID == it->get()->getId())
213  {
214  te::map::AbstractLayerPtr selectedLayer = it->get();
215  m_selectedLayer = selectedLayer;
216  std::unique_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
217 
218  if(schema->size() == 0)
219  return;
220 
222  m_properties.clear();
223 
224  const std::vector<te::dt::Property*>& properties = schema->getProperties();
225  te::common::Clone(properties, m_properties);
226 
228 
229  te::map::DataSetLayer* dsLayer = dynamic_cast<te::map::DataSetLayer*>(m_selectedLayer.get());
230  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(dsLayer->getDataSourceId(), true);
231  te::da::DataSetType* dsType = te::da::GetDataSetType(dsLayer->getDataSetName(), inDataSource->getId());
232  std::unique_ptr<te::gm::GeometryProperty>geomProp(te::da::GetFirstGeomProperty(dsType));
233 
234  te::gm::GeomType gmType = geomProp->getGeometryType();
235 
236  if(gmType == te::gm::PolygonType || gmType == te::gm::MultiPolygonType)
237  {
238  m_ui->m_ruleInOutRadioButton->setEnabled(true);
239  m_ui->m_ruleOnlyInRadioButton->setEnabled(true);
240  m_ui->m_ruleOnlyOutRadioButton->setEnabled(true);
241 
242  m_ui->m_ruleInOutRadioButton->setChecked(true);
243 
244  m_ui->m_okPushButton->setEnabled(true);
245  }
246  else
247  if(gmType == te::gm::LineStringType || gmType == te::gm::MultiLineStringType)
248  {
249  m_ui->m_ruleInOutRadioButton->setDisabled(true);
250  m_ui->m_ruleOnlyInRadioButton->setDisabled(true);
251 
252  m_ui->m_ruleOnlyOutRadioButton->setEnabled(true);
253  m_ui->m_ruleOnlyOutRadioButton->setChecked(true);
255 
256  m_ui->m_okPushButton->setEnabled(true);
257  }
258  else
259  if(gmType == te::gm::PointType || gmType == te::gm::MultiPointType)
260  {
261  m_ui->m_ruleInOutRadioButton->setDisabled(true);
262  m_ui->m_ruleOnlyInRadioButton->setDisabled(true);
263 
264  m_ui->m_ruleOnlyOutRadioButton->setEnabled(true);
265  m_ui->m_ruleOnlyOutRadioButton->setChecked(true);
267 
268  m_ui->m_okPushButton->setEnabled(true);
269  }
270  else
271  {
272  QMessageBox::information(this, "Buffer", "The geometry type ("+ QString(te::gm::Geometry::getGeomTypeString(geomProp->getGeometryType()).c_str()) +") is not supported to execute this operation.");
273  m_ui->m_okPushButton->setDisabled(true);
274  return;
275  }
276 
277  int srid = dsLayer->getSRID();
278  if(srid > 0)
279  {
280  m_ui->m_layerSRIDLabel->setText(te::srs::SpatialReferenceSystemManager::getInstance().getName(srid).c_str());
281  m_ui->m_resSRIDLabel->setText(te::srs::SpatialReferenceSystemManager::getInstance().getName(srid).c_str());
282 
284  std::string unitSymbol = unitPtr.get()->getSymbol();
285  m_ui->m_unitLabel->setText(unitSymbol.c_str());
286 
287  m_newSRID = srid;
288  }
289  else
290  {
291  m_ui->m_layerSRIDLabel->setText("No SRS defined");
292  m_ui->m_resSRIDLabel->setText("No SRS defined");
293  }
294 
295  return;
296  }
297  ++it;
298  }
299 }
300 
302 {
303  m_ui->m_fixedDistanceLineEdit->setEnabled(true);
304  m_ui->m_fromAttDistanceComboBox->setEnabled(false);
305 }
306 
308 {
309  m_ui->m_fromAttDistanceComboBox->setEnabled(true);
310  m_ui->m_fixedDistanceLineEdit->setEnabled(false);
311 }
312 
314 {
315  te::qt::widgets::SRSManagerDialog srsDialog(this);
316  srsDialog.setWindowTitle(tr("Choose the SRS"));
317 
318  if(srsDialog.exec() == QDialog::Rejected)
319  return;
320 
321  m_newSRID = srsDialog.getSelectedSRS().first;
322 
323  if (m_newSRID <= 0)
324  {
325  m_ui->m_resSRIDLabel->setText("No SRS defined");
326  }
327  else
328  {
330  m_ui->m_resSRIDLabel->setText(name.c_str());
331 
333  std::string unitSymbol = unitPtr.get()->getSymbol();
334  m_ui->m_unitLabel->setText(unitSymbol.c_str());
335  }
336 }
337 
339 {
340  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer-inside-outside").pixmap(150,60));
341 }
342 
344 {
345  te::gm::GeometryProperty* geomProp = nullptr;
346 
347  for(std::size_t i = 0; i < m_properties.size(); ++i)
348  {
349  int propertyType = m_properties[i]->getType();
350 
351  if(propertyType == te::dt::GEOMETRY_TYPE)
352  geomProp = static_cast<te::gm::GeometryProperty*>(m_properties[i]);
353  }
354 
355  int geomType = geomProp->getGeometryType();
356 
357  if(geomType == te::gm::PolygonType || geomType == te::gm::MultiPolygonType)
358  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer_only-outside").pixmap(150,60));
359  else
360  if(geomType == te::gm::LineStringType || geomType == te::gm::MultiLineStringType)
361  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer-line-outside").pixmap(150,60));
362  else
363  if(geomType == te::gm::PointType || geomType == te::gm::MultiPointType)
364  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer-point-outside").pixmap(150,60));
365 }
366 
368 {
369  m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme("buffer-only-inside").pixmap(150,60));
370 }
371 
373 {
374  m_ui->m_copyColumnsCheckBox->setChecked(false);
375  m_ui->m_copyColumnsCheckBox->setEnabled(false);
376 }
377 
379 {
380  m_ui->m_copyColumnsCheckBox->setEnabled(true);
381 }
382 
384 {
385  m_ui->m_newLayerNameLineEdit->clear();
386  m_ui->m_newLayerNameLineEdit->setEnabled(true);
388  dlg.exec();
389 
390  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
391 
392  if(dsPtrList.empty())
393  return;
394 
395  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
396 
397  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
398 
399  m_outputDatasource = *it;
400 
401  m_toFile = false;
402 }
403 
405 {
406  m_ui->m_newLayerNameLineEdit->clear();
407  m_ui->m_repositoryLineEdit->clear();
408 
410 
411  try {
412  fileDialog.exec();
413  }
414  catch (te::common::Exception& ex) {
415  QMessageBox::warning(this, tr("File information"), ex.what());
416  return;
417  }
418 
419  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
420  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
421 
422  m_toFile = true;
423  m_ui->m_newLayerNameLineEdit->setEnabled(false);
424 }
425 
427 {
428  if(m_ui->m_layersComboBox->currentText().isEmpty())
429  {
430  QMessageBox::information(this, "Buffer", "Select an input layer.");
431  return;
432  }
433 
434  // Checking consistency of the input layer where the buffer will executed
435  te::map::DataSetLayer* dsLayer = dynamic_cast<te::map::DataSetLayer*>(m_selectedLayer.get());
436  if(!dsLayer)
437  {
438  QMessageBox::information(this, "Buffer", "Can not execute this operation on this type of layer.");
439  return;
440  }
441 
442  const te::da::ObjectIdSet* oidSet = nullptr;
443 
444  if(m_ui->m_onlySelectedCheckBox->isChecked())
445  {
446  oidSet = m_selectedLayer->getSelected();
447  if(!oidSet)
448  {
449  QMessageBox::information(this, "Buffer", "Select the layer objects to perform the buffer operation.");
450  return;
451  }
452  }
453 
454 
455  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(dsLayer->getDataSourceId(), true);
456  if (!inDataSource.get())
457  {
458  QMessageBox::information(this, "Buffer", "The selected input data source can not be accessed.");
459  return;
460  }
461 
462  // Check consistency of buffer parameters
463  double distance;
464  int attributePosition = -1;
465 
466  if(m_ui->m_fixedAtRadioButton->isChecked())
467  {
468  distance = m_ui->m_fixedDistanceLineEdit->text().toDouble();
469  if (distance <= 0)
470  {
471  QMessageBox::information(this, "Buffer", "Fixed distance value should be greater than 0.");
472  return;
473  }
474  }
475  else
476  {
477  distance = 0;
478  std::string propDistance;
479  int i = m_ui->m_fromAttDistanceComboBox->currentIndex();
480  propDistance = m_ui->m_fromAttDistanceComboBox->itemText(i).toUtf8().data();
481 
482  std::unique_ptr<const te::map::LayerSchema> schema(m_selectedLayer->getSchema());
483  attributePosition = static_cast<int>(te::da::GetPropertyPos(schema.get(), propDistance));
484  }
485 
486  // Verify if the projection is lat/long
488  {
489  int reply = QMessageBox::question(this, tr("Buffer"),
490  tr("The buffer operation will be calculated with Geographic SRS. Would you like to continue?"),
491  QMessageBox::No, QMessageBox::Yes);
492 
493  if(reply == QMessageBox::No)
494  {
495  return;
496  }
497  }
498 
499  // Checking consistency of output paramenters
500  if(m_ui->m_repositoryLineEdit->text().isEmpty())
501  {
502  QMessageBox::information(this, "Buffer", "Select a repository for the resulting layer.");
503 
504  return;
505  }
506 
507  if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
508  {
509  QMessageBox::information(this, "Buffer", "Define a name for the resulting layer.");
510  return;
511  }
512 
513  int bufferPolygonRule = getPolygonRule();
514  int bufferBoundariesRule = getBoundariesRule();
515  bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
516  int levels = m_ui->m_levelsNumComboBox->currentText().toInt();
517  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
518 
519  //progress
521 
522  try
523  {
524  bool res;
525 
526  if(m_toFile)
527  {
528  boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toUtf8().data());
529 
530  if(te::core::FileSystem::exists(uri.string()))
531  {
532  QMessageBox::information(this, "Buffer", "Output file already exists. Remove it or select a new name and try again.");
533  return;
534  }
535 
536  std::size_t idx = outputdataset.find(".");
537  if(idx != std::string::npos)
538  outputdataset = outputdataset.substr(0,idx);
539 
540  std::string dsinfo("file://");
541  dsinfo += uri.string();
542 
543  te::da::DataSourcePtr dsOGR(te::da::DataSourceFactory::make("OGR", dsinfo).release());
544  dsOGR->open();
545 
546  if(dsOGR->dataSetExists(outputdataset))
547  {
548  QMessageBox::information(this, "Buffer", "There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
549  return;
550  }
551 
552  std::unique_ptr<te::da::DataSetTypeConverter> converter(new te::da::DataSetTypeConverter(dsLayer->getSchema().get(), dsOGR->getCapabilities(), dsOGR->getEncoding()));
553 
554  te::da::AssociateDataSetTypeConverterSRID(converter.get(), dsLayer->getSRID());
555 
556  this->setCursor(Qt::WaitCursor);
557 
558  te::vp::BufferOp* bufferOp = nullptr;
559 
560  // select a strategy based on the capabilities of the input datasource
561  const te::da::DataSourceCapabilities dsCapabilities = inDataSource->getCapabilities();
562 
563  if(dsCapabilities.supportsPreparedQueryAPI() && dsCapabilities.getQueryCapabilities().supportsSpatialSQLDialect())
564  {
565  bufferOp = new te::vp::BufferQuery();
566  }
567  else
568  {
569  bufferOp = new te::vp::BufferMemory();
570  }
571 
572  bufferOp->setInput(inDataSource, dsLayer->getDataSetName(), std::move(converter), oidSet);
573  bufferOp->setOutput(dsOGR, outputdataset);
574  bufferOp->setParams(distance, m_newSRID, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, attributePosition);
575 
576  if (!bufferOp->paramsAreValid())
577  res = false;
578  else
579  res = bufferOp->run();
580 
581  if(!res)
582  {
583  dsOGR->close();
584  QMessageBox::information(this, "Buffer", "Error: could not generate the buffer.");
585  }
586  dsOGR->close();
587 
588  delete bufferOp;
589 
590  // let's include the new datasource in the managers
591  boost::uuids::basic_random_generator<boost::mt19937> gen;
592  boost::uuids::uuid u = gen();
593  std::string id = boost::uuids::to_string(u);
594 
596  ds->setConnInfo(dsinfo);
597  ds->setTitle(uri.stem().string());
598  ds->setAccessDriver("OGR");
599  ds->setType("OGR");
600  ds->setDescription(uri.string());
601  ds->setId(id);
602 
603  te::da::DataSourcePtr newds = te::da::DataSourceManager::getInstance().get(id, "OGR", ds->getConnInfo());
604  newds->open();
607  }
608  else
609  {
611  if (!aux)
612  {
613  QMessageBox::information(this, "Buffer", "The selected output datasource can not be accessed.");
614  return;
615  }
616  if (aux->dataSetExists(outputdataset))
617  {
618  QMessageBox::information(this, "Buffer", "Dataset already exists. Remove it or select a new name and try again. ");
619  return;
620  }
621  this->setCursor(Qt::WaitCursor);
622 
623 
624  std::unique_ptr<te::da::DataSetTypeConverter> converter(new te::da::DataSetTypeConverter(dsLayer->getSchema().get(), aux->getCapabilities(), aux->getEncoding()));
625 
626  te::da::AssociateDataSetTypeConverterSRID(converter.get(), dsLayer->getSRID());
627 
628 
629  te::vp::BufferOp* bufferOp = nullptr;
630 
631  // select a strategy based on the capabilities of the input datasource
632  const te::da::DataSourceCapabilities dsCapabilities = inDataSource->getCapabilities();
633 
634  if(dsCapabilities.supportsPreparedQueryAPI() && dsCapabilities.getQueryCapabilities().supportsSpatialSQLDialect())
635  {
636  bufferOp = new te::vp::BufferQuery();
637  }
638  else
639  {
640  bufferOp = new te::vp::BufferMemory();
641  }
642 
643  bufferOp->setInput(inDataSource, dsLayer->getDataSetName(), std::move(converter), oidSet);
644  bufferOp->setOutput(aux, outputdataset);
645  bufferOp->setParams(distance, m_newSRID, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, attributePosition);
646 
647  if (!bufferOp->paramsAreValid())
648  res = false;
649  else
650  res = bufferOp->run();
651 
652  if(!res)
653  {
654  this->setCursor(Qt::ArrowCursor);
655  QMessageBox::information(this, "Buffer", "Error: could not generate the buffer.");
656  reject();
657  }
658 
659  delete bufferOp;
660  }
661 
662  // creating a layer for the result
664 
666 
667  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
668  m_outputLayer = converter(dt);
669  }
670  catch(const std::exception& e)
671  {
672  this->setCursor(Qt::ArrowCursor);
673  QMessageBox::information(this, "Buffer", e.what());
674 
675  std::string str = "Vector Processing - Buffer - ";
676  str += e.what();
677  TE_LOG_ERROR(str);
678 
679  return;
680  }
681 
682  this->setCursor(Qt::ArrowCursor);
683  accept();
684 }
685 
687 {
688  reject();
689 }
te::map::AbstractLayerPtr m_selectedLayer
Layer used for buffer.
Definition: BufferDialog.h:120
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setAttributesForDistance(std::vector< te::dt::Property * > properties)
std::vector< te::dt::Property * > m_properties
Properties related to the selected Layer.
Definition: BufferDialog.h:122
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Geometric property.
BufferDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Defines a component for choose a file.
Definition: FileDialog.h:52
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
Definition: FileSystem.cpp:142
virtual bool run()=0
It executes the operation.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
std::unique_ptr< Ui::BufferDialogForm > m_ui
Definition: BufferDialog.h:116
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
The boundaries between buffers will not be dissolved.
An abstract class to compute the buffer memory and buffer query operation.
Definition: BufferOp.h:61
A dialog buffer operation.
A class that models the description of a dataset.
Definition: DataSetType.h:72
void onLayerComboBoxChanged(int index)
virtual const char * what() const
It outputs the exception message.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
void setParams(const double &distance, const int &newSrid, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool &copyInputColumns, const int &levels, const int &attributePosition=-1)
It sets the input parameters that will be consumed to execute the operation.
Definition: BufferOp.cpp:62
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::dt::Date ds(2010, 01, 01)
const QueryCapabilities & getQueryCapabilities() const
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
Definition: BufferDialog.h:117
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
It sets the input data will be calculated.
Definition: BufferOp.cpp:51
int m_newSRID
newSRID to compure buffer Area.
Definition: BufferDialog.h:123
void onTargetFileToolButtonPressed()
An converter for DataSetType.
The buffer is generated only outside of the polygons.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
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 setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
The buffer is generated only inside of the polygons.
URI C++ Library.
Definition: Attributes.h:37
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
Definition: BufferDialog.h:119
virtual bool paramsAreValid()
It verifies if the parameters are valid.
Definition: BufferOp.cpp:85
bool IsProjectionLatLong(const int &srid)
A concrete class to compute the buffer operation.
Definition: BufferQuery.h:61
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the output parameters that will be used to persist operation result.
Definition: BufferOp.cpp:79
bool supportsSpatialSQLDialect() const
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
The buffer is generated Inside and outside of the polygons.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
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.
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
Definition: BufferDialog.h:121
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Definition: Logger.h:337
A class that represents a data source component.
void onTargetDatasourceToolButtonPressed()
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
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
static std::string getGeomTypeString(const int &gId)
It returns the TerraLib geometry type string given a type id.
A dialog used to build a SRSManagerDialog element.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::map::AbstractLayerPtr getLayer()
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
Definition: STLUtils.h:237
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
A concrete class to compute the buffer operation.
Definition: BufferMemory.h:62
virtual const std::string & getDataSourceId() const
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
The boundaries between buffers will be dissolved.