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/SamplePointsGeneratorRandom.h" 38 #include "../core/SamplePointsGeneratorStratified.h" 40 #include "../Exception.h" 43 #include "ui_SamplePointsGeneratorDialogForm.h" 46 #include <QFileDialog> 48 #include <QMessageBox> 55 #include <boost/filesystem.hpp> 59 te::sa::SamplePointsGeneratorDialog::SamplePointsGeneratorDialog(
QWidget* parent, Qt::WindowFlags f)
61 m_ui(new
Ui::SamplePointsGeneratorDialogForm)
68 m_ui->m_nPointsRandomLineEdit->setValidator(
new QIntValidator(
this));
69 m_ui->m_nPointsStratifiedLineEdit->setValidator(
new QIntValidator(
this));
72 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"sa-samplepoint-hint").pixmap(112,48));
73 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
76 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()));
83 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
84 m_ui->m_helpPushButton->setPageReference(
"plugins/sa/sa_samplepointsgenerator.html");
91 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
93 while(it != layers.end())
99 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
101 if(dsType->hasGeom())
102 m_ui->m_inputLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
109 if(
m_ui->m_inputLayerComboBox->count() > 0)
120 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
124 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
126 std::vector<te::dt::Property*> propVec = dsType->getProperties();
128 m_ui->m_attrStratifiedComboBox->clear();
130 for(std::size_t t = 0; t < propVec.size(); ++t)
132 int dataType = propVec[t]->getType();
135 m_ui->m_attrStratifiedComboBox->addItem(propVec[t]->getName().c_str(), dataType);
142 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
144 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a repository for the result."));
148 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
150 QMessageBox::information(
this, tr(
"Warning"), tr(
"Define a name for the resulting layer."));
159 if(
m_ui->m_nPointsRandomLineEdit->text().isEmpty())
161 QMessageBox::information(
this, tr(
"Warning"), tr(
"Number of points not defined."));
167 if(
m_ui->m_nPointsStratifiedLineEdit->text().isEmpty())
169 QMessageBox::information(
this, tr(
"Warning"), tr(
"Number of points not defined."));
175 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
178 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
203 std::string dataSetName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
205 std::size_t idx = dataSetName.find(
".");
206 if (idx != std::string::npos)
207 dataSetName=dataSetName.substr(0,idx);
209 std::vector<std::string> classNames;
214 QApplication::setOverrideCursor(Qt::WaitCursor);
258 catch(
const std::exception& e)
260 QMessageBox::warning(
this, tr(
"Warning"), e.what());
262 QApplication::restoreOverrideCursor();
268 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Internal Error.Sample Points not generated."));
270 QApplication::restoreOverrideCursor();
275 QApplication::restoreOverrideCursor();
290 m_ui->m_newLayerNameLineEdit->clear();
291 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
296 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
298 if(dsPtrList.empty())
301 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
303 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
312 m_ui->m_newLayerNameLineEdit->clear();
313 m_ui->m_repositoryLineEdit->clear();
315 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
317 if (fileName.isEmpty())
320 boost::filesystem::path outfile(fileName.toUtf8().data());
322 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
324 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
326 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
333 m_ui->m_generatorTypeComboBox->clear();
void onTargetDatasourceToolButtonPressed()
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setEnvelope(te::gm::Envelope env)
std::unique_ptr< Ui::SamplePointsGeneratorDialogForm > m_ui
boost::shared_ptr< DataSource > DataSourcePtr
TESAEXPORT te::da::DataSourcePtr CreateOGRDataSource(std::string repository)
void onTargetFileToolButtonPressed()
TESAEXPORT void CreateSampleGeneratorStratifiedGrouping(te::map::AbstractLayerPtr layer, std::vector< std::string > strVec)
void setOutputDataSource(te::da::DataSourcePtr ds)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
Class to generate samples points using stratified strategy.
void onOkPushButtonClicked()
void fillGeneratorTypes()
int getSRID() const
It returns the spatial reference system identifier associated to this property.
An Envelope defines a 2D rectangular region.
void onInputLayerComboBoxActivated(int index)
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
Utility functions for the data access module.
Virtual class to generate samples points.
void execute()
Function to execute the kernel operation.
void setOutputDataSetName(std::string dataSetName)
Class to generate samples points using random strategy.
~SamplePointsGeneratorDialog()
TESAEXPORT te::map::AbstractLayerPtr CreateLayer(te::da::DataSourcePtr ds, std::string dataSetName)
te::da::DataSourceInfoPtr m_outputDatasource
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A dialog to generate sample points inside an area of a dataset.
SamplePointsGeneratorType
Generator types used to create sample of points.
te::map::AbstractLayerPtr getOutputLayer()