27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/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>
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"));
84 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
85 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_bayeslocal.html");
94 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
96 while(it != layers.end())
102 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
106 if(dsLayer && dsType->hasGeom())
107 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
114 if(m_ui->m_inputLayerComboBox->count() > 0)
115 onInputLayerComboBoxActivated(0);
120 return m_outputLayer;
125 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
129 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
131 std::vector<te::dt::Property*> propVec = dsType->getProperties();
133 m_ui->m_attrEventComboBox->clear();
134 m_ui->m_attrPopComboBox->clear();
135 m_ui->m_attrLinkComboBox->clear();
137 for(std::size_t t = 0; t < propVec.size(); ++t)
139 int dataType = propVec[t]->getType();
146 m_ui->m_attrEventComboBox->addItem(propVec[t]->getName().c_str(), dataType);
147 m_ui->m_attrPopComboBox->addItem(propVec[t]->getName().c_str(), dataType);
150 m_ui->m_attrLinkComboBox->addItem(propVec[t]->getName().c_str(), dataType);
157 if(m_ui->m_repositoryLineEdit->text().isEmpty())
159 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
163 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
165 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
170 std::auto_ptr<te::sa::GeneralizedProximityMatrix> gpm;
178 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error. GPM not loaded."));
186 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
189 std::auto_ptr<te::da::DataSetType> dataSetType = l->getSchema();
190 std::auto_ptr<te::da::DataSet> dataSet = l->getData();
193 std::string dataSetName = m_ui->m_newLayerNameLineEdit->text().toStdString();
195 std::size_t idx = dataSetName.find(
".");
196 if (idx != std::string::npos)
197 dataSetName=dataSetName.substr(0,idx);
212 inParams->
m_ds = dataSet;
214 inParams->
m_eventAttrName = m_ui->m_attrEventComboBox->currentText().toStdString();
216 inParams->
m_rate = m_ui->m_rateComboBox->currentText().toDouble();
218 inParams->
m_gpm = gpm;
222 outParams->
m_ds = outputDataSource;
229 QApplication::setOverrideCursor(Qt::WaitCursor);
239 catch(
const std::exception& e)
241 QMessageBox::warning(
this, tr(
"Warning"), e.what());
243 QApplication::restoreOverrideCursor();
251 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error. Global Bayes not calculated."));
253 QApplication::restoreOverrideCursor();
260 QApplication::restoreOverrideCursor();
275 m_ui->m_newLayerNameLineEdit->clear();
276 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
281 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
283 if(dsPtrList.size() <= 0)
286 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
288 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
290 m_outputDatasource = *it;
297 m_ui->m_newLayerNameLineEdit->clear();
298 m_ui->m_repositoryLineEdit->clear();
300 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
302 if (fileName.isEmpty())
305 boost::filesystem::path outfile(fileName.toStdString());
307 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
309 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
311 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
318 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Generalized Proximity Matrix File"),
"", tr(
"GAL Files (*.gal *.GAL);; GWT Files (*.gwt *.GWT)"));
320 if(fileName.isEmpty())
324 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
329 std::string path = fileName.toStdString();
330 std::string dataSetName =
"";
331 std::string attrName =
"";
335 if(dsLayer->getDataSetName() != dataSetName)
337 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected layer."));
341 if(m_ui->m_attrLinkComboBox->currentText().toStdString() != attrName)
343 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected Attr Link."));
347 m_ui->m_gpmLineEdit->setText(fileName);
352 m_ui->m_rateComboBox->clear();
354 m_ui->m_rateComboBox->addItem(
"1");
355 m_ui->m_rateComboBox->addItem(
"10");
356 m_ui->m_rateComboBox->addItem(
"100");
357 m_ui->m_rateComboBox->addItem(
"1000");
358 m_ui->m_rateComboBox->addItem(
"10000");
359 m_ui->m_rateComboBox->addItem(
"100000");
364 std::auto_ptr<te::sa::GeneralizedProximityMatrix> gpm;
367 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
372 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid selected layer."));
383 if(!m_ui->m_gpmGroupBox->isChecked())
386 if(QMessageBox::question(
this, tr(
"Spatial Analysis"), tr(
"GPM not selected. Create default GPM?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
390 std::auto_ptr<te::da::DataSetType> dsType = dsLayer->
getSchema();
392 if(!dsType->getPrimaryKey() || dsType->getPrimaryKey()->getProperties().empty())
394 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid Data Set Primary Key."));
398 std::string attrLink = dsType->getPrimaryKey()->getProperties()[0]->getName();
406 builder.
setGPMInfo(ds, dataSetName, attrLink);
408 gpm = builder.
build();
412 if(m_ui->m_gpmLineEdit->text().isEmpty())
414 QMessageBox::warning(
this, tr(
"Warning"), tr(
"GPM File not selected."));
419 QFileInfo file(m_ui->m_gpmLineEdit->text());
421 std::string extension = file.suffix().toStdString();
425 if(extension ==
"gal" || extension ==
"GAL")
427 gpm.reset(swe.
importFromGAL(m_ui->m_gpmLineEdit->text().toStdString(), ds.get()));
429 else if(extension ==
"gwt" || extension ==
"GWT")
431 gpm.reset(swe.
importFromGWT(m_ui->m_gpmLineEdit->text().toStdString(), 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.
void fillRateCorrection()
Class that represents the Bayes output parameters.
std::auto_ptr< GeneralizedProximityMatrix > build()
Utility functions for the data access module.
const std::string & getDataSetName() const
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 a empty gpm (using a MEMORY DIRECT graph)
This class defines a class to calculates a weight for a GPM using No Weights strategy.
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.
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
TESAEXPORT void CreateBayesGrouping(te::map::AbstractLayerPtr layer)
void onInputLayerComboBoxActivated(int index)
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()
te::da::DataSourcePtr m_ds
Pointer to the output datasource.
This class defines a an Abstract class for a GPM constructor.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
This class defines a an Abstract class to calculates a weight for a GPM.
BayesLocalDialog(QWidget *parent=0, Qt::WindowFlags f=0)
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
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.
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
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)
std::auto_ptr< te::sa::GeneralizedProximityMatrix > loadGPM()
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void onGPMToolButtonClicked()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::auto_ptr< Ui::BayesLocalDialogForm > m_ui
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void execute()
Function to execute the bayes operation.
void onTargetFileToolButtonPressed()