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/utils/Utils.h" 32 #include "../../maptools/DataSetLayer.h" 33 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 34 #include "../core/GPMBuilder.h" 35 #include "../core/GPMConstructorAbstractStrategy.h" 36 #include "../core/GPMConstructorAdjacencyStrategy.h" 37 #include "../core/GPMConstructorDistanceStrategy.h" 38 #include "../core/GPMConstructorNearestNeighborStrategy.h" 39 #include "../core/GPMWeightsAbstractStrategy.h" 40 #include "../core/GPMWeightsInverseDistanceStrategy.h" 41 #include "../core/GPMWeightsNoWeightsStrategy.h" 42 #include "../core/GPMWeightsSquaredInverseDistanceStrategy.h" 43 #include "../core/SpatialWeightsExchanger.h" 44 #include "../Exception.h" 46 #include "ui_ProximityMatrixCreatorDialogForm.h" 49 #include <QFileDialog> 50 #include <QMessageBox> 55 te::sa::ProximityMatrixCreatorDialog::ProximityMatrixCreatorDialog(
QWidget* parent, Qt::WindowFlags f)
57 m_ui(new
Ui::ProximityMatrixCreatorDialogForm)
62 m_ui->m_distanceLineEdit->setValidator(
new QDoubleValidator(
this));
63 m_ui->m_nearNeighborLineEdit->setValidator(
new QIntValidator(
this));
66 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-proxmatrixcreator-hint").pixmap(112,48));
67 m_ui->m_fileToolButton->setIcon(QIcon::fromTheme(
"folder-open"));
70 connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(
int)),
this, SLOT(onInputLayerComboBoxActivated(
int)));
71 connect(m_ui->m_fileToolButton, SIGNAL(clicked()),
this, SLOT(onFileToolButtonClicked()));
72 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
75 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
76 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_proxmatrixcreator.html");
83 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
85 while(it != layers.end())
91 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
95 if(dsLayer && dsType->hasGeom())
96 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
103 if(
m_ui->m_inputLayerComboBox->count() > 0)
109 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
113 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
115 std::vector<te::dt::Property*> propVec = dsType->getProperties();
117 m_ui->m_attrIdComboBox->clear();
119 for(std::size_t t = 0; t < propVec.size(); ++t)
121 m_ui->m_attrIdComboBox->addItem(propVec[t]->getName().c_str());
124 m_ui->m_nameLineEdit->setText(l->getTitle().c_str());
129 if(!
m_ui->m_dsRadioButton->isChecked())
131 QString fileName = QFileDialog::getExistingDirectory(
this, tr(
"Save To File"),
"");
133 if(fileName.isEmpty())
136 m_ui->m_locationLineEdit->setText(fileName);
143 if(
m_ui->m_nameLineEdit->text().isEmpty())
145 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output name not defined."));
149 if(
m_ui->m_locationLineEdit->text().isEmpty())
151 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output location not defined."));
155 if(
m_ui->m_inputLayerComboBox->currentText().isEmpty() ||
m_ui->m_attrIdComboBox->currentText().isEmpty())
157 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Input information not defined."));
162 std::string attrName =
m_ui->m_attrIdComboBox->currentText().toUtf8().data();
164 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
172 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error getting input layer."));
181 if(
m_ui->m_buildStratContiguityRadioButton->isChecked())
185 else if(
m_ui->m_buildStratDistanceRadioButton->isChecked())
187 if(
m_ui->m_distanceLineEdit->text().isEmpty())
189 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Distance Value not Defined."));
195 else if(
m_ui->m_buildStratNNRadioButton->isChecked())
197 if(
m_ui->m_nearNeighborLineEdit->text().isEmpty())
199 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Number of Neighbors not Defined."));
209 if(
m_ui->m_weightNoWeightRadioButton->isChecked())
213 else if(
m_ui->m_weightInverseDistRadioButton->isChecked())
217 else if(
m_ui->m_weightSquareInverseDistRadioButton->isChecked())
230 QApplication::setOverrideCursor(Qt::WaitCursor);
234 builder.setGPMInfo(ds, dsLayer->getDataSetName(), attrName);
238 gpm = builder.getGPM();
240 catch(
const std::exception& e)
242 QMessageBox::warning(
this, tr(
"Warning"), e.what());
244 QApplication::restoreOverrideCursor();
250 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error."));
252 QApplication::restoreOverrideCursor();
257 QApplication::restoreOverrideCursor();
260 if(!
m_ui->m_dsRadioButton->isChecked())
265 if(
m_ui->m_galRadioButton->isChecked())
267 else if(
m_ui->m_gwtRadioButton->isChecked())
270 std::string name =
m_ui->m_nameLineEdit->text().toUtf8().data();
272 std::string fullFileName =
m_ui->m_locationLineEdit->text().toUtf8().data();
274 fullFileName +=
"/" + name + ext;
279 if(
m_ui->m_galRadioButton->isChecked())
280 exchanger .exportToGAL(gpm, fullFileName);
281 else if(
m_ui->m_gwtRadioButton->isChecked())
282 exchanger .exportToGWT(gpm, fullFileName, 1);
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.
boost::shared_ptr< DataSource > DataSourcePtr
This class defines a Generalized Proximity Matrix.
This class defines a nearest neighbor class for a GPM constructor.
This class defines a class to calculates a weight for a GPM using No Weights strategy.
This class defines a class to calculates a weight for a GPM using Inverse Distance strategy...
A dialog for Proximity Matrix Creation.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
static te::dt::Date ds(2010, 01, 01)
void onOkPushButtonClicked()
~ProximityMatrixCreatorDialog()
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
This class defines a class to calculates a weight for a GPM using Inverse Distance strategy...
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.
void onFileToolButtonClicked()
void onInputLayerComboBoxActivated(int index)
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 a an distance strategy class for a GPM constructor.
This class defines the GPM Builder class.
std::unique_ptr< Ui::ProximityMatrixCreatorDialogForm > m_ui
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr