27 #include "../../core/filesystem/FileSystem.h" 28 #include "../../common/StringUtils.h" 29 #include "../../dataaccess/dataset/DataSetAdapter.h" 30 #include "../../dataaccess/dataset/DataSetTypeConverter.h" 31 #include "../../dataaccess/dataset/ObjectIdSet.h" 32 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 33 #include "../../dataaccess/datasource/DataSourceManager.h" 34 #include "../../dataaccess/datasource/DataSourceFactory.h" 35 #include "../../dataaccess/query/And.h" 36 #include "../../dataaccess/query/DataSetName.h" 37 #include "../../dataaccess/query/Expression.h" 38 #include "../../dataaccess/query/Field.h" 39 #include "../../dataaccess/query/Fields.h" 40 #include "../../dataaccess/query/From.h" 41 #include "../../dataaccess/query/FromItem.h" 42 #include "../../dataaccess/query/LiteralInt32.h" 43 #include "../../dataaccess/query/PropertyName.h" 44 #include "../../dataaccess/query/ST_SetSRID.h" 45 #include "../../dataaccess/query/ST_Transform.h" 46 #include "../../dataaccess/query/Where.h" 47 #include "../../dataaccess/utils/Utils.h" 48 #include "../../datatype/SimpleData.h" 49 #include "../../geometry/GeometryProperty.h" 50 #include "../../maptools/QueryLayer.h" 51 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 52 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 53 #include "../../qt/widgets/utils/DoubleListWidget.h" 54 #include "../../qt/widgets/utils/FileDialog.h" 56 #include "../ComplexData.h" 60 #include "ui_UnionDialogForm.h" 63 #include <QFileDialog> 64 #include <QGridLayout> 65 #include <QMessageBox> 68 #include <boost/filesystem.hpp> 69 #include <boost/uuid/random_generator.hpp> 70 #include <boost/uuid/uuid_io.hpp> 74 te::vp::UnionDialog::UnionDialog(
QWidget* parent, Qt::WindowFlags f)
76 m_ui(new
Ui::UnionDialogForm),
82 m_ui->m_imgLabel->setPixmap(
83 QIcon::fromTheme(
"vp-union-hint").pixmap(112, 48));
85 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
89 m_ui->m_specificParamsTabWidget->widget(0)));
90 m_doubleListWidget->setLeftLabel(
"");
91 m_doubleListWidget->setRightLabel(
"");
94 new QGridLayout(m_ui->m_specificParamsTabWidget->widget(0));
95 layout->addWidget(m_doubleListWidget.get());
96 layout->setContentsMargins(0, 0, 0, 0);
98 QSize iconSize(96, 48);
100 m_ui->m_singleRadioButton->setIconSize(iconSize);
101 m_ui->m_singleRadioButton->setIcon(QIcon::fromTheme(
"vp-single-objects"));
103 m_ui->m_multiRadioButton->setIconSize(iconSize);
104 m_ui->m_multiRadioButton->setIcon(QIcon::fromTheme(
"vp-multi-objects"));
106 connect(m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onFirstLayerComboBoxChanged(
int)));
108 connect(m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onSecondLayerComboBoxChanged(
int)));
110 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
112 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
114 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
116 connect(m_ui->m_cancelPushButton, SIGNAL(clicked()),
this, SLOT(onCancelPushButtonClicked()));
118 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
119 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_union.html");
126 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
128 while (it != layers.end())
130 std::unique_ptr<te::da::DataSetType> dsType =
131 std::move(it->get()->getSchema());
133 if (dsType->hasGeom())
153 std::vector<std::pair<std::string, std::string> >
157 std::vector<std::pair<std::string, std::string> > result;
159 for (std::size_t i = 0; i < outVec.size(); ++i)
161 std::vector<std::string> tok;
164 std::pair<std::string, std::string>
p;
185 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
187 disconnect(
m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
192 m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()),
193 QVariant::fromValue(*it));
197 connect(
m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
200 QVariant varLayer =
m_ui->m_firstLayerComboBox->itemData(
201 m_ui->m_firstLayerComboBox->currentIndex(), Qt::UserRole);
210 int currIndex =
m_ui->m_firstLayerComboBox->currentIndex();
212 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
214 disconnect(
m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(
int)),
219 m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()),
220 QVariant::fromValue(*it));
224 m_ui->m_secondLayerComboBox->removeItem(currIndex);
226 connect(
m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
229 QVariant varLayer =
m_ui->m_secondLayerComboBox->itemData(
230 m_ui->m_secondLayerComboBox->currentIndex(), Qt::UserRole);
239 std::vector<std::string> inputValues;
241 std::unique_ptr<te::da::DataSetType> firstSchema;
242 std::unique_ptr<te::da::DataSetType> secondSchema;
254 std::vector<te::dt::Property*> firstProps = firstSchema->getProperties();
255 for (std::size_t i = 0; i < firstProps.size(); ++i)
259 std::string name = firstSchema->getTitle();
262 name = firstSchema->getName();
264 inputValues.push_back(name +
": " + firstProps[i]->getName());
268 std::vector<te::dt::Property*> secondProps = secondSchema->getProperties();
269 for (std::size_t i = 0; i < secondProps.size(); ++i)
273 std::string name = secondSchema->getTitle();
276 name = secondSchema->getName();
278 inputValues.push_back(secondSchema->getTitle() +
": " +
279 secondProps[i]->getName());
288 QVariant varLayer =
m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole);
291 m_ui->m_secondLayerComboBox->clear();
303 m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole);
314 m_ui->m_newLayerNameLineEdit->clear();
315 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
319 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
321 if (dsPtrList.empty())
324 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
326 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
335 m_ui->m_newLayerNameLineEdit->clear();
336 m_ui->m_repositoryLineEdit->clear();
344 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
348 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
349 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
352 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
357 if(
m_ui->m_firstLayerComboBox->currentText().isEmpty() ||
358 m_ui->m_secondLayerComboBox->currentText().isEmpty())
360 QMessageBox::information(
361 this, tr(
"Union"), tr(
"It is necessary at least two layer to operat!"));
366 if (
m_ui->m_repositoryLineEdit->text().isEmpty())
368 QMessageBox::information(
369 this, tr(
"Union"), tr(
"Select a repository for the resulting layer!"));
374 if (
m_ui->m_newLayerNameLineEdit->text().isEmpty())
376 QMessageBox::information(
this, tr(
"Union"),
377 tr(
"Define a name for the resulting layer!"));
384 if (firstSrid <= 0 || secondSrid <= 0)
386 QMessageBox::information(
this, tr(
"Union"),
387 tr(
"All layers must have SRID!"));
391 std::string outputdataset =
392 m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
403 std::unique_ptr<te::da::DataSetTypeConverter> firstConverter(
405 firstSource->getCapabilities(),
406 firstSource->getEncoding()));
411 std::unique_ptr<te::da::DataSetTypeConverter> secondConverter(
413 secondSource->getCapabilities(),
414 secondSource->getEncoding()));
429 std::unique_ptr<te::da::DataSet> firstDs(firstAdapter);
430 std::unique_ptr<te::da::DataSet> secondDs(secondAdapter);
444 std::vector<te::vp::InputParams> params;
445 params.push_back(inputParam);
446 params.push_back(mergeParam);
450 std::vector<std::pair<std::string, std::string> > >(
453 std::map<std::string, te::dt::AbstractData*> specificParams;
454 specificParams[
"ATTRIBUTES"] = attrs;
456 specificParams[
"IS_COLLECTION"] =
458 !
m_ui->m_singleRadioButton->isChecked());
461 aParams->setInputParams(params);
462 aParams->setOutputDataSetName(outputdataset);
463 aParams->setSpecificParams(specificParams);
466 std::string ogrDsinfo(
"file://");
467 boost::filesystem::path ogrUri;
471 ogrUri =
m_ui->m_repositoryLineEdit->text().toUtf8().data();
475 QMessageBox::information(
this, tr(
"Union"),
476 tr(
"Output file already exists. Remove it or " 477 "select a new name and try again."));
481 std::size_t idx = outputdataset.find(
".");
482 if (idx != std::string::npos)
483 outputdataset = outputdataset.substr(0, idx);
485 aParams->setOutputDataSetName(outputdataset);
487 ogrDsinfo += ogrUri.string();
493 if (auxSource->dataSetExists(outputdataset))
495 QMessageBox::information(
497 tr(
"There is already a dataset with the requested name in the " 498 "output data source. Remove it or select a new name and try " 508 QMessageBox::information(
510 tr(
"The selected output datasource can not be accessed."));
513 if (auxSource->dataSetExists(outputdataset))
515 QMessageBox::information(
this, tr(
"Union"),
516 tr(
"Dataset already exists. Remove it or " 517 "select a new name and try again."));
522 aParams->setOutputDataSource(auxSource);
532 boost::uuids::basic_random_generator<boost::mt19937> gen;
533 boost::uuids::uuid u = gen();
534 std::string
id = boost::uuids::to_string(u);
537 ds->setConnInfo(ogrDsinfo);
538 ds->setTitle(ogrUri.stem().string());
539 ds->setAccessDriver(
"OGR");
541 ds->setDescription(ogrUri.string());
559 outDataSource->getDataSetType(outputdataset).release());
564 QMessageBox::warning(
this, tr(
"Union"), e.
what());
567 catch (
const std::exception& e)
569 QMessageBox::warning(
this, tr(
"Union"), e.what());
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
te::map::AbstractLayerPtr m_firstSelectedLayer
Input layer selected.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
void onOkPushButtonClicked()
boost::shared_ptr< DataSource > DataSourcePtr
bool m_toFile
The result is in a file?
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A class that models the description of a dataset.
std::vector< std::pair< std::string, std::string > > getSelectedProperties()
virtual const char * what() const
It outputs the exception message.
void onTargetDatasourceToolButtonPressed()
static te::dt::Date ds(2010, 01, 01)
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void updateFirstLayerComboBox()
void onSecondLayerComboBoxChanged(int index)
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.
te::map::AbstractLayerPtr getLayer()
A template for complex data types.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
std::unique_ptr< te::qt::widgets::DoubleListWidget > m_doubleListWidget
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::unique_ptr< Ui::UnionDialogForm > m_ui
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
te::map::AbstractLayerPtr m_secondSelectedLayer
Union layer selected.
void onTargetFileToolButtonPressed()
void onFirstLayerComboBoxChanged(int index)
std::list< te::map::AbstractLayerPtr > m_layers
The vector layers in Layer Explorer.
A class that represents a data source component.
void updateSecondLayerComboBox()
bool executeMemory(te::vp::AlgorithmParams *mainParams)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
A template for atomic data types (integers, floats, strings and others).
void updateDoubleListWidget()
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onCancelPushButtonClicked()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr