27 #include "../../core/logger/Logger.h" 28 #include "../../common/progress/ProgressManager.h" 29 #include "../../core/translator/Translator.h" 30 #include "../../common/STLUtils.h" 31 #include "../../dataaccess/datasource/DataSource.h" 32 #include "../../dataaccess/utils/Utils.h" 33 #include "../../geometry/GeometryProperty.h" 34 #include "../../maptools/DataSetLayer.h" 35 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 36 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 37 #include "../core/BayesGlobalOperation.h" 38 #include "../core/BayesParams.h" 39 #include "../core/Utils.h" 40 #include "../Exception.h" 43 #include "ui_BayesGlobalDialogForm.h" 46 #include <QFileDialog> 48 #include <QMessageBox> 55 #include <boost/filesystem.hpp> 60 te::sa::BayesGlobalDialog::BayesGlobalDialog(
QWidget* parent, Qt::WindowFlags f)
62 m_ui(new
Ui::BayesGlobalDialogForm)
70 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-bayesglobal-hint").pixmap(112,48));
71 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
74 connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(
int)),
this, SLOT(onInputLayerComboBoxActivated(
int)));
75 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
76 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
77 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
80 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
81 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_bayesglobal.html");
88 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
90 while(it != layers.end())
96 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
100 if(dsLayer && dsType->hasGeom())
101 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
108 if(
m_ui->m_inputLayerComboBox->count() > 0)
119 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
123 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
125 std::vector<te::dt::Property*> propVec = dsType->getProperties();
127 m_ui->m_attrEventComboBox->clear();
128 m_ui->m_attrPopComboBox->clear();
130 for(std::size_t t = 0; t < propVec.size(); ++t)
132 int dataType = propVec[t]->getType();
139 m_ui->m_attrEventComboBox->addItem(propVec[t]->getName().c_str(), dataType);
140 m_ui->m_attrPopComboBox->addItem(propVec[t]->getName().c_str(), dataType);
148 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
150 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
154 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
156 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
161 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
164 std::unique_ptr<te::da::DataSetType> dataSetType = l->getSchema();
165 std::unique_ptr<te::da::DataSet> dataSet = l->getData();
168 std::string dataSetName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
170 std::size_t idx = dataSetName.find(
".");
171 if (idx != std::string::npos)
172 dataSetName=dataSetName.substr(0,idx);
187 inParams->m_ds = std::move(dataSet);
188 inParams->m_dsType = std::move(dataSetType);
189 inParams->m_eventAttrName =
m_ui->m_attrEventComboBox->currentText().toUtf8().data();
190 inParams->m_populationAttrName =
m_ui->m_attrPopComboBox->currentText().toUtf8().data();
191 inParams->m_rate =
m_ui->m_rateComboBox->currentText().toDouble();
195 outParams->
m_ds = outputDataSource;
201 QApplication::setOverrideCursor(Qt::WaitCursor);
211 catch(
const std::exception& e)
213 QMessageBox::warning(
this, tr(
"Warning"), e.what());
215 QApplication::restoreOverrideCursor();
221 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error.Global Bayes not calculated."));
223 QApplication::restoreOverrideCursor();
228 QApplication::restoreOverrideCursor();
241 m_ui->m_newLayerNameLineEdit->clear();
242 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
247 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
249 if(dsPtrList.empty())
252 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
254 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
263 m_ui->m_newLayerNameLineEdit->clear();
264 m_ui->m_repositoryLineEdit->clear();
266 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
268 if (fileName.isEmpty())
271 boost::filesystem::path outfile(fileName.toUtf8().data());
273 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
275 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
277 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
284 m_ui->m_rateComboBox->clear();
286 m_ui->m_rateComboBox->addItem(
"1");
287 m_ui->m_rateComboBox->addItem(
"10");
288 m_ui->m_rateComboBox->addItem(
"100");
289 m_ui->m_rateComboBox->addItem(
"1000");
290 m_ui->m_rateComboBox->addItem(
"10000");
291 m_ui->m_rateComboBox->addItem(
"100000");
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void fillRateCorrection()
Class that represents the Bayes output parameters.
te::da::DataSourceInfoPtr m_outputDatasource
void onTargetFileToolButtonPressed()
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
boost::shared_ptr< DataSource > DataSourcePtr
TESAEXPORT te::da::DataSourcePtr CreateOGRDataSource(std::string repository)
A dialog to calculate the global empirical bayes of a dataset.
void execute()
Function to execute the bayes operation.
te::map::AbstractLayerPtr getOutputLayer()
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
std::string m_outputDataSetName
Attribute that defines the output dataset name.
void onInputLayerComboBoxActivated(int index)
TESAEXPORT void CreateBayesGrouping(te::map::AbstractLayerPtr layer)
std::unique_ptr< Ui::BayesGlobalDialogForm > m_ui
void onTargetDatasourceToolButtonPressed()
Utility functions for the data access module.
Class used to execute the bayes global operations.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
te::da::DataSourcePtr m_ds
Pointer to the output datasource.
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
void setParameters(te::sa::BayesInputParams *inParams, te::sa::BayesOutputParams *outParams)
void onOkPushButtonClicked()
A layer with reference to a dataset.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr