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/BayesLocalOperation.h" 38 #include "../core/BayesParams.h" 39 #include "../core/GPMBuilder.h" 40 #include "../core/GPMConstructorAdjacencyStrategy.h" 41 #include "../core/GPMWeightsNoWeightsStrategy.h" 42 #include "../core/SpatialWeightsExchanger.h" 43 #include "../core/Utils.h" 44 #include "../Exception.h" 47 #include "ui_BayesLocalDialogForm.h" 50 #include <QFileDialog> 52 #include <QMessageBox> 59 #include <boost/filesystem.hpp> 63 te::sa::BayesLocalDialog::BayesLocalDialog(
QWidget* parent, Qt::WindowFlags f)
65 m_ui(new
Ui::BayesLocalDialogForm)
73 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-bayeslocal-hint").pixmap(112,48));
74 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
77 connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(
int)),
this, SLOT(onInputLayerComboBoxActivated(
int)));
78 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
79 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
80 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
81 connect(m_ui->m_gpmToolButton, SIGNAL(clicked()),
this, SLOT(onGPMToolButtonClicked()));
84 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
85 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_bayeslocal.html");
92 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
94 while(it != layers.end())
100 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
104 if(dsLayer && dsType->hasGeom())
105 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
112 if(
m_ui->m_inputLayerComboBox->count() > 0)
123 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
127 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
129 std::vector<te::dt::Property*> propVec = dsType->getProperties();
131 m_ui->m_attrEventComboBox->clear();
132 m_ui->m_attrPopComboBox->clear();
133 m_ui->m_attrLinkComboBox->clear();
135 for(std::size_t t = 0; t < propVec.size(); ++t)
137 int dataType = propVec[t]->getType();
144 m_ui->m_attrEventComboBox->addItem(propVec[t]->getName().c_str(), dataType);
145 m_ui->m_attrPopComboBox->addItem(propVec[t]->getName().c_str(), dataType);
148 m_ui->m_attrLinkComboBox->addItem(propVec[t]->getName().c_str(), dataType);
155 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
157 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
161 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
163 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
168 std::unique_ptr<te::sa::GeneralizedProximityMatrix> gpm;
176 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error. GPM not loaded."));
184 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
187 std::unique_ptr<te::da::DataSetType> dataSetType = l->getSchema();
188 std::unique_ptr<te::da::DataSet> dataSet = l->getData();
191 std::string dataSetName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
193 std::size_t idx = dataSetName.find(
".");
194 if (idx != std::string::npos)
195 dataSetName=dataSetName.substr(0,idx);
210 inParams->m_ds = std::move(dataSet);
211 inParams->m_dsType = std::move(dataSetType);
212 inParams->m_eventAttrName =
m_ui->m_attrEventComboBox->currentText().toUtf8().data();
213 inParams->m_populationAttrName =
m_ui->m_attrPopComboBox->currentText().toUtf8().data();
214 inParams->m_rate =
m_ui->m_rateComboBox->currentText().toDouble();
215 inParams->m_gpmAttrLink = gpm->getAttributeName();
216 inParams->m_gpm = std::move(gpm);
220 outParams->
m_ds = outputDataSource;
226 QApplication::setOverrideCursor(Qt::WaitCursor);
236 catch(
const std::exception& e)
238 QMessageBox::warning(
this, tr(
"Warning"), e.what());
240 QApplication::restoreOverrideCursor();
246 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error. Global Bayes not calculated."));
248 QApplication::restoreOverrideCursor();
253 QApplication::restoreOverrideCursor();
266 m_ui->m_newLayerNameLineEdit->clear();
267 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
272 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
274 if(dsPtrList.empty())
277 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
279 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
288 m_ui->m_newLayerNameLineEdit->clear();
289 m_ui->m_repositoryLineEdit->clear();
291 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
293 if (fileName.isEmpty())
296 boost::filesystem::path outfile(fileName.toUtf8().data());
298 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
300 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
302 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
309 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Generalized Proximity Matrix File"),
"", tr(
"GAL Files (*.gal *.GAL);; GWT Files (*.gwt *.GWT)"));
311 if(fileName.isEmpty())
315 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
320 std::string path = fileName.toUtf8().data();
321 std::string dataSetName;
322 std::string attrName;
326 if(dsLayer->getDataSetName() != dataSetName)
328 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected layer."));
332 if(
m_ui->m_attrLinkComboBox->currentText().toUtf8().data() != attrName)
334 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected Attr Link."));
338 m_ui->m_gpmLineEdit->setText(fileName);
343 m_ui->m_rateComboBox->clear();
345 m_ui->m_rateComboBox->addItem(
"1");
346 m_ui->m_rateComboBox->addItem(
"10");
347 m_ui->m_rateComboBox->addItem(
"100");
348 m_ui->m_rateComboBox->addItem(
"1000");
349 m_ui->m_rateComboBox->addItem(
"10000");
350 m_ui->m_rateComboBox->addItem(
"100000");
355 std::unique_ptr<te::sa::GeneralizedProximityMatrix> gpm;
358 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
363 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid selected layer."));
374 if(!
m_ui->m_gpmGroupBox->isChecked())
377 if(QMessageBox::question(
this, tr(
"Spatial Analysis"), tr(
"GPM not selected. Create default GPM?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
381 std::unique_ptr<te::da::DataSetType> dsType = dsLayer->
getSchema();
383 if(!dsType->getPrimaryKey() || dsType->getPrimaryKey()->getProperties().empty())
385 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid Data Set Primary Key."));
389 std::string attrLink = dsType->getPrimaryKey()->getProperties()[0]->getName();
397 builder.
setGPMInfo(ds, dataSetName, attrLink);
400 gpm.reset(builder.
getGPM());
404 if(
m_ui->m_gpmLineEdit->text().isEmpty())
406 QMessageBox::warning(
this, tr(
"Warning"), tr(
"GPM File not selected."));
411 QFileInfo
file(
m_ui->m_gpmLineEdit->text());
413 std::string extension =
file.suffix().toUtf8().data();
417 if(extension ==
"gal" || extension ==
"GAL")
419 gpm.reset(swe.
importFromGAL(
m_ui->m_gpmLineEdit->text().toUtf8().data(), ds.get()));
421 else if(extension ==
"gwt" || extension ==
"GWT")
423 gpm.reset(swe.
importFromGWT(
m_ui->m_gpmLineEdit->text().toUtf8().data(), ds.get()));
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
This class defines a an adjacency strategy class for a GPM constructor.
GeneralizedProximityMatrix * getGPM()
Function used to return the generated gpm.
void fillRateCorrection()
Class that represents the Bayes output parameters.
boost::shared_ptr< DataSource > DataSourcePtr
TESAEXPORT te::da::DataSourcePtr CreateOGRDataSource(std::string repository)
bool setGPMInfo(te::da::DataSourcePtr ds, const std::string &dataSetName, const std::string &attributeName)
Function used to create an empty gpm (using a MEMORY DIRECT graph)
This class defines a class to calculates a weight for a GPM using No Weights strategy.
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
static te::dt::Date ds(2010, 01, 01)
void onOkPushButtonClicked()
te::sa::GeneralizedProximityMatrix * importFromGAL(std::string pathFileName, te::da::DataSource *ds=0)
Function used to import a gpm from a Spatial Weights File GAL Format.
te::sa::GeneralizedProximityMatrix * importFromGWT(std::string pathFileName, te::da::DataSource *ds=0)
Function used to import a gpm from a Spatial Weights File GWT Format.
std::string m_outputDataSetName
Attribute that defines the output dataset name.
TESAEXPORT void CreateBayesGrouping(te::map::AbstractLayerPtr layer)
std::unique_ptr< te::sa::GeneralizedProximityMatrix > loadGPM()
void onInputLayerComboBoxActivated(int index)
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
static void getSpatialWeightsFileInfo(std::string pathFileName, std::string &dataSetName, std::string &attrName)
Function used to get information of how a Spatial Weights was generated.
void onTargetDatasourceToolButtonPressed()
Utility functions for the data access module.
std::unique_ptr< Ui::BayesLocalDialogForm > m_ui
te::da::DataSourcePtr m_ds
Pointer to the output datasource.
This class defines a an Abstract class for a GPM constructor.
This class defines a an Abstract class to calculates a weight for a GPM.
const std::string & getDataSetName() const
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
te::map::AbstractLayerPtr getOutputLayer()
This class defines functions used to load and save gpm's using GAL and GWT formats, both formats use a ' ' as separator.
A layer with reference to a dataset.
This class defines the GPM Builder class.
A dialog to calculate the local empirical bayes of a dataset.
void setParameters(te::sa::BayesInputParams *inParams, te::sa::BayesOutputParams *outParams)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
te::da::DataSourceInfoPtr m_outputDatasource
void onGPMToolButtonClicked()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual const std::string & getDataSourceId() const
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
void execute()
Function to execute the bayes operation.
void onTargetFileToolButtonPressed()