27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/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>
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"));
75 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
76 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_proxmatrixcreator.html");
85 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
87 while(it != layers.end())
93 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
97 if(dsLayer && dsType->hasGeom())
98 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
105 if(m_ui->m_inputLayerComboBox->count() > 0)
106 onInputLayerComboBoxActivated(0);
111 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
115 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
117 std::vector<te::dt::Property*> propVec = dsType->getProperties();
119 m_ui->m_attrIdComboBox->clear();
121 for(std::size_t t = 0; t < propVec.size(); ++t)
123 m_ui->m_attrIdComboBox->addItem(propVec[t]->getName().c_str());
126 m_ui->m_nameLineEdit->setText(l->getTitle().c_str());
131 if(!m_ui->m_dsRadioButton->isChecked())
133 QString fileName = QFileDialog::getExistingDirectory(
this, tr(
"Save To File"),
"");
135 if(fileName.isEmpty())
138 m_ui->m_locationLineEdit->setText(fileName);
145 if(m_ui->m_nameLineEdit->text().isEmpty())
147 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output name not defined."));
151 if(m_ui->m_locationLineEdit->text().isEmpty())
153 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Output location not defined."));
157 if(m_ui->m_inputLayerComboBox->currentText().isEmpty() || m_ui->m_attrIdComboBox->currentText().isEmpty())
159 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Input information not defined."));
164 std::string attrName = m_ui->m_attrIdComboBox->currentText().toStdString();
166 QVariant varLayer = m_ui->m_inputLayerComboBox->itemData(m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
174 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error getting input layer."));
183 if(m_ui->m_buildStratContiguityRadioButton->isChecked())
187 else if(m_ui->m_buildStratDistanceRadioButton->isChecked())
189 if(m_ui->m_distanceLineEdit->text().isEmpty())
191 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Distance Value not Defined."));
197 else if(m_ui->m_buildStratNNRadioButton->isChecked())
199 if(m_ui->m_nearNeighborLineEdit->text().isEmpty())
201 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Number of Neighbors not Defined."));
211 if(m_ui->m_weightNoWeightRadioButton->isChecked())
215 else if(m_ui->m_weightInverseDistRadioButton->isChecked())
219 else if(m_ui->m_weightSquareInverseDistRadioButton->isChecked())
227 std::auto_ptr<te::sa::GeneralizedProximityMatrix> gpm;
233 QApplication::setOverrideCursor(Qt::WaitCursor);
237 builder.
setGPMInfo(ds, dsLayer->getDataSetName(), attrName);
239 gpm = builder.
build();
241 catch(
const std::exception& e)
243 QMessageBox::warning(
this, tr(
"Warning"), e.what());
245 QApplication::restoreOverrideCursor();
253 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error."));
255 QApplication::restoreOverrideCursor();
262 QApplication::restoreOverrideCursor();
267 if(!m_ui->m_dsRadioButton->isChecked())
270 std::string ext =
"";
272 if(m_ui->m_galRadioButton->isChecked())
274 else if(m_ui->m_gwtRadioButton->isChecked())
277 std::string name = m_ui->m_nameLineEdit->text().toStdString();
279 std::string fullFileName = m_ui->m_locationLineEdit->text().toStdString();
281 fullFileName +=
"/" + name + ext;
286 if(m_ui->m_galRadioButton->isChecked())
287 exchanger .exportToGAL(gpm.get(), fullFileName);
288 else if(m_ui->m_gwtRadioButton->isChecked())
289 exchanger .exportToGWT(gpm.get(), 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.
std::auto_ptr< GeneralizedProximityMatrix > build()
boost::shared_ptr< DataSource > DataSourcePtr
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 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.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void onOkPushButtonClicked()
~ProximityMatrixCreatorDialog()
ProximityMatrixCreatorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
This class defines a class to calculates a weight for a GPM using Inverse Distance strategy...
std::auto_ptr< Ui::ProximityMatrixCreatorDialogForm > m_ui
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.
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.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr