30 #include "../../core/filesystem/FileSystem.h" 31 #include "../../core/logger/Logger.h" 32 #include "../../common/progress/ProgressManager.h" 33 #include "../../dataaccess/dataset/DataSet.h" 34 #include "../../dataaccess/dataset/DataSetType.h" 35 #include "../../dataaccess/dataset/DataSetTypeConverter.h" 36 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 37 #include "../../dataaccess/datasource/DataSourceInfo.h" 38 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 39 #include "../../dataaccess/datasource/DataSourceFactory.h" 40 #include "../../dataaccess/datasource/DataSourceManager.h" 41 #include "../../dataaccess/utils/Utils.h" 43 #include "../../geometry/GeometryProperty.h" 44 #include "../../geometry/Utils.h" 46 #include "../../maptools/AbstractLayer.h" 48 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 49 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 50 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 51 #include "../../qt/widgets/srs/SRSManagerDialog.h" 52 #include "../../qt/widgets/utils/FileDialog.h" 54 #include "../../srs/SpatialReferenceSystemManager.h" 56 #include "../Config.h" 57 #include "../Exception.h" 60 #include "ui_GeometricOpDialogForm.h" 62 #include "../GeometricOp.h" 63 #include "../GeometricOpMemory.h" 64 #include "../GeometricOpQuery.h" 70 #include <QFileDialog> 71 #include <QMessageBox> 74 #include <boost/algorithm/string.hpp> 75 #include <boost/filesystem.hpp> 76 #include <boost/uuid/random_generator.hpp> 77 #include <boost/uuid/uuid_io.hpp> 81 m_ui(new
Ui::GeometricOpDialogForm),
83 m_selectedLayer(nullptr)
88 QSize iconSize(32, 32);
90 m_ui->m_convexHullCheckBox->setIconSize(iconSize);
91 m_ui->m_convexHullCheckBox->setIcon(QIcon::fromTheme(
"vp-convex-hull-hint"));
93 m_ui->m_centroidCheckBox->setIconSize(iconSize);
94 m_ui->m_centroidCheckBox->setIcon(QIcon::fromTheme(
"vp-centroid-hint"));
96 m_ui->m_mbrCheckBox->setIconSize(iconSize);
97 m_ui->m_mbrCheckBox->setIcon(QIcon::fromTheme(
"vp-mbr-hint"));
99 m_ui->m_areaCheckBox->setIconSize(iconSize);
100 m_ui->m_areaCheckBox->setIcon(QIcon::fromTheme(
"vp-area-hint"));
102 m_ui->m_lineCheckBox->setIconSize(iconSize);
103 m_ui->m_lineCheckBox->setIcon(QIcon::fromTheme(
"vp-line-length-hint"));
105 m_ui->m_perimeterCheckBox->setIconSize(iconSize);
106 m_ui->m_perimeterCheckBox->setIcon(QIcon::fromTheme(
"vp-perimeter-hint"));
108 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
110 m_ui->m_srsToolButton->setIcon(QIcon::fromTheme(
"srs"));
112 connect(
m_ui->m_inputLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
114 connect(
m_ui->m_attributesComboBox, SIGNAL(currentIndexChanged(
int)),
this,
116 connect(
m_ui->m_byObjectRadioButton, SIGNAL(toggled(
bool)),
this,
118 connect(
m_ui->m_allLayerRadioButton, SIGNAL(toggled(
bool)),
this,
120 connect(
m_ui->m_byAttributeRadioButton, SIGNAL(toggled(
bool)),
this,
122 connect(
m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this,
124 connect(
m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this,
126 connect(
m_ui->m_okPushButton, SIGNAL(clicked()),
this,
128 connect(
m_ui->m_cancelPushButton, SIGNAL(clicked()),
this,
130 connect(
m_ui->m_srsToolButton, SIGNAL(clicked()),
this,
133 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
134 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_geometricOper.html");
137 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
146 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
150 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
151 if(dsType.get() && dsType->hasGeom())
153 m_ui->m_inputLayerComboBox->addItem(
154 QString(it->get()->getTitle().c_str()),
155 QVariant(it->get()->getId().c_str()));
173 return m_ui->m_convexHullCheckBox->isChecked();
178 return m_ui->m_centroidCheckBox->isChecked();
183 return m_ui->m_mbrCheckBox->isChecked();
188 return m_ui->m_areaCheckBox->isChecked();
193 return m_ui->m_lineCheckBox->isChecked();
198 return m_ui->m_perimeterCheckBox->isChecked();
215 m_ui->m_areaCheckBox->setEnabled(
false);
216 m_ui->m_lineCheckBox->setEnabled(
false);
217 m_ui->m_perimeterCheckBox->setEnabled(
false);
218 m_ui->m_byObjectRadioButton->setEnabled(
false);
219 m_ui->m_byAttributeRadioButton->setEnabled(
false);
220 m_ui->m_allLayerRadioButton->setChecked(
true);
230 m_ui->m_areaCheckBox->setEnabled(
false);
231 m_ui->m_lineCheckBox->setEnabled(
true);
232 m_ui->m_perimeterCheckBox->setEnabled(
false);
233 m_ui->m_byObjectRadioButton->setEnabled(
true);
234 m_ui->m_byAttributeRadioButton->setEnabled(
true);
235 m_ui->m_byObjectRadioButton->setChecked(
true);
238 m_ui->m_areaCheckBox->setEnabled(
true);
239 m_ui->m_lineCheckBox->setEnabled(
false);
240 m_ui->m_perimeterCheckBox->setEnabled(
true);
241 m_ui->m_byObjectRadioButton->setEnabled(
true);
242 m_ui->m_byAttributeRadioButton->setEnabled(
true);
243 m_ui->m_byObjectRadioButton->setChecked(
true);
251 if(
m_ui->m_byObjectRadioButton->isChecked())
253 if(
m_ui->m_allLayerRadioButton->isChecked())
255 if(
m_ui->m_byAttributeRadioButton->isChecked())
263 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
264 std::string layerID =
265 m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole)
270 m_ui->m_propertiesListWidget->clear();
271 m_ui->m_attributesComboBox->clear();
275 if(layerID == it->get()->getId())
280 std::unique_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
282 int srid = selectedLayer->getSRID();
290 m_ui->m_layerSRIDLabel->setText(
"No SRS defined");
292 if(schema->size() == 0)
295 const std::vector<te::dt::Property*>& properties = schema->getProperties();
297 for(
size_t i = 0; i < properties.size(); ++i)
299 type = properties[i]->getType();
311 m_ui->m_propertiesListWidget->addItem(
312 properties[i]->getName().c_str());
314 m_ui->m_attributesComboBox->addItem(properties[i]->getName().c_str());
325 if(
m_ui->m_byAttributeRadioButton->isChecked())
326 m_attribute =
m_ui->m_attributesComboBox->itemText(index).toUtf8().data();
333 m_ui->m_attributesComboBox->setEnabled(
false);
339 m_ui->m_attributesComboBox->setEnabled(
false);
345 m_ui->m_attributesComboBox->setEnabled(
true);
350 m_ui->m_newLayerNameLineEdit->clear();
351 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
355 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
357 if(dsPtrList.empty())
360 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
362 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
371 m_ui->m_newLayerNameLineEdit->clear();
372 m_ui->m_repositoryLineEdit->clear();
380 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
384 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
385 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
388 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
406 std::vector<std::string> geoProps;
407 QList<QListWidgetItem*> selection =
m_ui->m_propertiesListWidget->selectedItems();
408 for(
int i = 0; i < selection.size(); ++i)
409 geoProps.push_back(selection.at(i)->text().toUtf8().data());
436 QMessageBox::information(
this, tr(
"Geometric Operation"),
437 tr(
"Check at least one operation."));
447 int reply = QMessageBox::question(
this, tr(
"Geometric Operation"),
448 tr(
"The tabular operations will be calculated with Geographic SRS. Would you like to continue?"),
449 QMessageBox::No, QMessageBox::Yes);
451 if(reply == QMessageBox::No)
464 m_attribute =
m_ui->m_attributesComboBox->currentText().toUtf8().data();
467 std::string outputdataset =
468 m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
470 std::vector<std::string> outputDSetNames;
475 std::string path =
m_ui->m_repositoryLineEdit->text().toUtf8().data();
476 boost::filesystem::path uri(path);
478 bool ops_selected =
false;
482 std::vector<std::string> splitedName;
483 boost::split(splitedName, outputdataset, boost::is_any_of(
"."));
485 boost::filesystem::path uri_file(path +
"/" + splitedName[0] +
"_convex_hull.shp");
489 QMessageBox::information(
490 this, tr(
"Geometric Operation"),
491 tr(
"The convex hull output file already " 492 "exists. Remove it or select a new name and " 502 std::vector<std::string> splitedName;
503 boost::split(splitedName, outputdataset, boost::is_any_of(
"."));
505 boost::filesystem::path uri_file(path +
"/" + splitedName[0] +
"_centroid.shp");
509 QMessageBox::information(
510 this, tr(
"Geometric Operation"),
511 tr(
"The centroid output file already exists. " 512 "Remove it or select a new name and try " 522 std::vector<std::string> splitedName;
523 boost::split(splitedName, outputdataset, boost::is_any_of(
"."));
525 boost::filesystem::path uri_file(path +
"/" + splitedName[0] +
"_mbr.shp");
529 QMessageBox::information(
530 this, tr(
"Geometric Operation"),
531 tr(
"The mbr output file already exists. Remove " 532 "it or select a new name and try again."));
541 std::vector<std::string> splitedName;
542 boost::split(splitedName, outputdataset, boost::is_any_of(
"."));
544 boost::filesystem::path uri_file(path +
"/" + splitedName[0] +
".shp");
548 QMessageBox::information(
549 this, tr(
"Geometric Operation"),
550 tr(
"Output file already exists. Remove it or " 551 "select a new name and try again."));
557 std::size_t idx = outputdataset.find(
".");
558 if (idx != std::string::npos)
559 outputdataset=outputdataset.substr(0,idx);
561 std::string dsinfo(
"file://");
562 dsinfo += uri.string();
566 std::unique_ptr<te::da::DataSetTypeConverter> converter(
568 dsOGR->getCapabilities(),
569 dsOGR->getEncoding()));
574 this->setCursor(Qt::WaitCursor);
581 inDataSource->getCapabilities();
594 geomOp->
setOutput(std::move(dsOGR), outputdataset);
602 result = geomOp->
run();
606 this->setCursor(Qt::ArrowCursor);
607 QMessageBox::information(
608 this, tr(
"Geometric Operation"),
609 tr(
"Error: could not generate the operation, check the log file."));
619 boost::uuids::basic_random_generator<boost::mt19937> gen;
620 boost::uuids::uuid u = gen();
621 std::string
id = boost::uuids::to_string(u);
624 ds->setConnInfo(dsinfo);
625 ds->setTitle(uri.stem().string());
626 ds->setAccessDriver(
"OGR");
628 ds->setDescription(uri.string());
640 std::unique_ptr<te::da::DataSource> trgDs =
647 QMessageBox::information(
648 this, tr(
"Geometric Operation"),
649 tr(
"The selected output datasource can not be accessed."));
654 if(trgDs->dataSetExists(outputdataset))
656 QMessageBox::information(
657 this, tr(
"Geometric Operation"),
658 tr(
"Dataset already exists. Remove it or select " 659 "a new name and try again."));
664 std::unique_ptr<te::da::DataSetTypeConverter> converter(
666 trgDs->getCapabilities(),
667 trgDs->getEncoding()));
672 this->setCursor(Qt::WaitCursor);
678 inDataSource->getCapabilities();
691 geomOp->
setOutput(std::move(trgDs), outputdataset);
698 result = geomOp->
run();
702 this->setCursor(Qt::ArrowCursor);
703 QMessageBox::information(
704 this, tr(
"Geometric Operation"),
705 tr(
"Error: could not generate the operation."));
720 outDataSource->close();
721 outDataSource->open();
725 for(std::size_t i = 0; i < outputDSetNames.size(); ++i)
728 outDataSource->getDataSetType(outputDSetNames[i]).release());
733 catch(
const std::exception& e)
735 this->setCursor(Qt::ArrowCursor);
736 QMessageBox::information(
this, tr(
"Geometric Operation"), e.what());
738 #ifdef TERRALIB_LOGGER_ENABLED 739 std::string str =
"Geometric Operation - ";
747 this->setCursor(Qt::ArrowCursor);
760 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
762 if(srsDialog.exec() == QDialog::Rejected)
769 m_ui->m_resSRIDLabel->setText(
"No SRS defined");
774 m_ui->m_resSRIDLabel->setText(name.c_str());
A Qt dialog that allows users to run the basic geometric operations defined by VP module...
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
std::vector< te::map::AbstractLayerPtr > getOutLayer()
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
std::unique_ptr< Ui::GeometricOpDialogForm > m_ui
Qt Dialog Form.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
std::vector< std::string > GetOutputDSetNames()
boost::shared_ptr< DataSetType > DataSetTypePtr
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter)
The geographic operation Line.
boost::shared_ptr< DataSource > DataSourcePtr
std::string m_attribute
Properties related to the selected Layer to do the dissolve before operation.
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
The geographic operation Minimum Bounding Rectangle.
void setParams(std::vector< std::string > selectedProps, std::vector< te::vp::GeometricOperation > operations, te::vp::GeometricOpObjStrategy objStrategy, std::string attribute, int newSRID)
void onAttributeComboBoxChanged(int index)
virtual const char * what() const
It outputs the exception message.
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
void setOutput(std::unique_ptr< da::DataSource > outDsrc, std::string dsname)
void onTargetFileToolButtonPressed()
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::dt::Date ds(2010, 01, 01)
void onOkPushButtonClicked()
void onAllLayerOperationToggled()
const QueryCapabilities & getQueryCapabilities() const
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
GeometricOpObjStrategy
Defines the strategy used for the processing of the input geometries.
An converter for DataSetType.
te::map::AbstractLayerPtr m_selectedLayer
Selected layer to operation.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
The geographic operation Area.
void onCancelPushButtonClicked()
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
te::map::AbstractLayerPtr getInLayer()
GeometricOpDialog(QWidget *parent=0, Qt::WindowFlags f=0)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
Aggregate objects by attribute.
bool IsProjectionLatLong(const int &srid)
The geographic operation Perimeter.
bool supportsSpatialSQLDialect() const
Utility functions for the data access module.
The geographic operation Centroid.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
bool m_toFile
Flag to indicate if the output will be stored in a file.
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
const std::string & getDataSetName() const
std::vector< te::map::AbstractLayerPtr > m_outputLayer
Generated Layer.
void onLayerComboBoxChanged(int index)
std::vector< te::vp::GeometricOperation > m_ops
Operations selected to be executed.
void onSrsToolButtonClicked()
bool supportsPreparedQueryAPI() const
virtual bool paramsAreValid()
The geographic operation Convex Hull.
A class that represents a data source component.
void onAllObjectsToggled()
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
A layer with reference to a dataset.
void onAttributeOperationToggled()
te::vp::GeometricOpObjStrategy getObjectStrategy()
void enableOperations(te::gm::GeomType type)
All objects individually.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual const std::string & getDataSourceId() const
void onTargetDatasourceToolButtonPressed()
int m_newSRID
newSRID to compure tabular operations (Area, Perimeter, Line).
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr