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/GPMBuilder.h" 38 #include "../core/GPMConstructorAdjacencyStrategy.h" 39 #include "../core/GPMWeightsNoWeightsStrategy.h" 40 #include "../core/SkaterOperation.h" 41 #include "../core/SkaterParams.h" 42 #include "../core/SpatialWeightsExchanger.h" 43 #include "../core/Utils.h" 44 #include "../Exception.h" 47 #include "ui_SkaterDialogForm.h" 50 #include <QFileDialog> 52 #include <QGridLayout> 53 #include <QMessageBox> 60 #include <boost/filesystem.hpp> 64 te::sa::SkaterDialog::SkaterDialog(
QWidget* parent, Qt::WindowFlags f)
66 m_ui(new
Ui::SkaterDialogForm)
73 m_doubleListWidget->setLeftLabel(
"Layer Attributes");
74 m_doubleListWidget->setRightLabel(
"Selected Attributes");
75 QGridLayout* layout =
new QGridLayout(m_ui->m_widget);
76 layout->addWidget(m_doubleListWidget);
77 layout->setContentsMargins(0, 0, 0, 0);
80 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-skater-hint").pixmap(112,48));
81 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
84 connect(m_ui->m_inputLayerComboBox, SIGNAL(activated(
int)),
this, SLOT(onInputLayerComboBoxActivated(
int)));
85 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
86 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
87 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
88 connect(m_ui->m_gpmToolButton, SIGNAL(clicked()),
this, SLOT(onGPMToolButtonClicked()));
91 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
92 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_skater.html");
99 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
101 while(it != layers.end())
107 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
110 if(dsLayer && dsType->hasGeom())
111 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
118 if(
m_ui->m_inputLayerComboBox->count() > 0)
129 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
133 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
135 std::vector<te::dt::Property*> propVec = dsType->getProperties();
137 m_ui->m_popComboBox->clear();
138 m_ui->m_attrLinkComboBox->clear();
143 std::vector<std::string> vec;
145 for(std::size_t t = 0; t < propVec.size(); ++t)
147 int dataType = propVec[t]->getType();
154 m_ui->m_popComboBox->addItem(propVec[t]->getName().c_str(), dataType);
156 vec.push_back(propVec[t]->getName());
159 m_ui->m_attrLinkComboBox->addItem(propVec[t]->getName().c_str(), dataType);
162 std::sort(vec.begin(), vec.end());
170 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
172 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
176 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
178 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
182 if(!
m_ui->m_clustersCheckBox->isChecked() && !
m_ui->m_popCheckBox->isChecked())
184 QMessageBox::information(
this, tr(
"Warning"), tr(
"Select the aggregation type."));
188 if(
m_ui->m_clustersCheckBox->isChecked())
190 if(
m_ui->m_nClustersLineEdit->text().isEmpty())
192 QMessageBox::information(
this, tr(
"Warning"), tr(
"Number of clusters not defined."));
197 if(
m_ui->m_popCheckBox->isChecked())
199 if(
m_ui->m_minPopLineEdit->text().isEmpty())
201 QMessageBox::information(
this, tr(
"Warning"), tr(
"Minimum population not defined."));
210 QMessageBox::information(
this, tr(
"Warning"), tr(
"Select the attributes."));
215 std::unique_ptr<te::sa::GeneralizedProximityMatrix> gpm;
223 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal error. GPM not loaded."));
231 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
234 std::unique_ptr<te::da::DataSetType> dataSetType = l->getSchema();
235 std::unique_ptr<te::da::DataSet> dataSet = l->getData();
238 std::string dataSetName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
240 std::size_t idx = dataSetName.find(
".");
241 if (idx != std::string::npos)
242 dataSetName=dataSetName.substr(0,idx);
258 inParams->m_ds = std::move(dataSet);
259 inParams->m_dsType = std::move(dataSetType);
260 inParams->m_gpmAttrLink = gpm->getAttributeName();
261 inParams->m_gpm = std::move(gpm);
264 if(
m_ui->m_clustersCheckBox->isChecked() &&
m_ui->m_popCheckBox->isChecked())
267 inParams->m_nClusters = (std::size_t)
m_ui->m_nClustersLineEdit->text().toInt();
268 inParams->m_minPop = (std::size_t)
m_ui->m_minPopLineEdit->text().toInt();
269 inParams->m_attrPop =
m_ui->m_popComboBox->currentText().toUtf8().data();
271 else if(
m_ui->m_clustersCheckBox->isChecked())
274 inParams->m_nClusters = (std::size_t)
m_ui->m_nClustersLineEdit->text().toInt();
276 else if(
m_ui->m_popCheckBox->isChecked())
279 inParams->m_minPop = (std::size_t)
m_ui->m_minPopLineEdit->text().toInt();
280 inParams->m_attrPop =
m_ui->m_popComboBox->currentText().toUtf8().data();
283 inParams->m_attrs = attrs;
295 QApplication::setOverrideCursor(Qt::WaitCursor);
307 catch(
const std::exception& e)
309 QMessageBox::warning(
this, tr(
"Warning"), e.what());
311 QApplication::restoreOverrideCursor();
317 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error. Skater not calculated."));
319 QApplication::restoreOverrideCursor();
324 QApplication::restoreOverrideCursor();
337 m_ui->m_newLayerNameLineEdit->clear();
338 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
343 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
345 if(dsPtrList.empty())
348 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
350 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
359 m_ui->m_newLayerNameLineEdit->clear();
360 m_ui->m_repositoryLineEdit->clear();
362 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
364 if (fileName.isEmpty())
367 boost::filesystem::path outfile(fileName.toUtf8().data());
369 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
371 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
373 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
380 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Generalized Proximity Matrix File"),
"", tr(
"GAL Files (*.gal *.GAL);; GWT Files (*.gwt *.GWT)"));
382 if(fileName.isEmpty())
386 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
391 std::string path = fileName.toUtf8().data();
392 std::string dataSetName;
393 std::string attrName;
397 if(dsLayer->getDataSetName() != dataSetName)
399 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected layer."));
403 if(
m_ui->m_attrLinkComboBox->currentText().toUtf8().data() != attrName)
405 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid GPM file for selected Attr Link."));
409 m_ui->m_gpmLineEdit->setText(fileName);
414 std::unique_ptr<te::sa::GeneralizedProximityMatrix> gpm;
417 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
422 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid selected layer."));
433 if(!
m_ui->m_gpmGroupBox->isChecked())
436 if(QMessageBox::question(
this, tr(
"Spatial Analysis"), tr(
"GPM not selected. Create default GPM?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
440 std::unique_ptr<te::da::DataSetType> dsType = dsLayer->
getSchema();
442 if(!dsType->getPrimaryKey() || dsType->getPrimaryKey()->getProperties().empty())
444 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Invalid Data Set Primary Key."));
448 std::string attrLink = dsType->getPrimaryKey()->getProperties()[0]->getName();
456 builder.
setGPMInfo(ds, dataSetName, attrLink);
460 gpm.reset(builder.
getGPM());
464 if(
m_ui->m_gpmLineEdit->text().isEmpty())
466 QMessageBox::warning(
this, tr(
"Warning"), tr(
"GPM File not selected."));
471 QFileInfo
file(
m_ui->m_gpmLineEdit->text());
473 std::string extension =
file.suffix().toUtf8().data();
477 if(extension ==
"gal" || extension ==
"GAL")
479 gpm.reset(swe.
importFromGAL(
m_ui->m_gpmLineEdit->text().toUtf8().data(), ds.get()));
481 else if(extension ==
"gwt" || extension ==
"GWT")
483 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.
void execute()
Function to execute the skater operation.
This class defines a an adjacency strategy class for a GPM constructor.
GeneralizedProximityMatrix * getGPM()
Function used to return the generated gpm.
te::map::AbstractLayerPtr getOutputLayer()
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.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
te::qt::widgets::DoubleListWidget * m_doubleListWidget
Widget used to select attributes.
static te::dt::Date ds(2010, 01, 01)
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.
Class that represents the skater output parameters.
te::da::DataSourceInfoPtr m_outputDatasource
Class used to execute the skater operations.
void onTargetDatasourceToolButtonPressed()
A dialog for Spatial 'K'luster Analysis by Tree Edge Removal.
void setParameters(te::sa::SkaterInputParams *inParams, te::sa::SkaterOutputParams *outParams)
std::unique_ptr< Ui::SkaterDialogForm > m_ui
void onGPMToolButtonClicked()
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
static void getSpatialWeightsFileInfo(std::string pathFileName, std::string &dataSetName, std::string &attrName)
Function used to get information of how a Spatial Weights was generated.
Utility functions for the data access module.
std::string m_outputDataSetName
Attribute that defines the output dataset name.
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
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.
te::da::DataSourcePtr m_dataSource
Pointer to the output data source.
const std::string & getDataSetName() const
std::unique_ptr< te::sa::GeneralizedProximityMatrix > loadGPM()
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
void onOkPushButtonClicked()
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.
TESAEXPORT void CreateSkaterGrouping(te::map::AbstractLayerPtr layer, int nClasses)
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 onInputLayerComboBoxActivated(int index)
void onTargetFileToolButtonPressed()