27 #include "../../core/filesystem/FileSystem.h" 28 #include "../../core/translator/Translator.h" 29 #include "../../common/Exception.h" 30 #include "../../common/progress/ProgressManager.h" 31 #include "../../common/UnitsOfMeasureManager.h" 32 #include "../../dataaccess/datasource/DataSourceFactory.h" 33 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 34 #include "../../dataaccess/datasource/DataSourceManager.h" 35 #include "../../dataaccess/utils/Utils.h" 36 #include "../../geometry/GeometryProperty.h" 37 #include "../../maptools/DataSetLayer.h" 38 #include "../../mnt/core/TINGeneration.h" 39 #include "../../mnt/core/Utils.h" 40 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 41 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 42 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 43 #include "../../qt/widgets/srs/SRSManagerDialog.h" 44 #include "../../qt/widgets/utils/FileDialog.h" 45 #include "../../srs/SpatialReferenceSystemManager.h" 49 #include "ui_TINGenerationDialogForm.h" 52 #include <QFileDialog> 53 #include <QMessageBox> 56 #include <boost/algorithm/string.hpp> 57 #include <boost/filesystem.hpp> 58 #include <boost/lexical_cast.hpp> 59 #include <boost/uuid/random_generator.hpp> 60 #include <boost/uuid/uuid_io.hpp> 64 m_ui(new
Ui::TINGenerationDialogForm),
78 connect(
m_ui->m_yesradioButton, SIGNAL(toggled(
bool)),
this, SLOT(
onYesToggled()));
79 connect(
m_ui->m_noradioButton, SIGNAL(toggled(
bool)),
this, SLOT(
onNoToggled()));
83 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
90 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
91 m_ui->m_helpPushButton->setPageReference(
"plugins/mnt/DTM_TIN.html");
93 m_ui->m_srsToolButton->setIcon(QIcon::fromTheme(
"srs"));
96 m_ui->m_noradioButton->setChecked(
true);
97 m_ui->m_isolinescomboBox->addItem(QString(
""), QVariant(
""));
98 m_ui->m_samplescomboBox->addItem(QString(
""), QVariant(
""));
99 m_ui->m_breaklinecomboBox->addItem(QString(
""), QVariant(
""));
114 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
120 if (it->get()->isValid())
122 std::unique_ptr<te::da::DataSetType> dsType(it->get()->getSchema());
126 m_ui->m_samplescomboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
130 m_ui->m_isolinescomboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
131 m_ui->m_breaklinecomboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
143 QList<mntType> types;
147 if (search.exec() != QDialog::Accepted)
152 int index =
m_ui->m_isolinescomboBox->findText(search.
getLayer().get()->getTitle().c_str());
153 m_ui->m_isolinescomboBox->setCurrentIndex(index);
158 m_ui->m_isolinesZcomboBox->clear();
160 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
161 std::string layerID =
m_ui->m_isolinescomboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
165 if(layerID == it->get()->getId())
168 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
187 std::unique_ptr<te::gm::Geometry> gin = inDset->getGeometry(geo_pos);
190 m_ui->m_isolinesZlabel->hide();
191 m_ui->m_isolinesZcomboBox->hide();
195 m_ui->m_isolinesZlabel->show();
196 m_ui->m_isolinesZcomboBox->show();
198 std::vector<te::dt::Property*> props = dsType->getProperties();
199 for (std::size_t i = 0; i < props.size(); ++i)
201 switch (props[i]->getType())
212 m_ui->m_isolinesZcomboBox->addItem(QString(props[i]->getName().c_str()), QVariant(props[i]->getName().c_str()));
221 catch (
const std::exception& e)
223 QMessageBox::information(
this, tr(
"TIN Generation"), e.what());
232 QList<mntType> types;
236 if (search.exec() != QDialog::Accepted)
241 int index =
m_ui->m_samplescomboBox->findText(search.
getLayer().get()->getTitle().c_str());
242 m_ui->m_samplescomboBox->setCurrentIndex(index);
248 m_ui->m_samplesZcomboBox->clear();
250 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
251 std::string layerID =
m_ui->m_samplescomboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
254 if(layerID == it->get()->getId())
273 std::unique_ptr<te::gm::Geometry> gin = inDset->getGeometry(geo_pos);
276 m_ui->m_samplesZlabel->hide();
277 m_ui->m_samplesZcomboBox->hide();
281 m_ui->m_samplesZlabel->show();
282 m_ui->m_samplesZcomboBox->show();
284 std::unique_ptr<te::da::DataSetType> dsType =
m_samplesLayer->getSchema();
285 std::vector<te::dt::Property*> props = dsType->getProperties();
287 for (std::size_t i = 0; i < props.size(); ++i)
289 switch (props[i]->getType())
300 m_ui->m_samplesZcomboBox->addItem(QString(props[i]->getName().c_str()), QVariant(props[i]->getName().c_str()));
308 catch (
const std::exception& e)
310 QMessageBox::information(
this, tr(
"TIN Generation"), e.what());
317 m_scale =
m_ui->m_scalelineEdit->text().toDouble();
323 m_ui->m_tollineEdit->setText(QString::number(
m_tol));
331 m_ui->m_breaklinelabel->setEnabled(
true);
332 m_ui->m_breaklinecomboBox->setEnabled(
true);
333 m_ui->m_breaktollabel->setEnabled(
true);
334 m_ui->m_breaktollineEdit->setEnabled(
true);
339 m_ui->m_breaklinecomboBox->setCurrentIndex(0);
340 m_ui->m_breaklinelabel->setDisabled(
true);
341 m_ui->m_breaklinecomboBox->setDisabled(
true);
342 m_ui->m_breaktollabel->setDisabled(
true);
343 m_ui->m_breaktollineEdit->setDisabled(
true);
349 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
350 std::string layerID =
m_ui->m_breaklinecomboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
353 if(layerID == it->get()->getId())
366 QList<mntType> types;
370 if (search.exec() != QDialog::Accepted)
375 int index =
m_ui->m_breaklinecomboBox->findText(search.
getLayer().get()->getTitle().c_str());
376 m_ui->m_breaklinecomboBox->setCurrentIndex(index);
381 m_ui->m_newLayerNameLineEdit->clear();
382 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
386 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
388 if (dsPtrList.empty())
391 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
393 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
402 m_ui->m_newLayerNameLineEdit->clear();
403 m_ui->m_repositoryLineEdit->clear();
410 catch (
const std::exception& e)
412 QMessageBox::information(
this, tr(
"TIN Generation"), e.what());
416 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
417 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
420 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
430 QApplication::setOverrideCursor(Qt::WaitCursor);
448 m_tol =
m_ui->m_tollineEdit->text().toDouble(&ok);
476 if (!dsbreaklineLayer)
480 if (!inDataSource.get())
483 std::string inDsetNamebreakline = dsbreaklineLayer->
getDataSetName();
484 Tin->
setBreakLine(inDataSource, inDsetNamebreakline, inDataSource->getDataSetType(inDsetNamebreakline),
m_breaktol);
488 if (
m_ui->m_repositoryLineEdit->text().isEmpty())
491 if (
m_ui->m_newLayerNameLineEdit->text().isEmpty())
494 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
496 std::string dsinfo(
"file://");
497 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
504 std::size_t idx = outputdataset.find(
".");
505 if (idx != std::string::npos)
506 outputdataset = outputdataset.substr(0, idx);
508 dsinfo += uri.string();
513 if (dsOGR->dataSetExists(outputdataset))
514 throw te::common::Exception(
TE_TR(
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again."));
524 if (aux->dataSetExists(outputdataset))
525 throw te::common::Exception(
TE_TR(
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again."));
550 int method =
m_ui->m_typecomboBox->currentIndex();
553 bool result = Tin->
run();
560 boost::uuids::basic_random_generator<boost::mt19937> gen;
561 boost::uuids::uuid u = gen();
562 std::string
id = boost::uuids::to_string(u);
565 ds->setConnInfo(dsinfo);
566 ds->setTitle(uri.stem().string());
567 ds->setAccessDriver(
"OGR");
569 ds->setDescription(uri.string());
589 catch (
const std::exception& e)
591 QApplication::restoreOverrideCursor();
592 QMessageBox::information(
this, tr(
"TIN Generation"), e.what());
595 QApplication::restoreOverrideCursor();
612 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
614 if (srsDialog.exec() == QDialog::Rejected)
627 m_ui->m_resSRIDLabel->setText(
"No SRS defined");
633 m_ui->m_resSRIDLabel->setText(name.c_str());
635 m_ui->m_resSRIDLabel->setText(QString(
"%1").arg(newSRID));
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void onSamplesComboBoxChanged(int index)
double m_scale
Triangulation scale.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
TEMNTEXPORT bool convertPlanarToAngle(double &val, te::common::UnitOfMeasurePtr unit)
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
void onInputIsolinesToolButtonClicked()
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
te::map::AbstractLayerPtr getLayer()
boost::shared_ptr< DataSource > DataSourcePtr
std::string m_sampleSetName
Samples DataSetLayer name.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the Datasource that is being used to save TIN.
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
void onTargetFileToolButtonPressed()
double m_distance
Triangulation lines simplification maximum distance.
void setBreakLine(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, double tol)
It sets the BreakLine Datasource that is being used to generate TIN.
void onScalePushButtonClicked()
void onInputBreaklineToolButtonClicked()
double m_tol
Triangulation lines simplification tolerance.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void onTargetDatasourceToolButtonPressed()
void setSRID(int newSRID)
void onBreakLinesComboBoxChanged(int index)
void onInputSamplesToolButtonClicked()
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
te::map::AbstractLayerPtr getLayer()
std::string m_isoSetName
Isolines DataSetLayer name.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onCancelPushButtonClicked()
void setMethod(int method)
double m_breaktol
Triangulation breaklines simplification tolerance.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void onSrsToolButtonClicked()
void onOkPushButtonClicked()
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
const std::string & getDataSetName() const
Class to define TIN strutures.
bool run()
Generate TIN \ return true or false.
void setActive(const QList< mntType > &types)
te::map::AbstractLayerPtr m_samplesLayer
Points layer.
te::da::DataSourcePtr m_samplesDataSource
Samples DataSourcePtr.
A class that represents a data source component.
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
te::da::DataSourcePtr m_isolinesDataSource
Isolines DataSourcePtr.
A layer with reference to a dataset.
std::unique_ptr< Ui::TINGenerationDialogForm > m_ui
UnitOfMeasurePtr find(unsigned int id) const
Returns a unit of measure identified by its identificaton.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void onIsolinesComboBoxChanged(int index)
TEMNTEXPORT te::mnt::mntType getMNTType(const te::da::DataSetType *dt)
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, InputType type)
It sets the Datasource that is being used to generate TIN.
te::map::AbstractLayerPtr m_isolinesLayer
Isolines layer.
te::map::AbstractLayerPtr m_breaklinesLayer
BreakLines layer.
double m_edgeSize
Triangulation edges minimum size.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual const std::string & getDataSourceId() const
TINGenerationDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void setParams(const double &tolerance, const double &maxdist, const double &minedgesize, const std::string &atrz_iso, const std::string &atrz_pt)
It sets the parameters to generate TIN.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr