27 #include "../../attributefill/Enums.h" 28 #include "../../attributefill/Utils.h" 29 #include "../../attributefill/VectorToVectorOp.h" 30 #include "../../attributefill/VectorToVectorMemory.h" 31 #include "../../core/filesystem/FileSystem.h" 32 #include "../../core/logger/Logger.h" 33 #include "../../core/translator/Translator.h" 34 #include "../../common/Exception.h" 35 #include "../../common/progress/ProgressManager.h" 36 #include "../../common/StringUtils.h" 37 #include "../../dataaccess/dataset/DataSetType.h" 38 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 39 #include "../../dataaccess/datasource/DataSourceInfo.h" 40 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 41 #include "../../dataaccess/datasource/DataSourceFactory.h" 42 #include "../../dataaccess/datasource/DataSourceManager.h" 43 #include "../../dataaccess/utils/Utils.h" 44 #include "../../datatype/Enums.h" 45 #include "../../datatype/Property.h" 46 #include "../../geometry/GeometryProperty.h" 47 #include "../../maptools/AbstractLayer.h" 48 #include "../../qt/af/Utils.h" 49 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 50 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 51 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 52 #include "../../qt/widgets/Utils.h" 53 #include "../../qt/widgets/utils/DoubleListWidget.h" 54 #include "../../qt/widgets/utils/FileDialog.h" 55 #include "../../statistics/core/Utils.h" 56 #include "../Config.h" 58 #include "ui_VectorToVectorDialogForm.h" 62 #include <QDialogButtonBox> 63 #include <QFileDialog> 65 #include <QListWidget> 66 #include <QListWidgetItem> 67 #include <QMessageBox> 69 #if QT_VERSION >= 0x050000 70 #include <QStandardPaths> 72 #include <QDesktopServices> 76 #include <boost/algorithm/string.hpp> 77 #include <boost/filesystem.hpp> 78 #include <boost/lexical_cast.hpp> 79 #include <boost/uuid/random_generator.hpp> 80 #include <boost/uuid/uuid_io.hpp> 84 m_ui(new
Ui::VectorToVectorDialogForm),
86 m_outputAttributes(
std::vector<
std::string>()),
96 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"attributefill-vector2vector-hint").pixmap(112,48));
97 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
115 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
116 m_ui->m_helpPushButton->setPageReference(
"plugins/attributefill/attrfill_vector_to_vector.html");
125 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
129 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
130 if(dsType->hasGeom())
132 std::string layerName = it->get()->getTitle();
133 std::string layerId = it->get()->getId();
135 m_ui->m_toLayerComboBox->addItem(QString(layerName.c_str()), QVariant(layerId.c_str()));
136 m_ui->m_fromLayerComboBox->addItem(QString(layerName.c_str()), QVariant(layerId.c_str()));
141 if(
m_ui->m_fromLayerComboBox->count() > 1)
143 m_ui->m_fromLayerComboBox->setCurrentIndex(0);
145 m_ui->m_toLayerComboBox->setCurrentIndex(1);
160 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"\"From\" layer invalid!"));
168 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"\"To\" layer invalid!"));
172 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
174 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"Define a repository for the result."));
178 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
180 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"Define a name for the resulting layer."));
184 std::unique_ptr<te::da::DataSetType> fromSchema = fromLayer->getSchema();
185 std::unique_ptr<te::da::DataSet> fromData = fromLayer->getData();
188 std::unique_ptr<te::da::DataSetType> toSchema = fromLayer->getSchema();
189 std::unique_ptr<te::da::DataSet> toData = toLayer->getData();
192 std::string outDataSetName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
200 v2v->setInput(fromLayer, toLayer);
204 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
208 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"Output file already exists. Remove it or select a new name and try again."));
212 std::size_t idx = outDataSetName.find(
".");
213 if (idx != std::string::npos)
214 outDataSetName=outDataSetName.substr(0,idx);
216 std::string dsinfo(
"file://" + uri.string());
221 if (outSource->dataSetExists(outDataSetName))
223 QMessageBox::warning(
this, tr(
"VectorToVector"), 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."));
227 v2v->setOutput(outSource, outDataSetName);
230 boost::uuids::basic_random_generator<boost::mt19937> gen;
231 boost::uuids::uuid u = gen();
232 std::string id_ds = boost::uuids::to_string(u);
235 ds->setConnInfo(dsinfo);
236 ds->setTitle(uri.stem().string());
237 ds->setAccessDriver(
"OGR");
239 ds->setDescription(uri.string());
252 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"The selected output datasource can not be accessed."));
256 if (aux->dataSetExists(outDataSetName))
258 QMessageBox::warning(
this, tr(
"VectorToVector"), tr(
"Dataset already exists. Remove it or select a new name and try again."));
261 this->setCursor(Qt::WaitCursor);
263 v2v->setOutput(aux, outDataSetName);
280 m_outLayer->setSRID(toLayer->getSRID());
285 QMessageBox::warning(
this, tr(
"Vector To Vector"), e.
what());
288 catch(std::exception& e)
290 QMessageBox::warning(
this, tr(
"Vector To Vector"), e.what());
294 this->setCursor(Qt::ArrowCursor);
298 QString err(tr(
"Some errors occurred during execution."));
299 #ifdef TERRALIB_LOGGER_ENABLED 300 err.append(tr(
" The error log can be found at: "));
305 #if QT_VERSION >= 0x050000 306 userDataDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
308 userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
311 QString logfile(userDataDir);
312 logfile.append(
"/log/TerraLib.log");
315 #endif //TERRALIB_LOGGER_ENABLED 317 QMessageBox::warning(
this, tr(
"Vector to Vector"), err);
331 if(
m_ui->m_toLayerComboBox->count() <= 1 ||
m_ui->m_fromLayerComboBox->count() <= 1 )
334 int currentIndex =
m_ui->m_fromLayerComboBox->currentIndex();
336 if(currentIndex ==
m_ui->m_toLayerComboBox->currentIndex())
338 if(currentIndex == 0)
339 m_ui->m_toLayerComboBox->setCurrentIndex(1);
341 m_ui->m_toLayerComboBox->setCurrentIndex(0);
349 if(
m_ui->m_toLayerComboBox->count() <= 1 ||
m_ui->m_fromLayerComboBox->count() <= 1 )
352 int currentIndex =
m_ui->m_toLayerComboBox->currentIndex();
354 if(
m_ui->m_fromLayerComboBox->count() > 0 && currentIndex ==
m_ui->m_fromLayerComboBox->currentIndex())
356 if(currentIndex == 0)
357 m_ui->m_fromLayerComboBox->setCurrentIndex(1);
359 m_ui->m_fromLayerComboBox->setCurrentIndex(0);
362 std::unique_ptr<te::da::DataSetType> toSchema =
getCurrentToLayer()->getSchema();
364 std::vector<te::dt::Property*> props = toSchema->getProperties();
365 std::vector<te::dt::Property*> pkProps = toSchema->getPrimaryKey()->getProperties();
366 for(std::size_t i = 0; i < props.size(); ++i)
369 for(std::size_t j = 0; j < pkProps.size(); ++j)
371 if(props[i]->getName() == pkProps[j]->getName())
387 m_ui->m_selectAllComboBox->addItem(
"");
415 m_ui->m_rejectAllComboBox->addItem(
"");
446 std::string layerID =
m_ui->m_fromLayerComboBox->itemData(
m_ui->m_fromLayerComboBox->currentIndex(), Qt::UserRole).toString().toUtf8().data();
448 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
452 if(it->get()->getId() == layerID)
462 std::string layerID =
m_ui->m_toLayerComboBox->itemData(
m_ui->m_toLayerComboBox->currentIndex(), Qt::UserRole).toString().toUtf8().data();
464 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
468 if(it->get()->getId() == layerID)
478 if(item->text().isEmpty())
479 item->setSelected(
false);
484 QString text =
m_ui->m_selectAllComboBox->itemText(index);
485 Qt::MatchFlags flag = Qt::MatchEndsWith;
490 QList<QListWidgetItem *> listFound;
491 listFound =
m_ui->m_statisticsListWidget->findItems(text, flag);
493 for(
int i=0; i < listFound.size(); ++i)
495 std::vector<std::string> tokens;
498 if(tokens.size() < 2)
501 QString token(tokens[1].c_str());
503 if(token.trimmed() == text)
504 listFound.at(i)->setSelected(
true);
507 m_ui->m_rejectAllComboBox->setCurrentIndex(0);
512 QString text =
m_ui->m_selectAllComboBox->itemText(index);
513 Qt::MatchFlags flag = Qt::MatchEndsWith;
518 QList<QListWidgetItem *> listFound;
519 listFound =
m_ui->m_statisticsListWidget->findItems(text, flag);
521 for(
int i=0; i < listFound.size(); ++i)
523 std::vector<std::string> tokens;
526 if(tokens.size() < 2)
529 QString token(tokens[1].c_str());
531 if(token.trimmed() == text)
532 listFound.at(i)->setSelected(
false);
535 m_ui->m_selectAllComboBox->setCurrentIndex(0);
540 m_ui->m_newLayerNameLineEdit->clear();
541 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
545 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
547 if(dsPtrList.empty())
550 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
552 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
561 m_ui->m_newLayerNameLineEdit->clear();
562 m_ui->m_repositoryLineEdit->clear();
570 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
574 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
575 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
578 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
583 std::map<std::string, std::vector<te::attributefill::OperationType> > result;
587 std::vector<std::string> props;
588 for(
int i = 0; i <
m_ui->m_statisticsListWidget->count(); ++i)
590 QListWidgetItem* item =
m_ui->m_statisticsListWidget->item(i);
592 if(!item->isSelected())
595 std::string itemText = item->text().toUtf8().data();
597 std::vector<std::string> tokens;
600 std::string propName = tokens[0];
601 boost::trim(propName);
605 if(std::find(props.begin(), props.end(), propName) != props.end())
607 std::vector<te::attributefill::OperationType> vec;
608 vec.push_back(operationType);
610 result[propName] = vec;
614 result[propName].push_back(operationType);
623 m_ui->m_selectAllComboBox->setCurrentIndex(0);
624 m_ui->m_rejectAllComboBox->setCurrentIndex(0);
625 m_ui->m_statisticsListWidget->clear();
629 std::unique_ptr<te::da::DataSetType> dst = layer->getSchema();
630 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
636 std::string geomPropName = layer->getGeomPropertyName();
638 if(geomPropName.empty())
646 std::vector<te::dt::Property*> props = dst->getProperties();
648 for(std::size_t i = 0; i < props.size(); ++i)
654 int propertyType = prop->
getType();
658 m_ui->m_statisticsListWidget->addItem(item);
664 m_ui->m_statisticsListWidget->addItem(item);
668 m_ui->m_statisticsListWidget->addItem(item);
672 m_ui->m_statisticsListWidget->addItem(item);
676 m_ui->m_statisticsListWidget->addItem(item);
680 m_ui->m_statisticsListWidget->addItem(item);
686 m_ui->m_statisticsListWidget->addItem(item);
690 m_ui->m_statisticsListWidget->addItem(item);
694 m_ui->m_statisticsListWidget->addItem(item);
698 m_ui->m_statisticsListWidget->addItem(item);
702 m_ui->m_statisticsListWidget->addItem(item);
706 m_ui->m_statisticsListWidget->addItem(item);
710 m_ui->m_statisticsListWidget->addItem(item);
714 m_ui->m_statisticsListWidget->addItem(item);
718 m_ui->m_statisticsListWidget->addItem(item);
722 m_ui->m_statisticsListWidget->addItem(item);
726 m_ui->m_statisticsListWidget->addItem(item);
730 m_ui->m_statisticsListWidget->addItem(item);
734 m_ui->m_statisticsListWidget->addItem(item);
738 m_ui->m_statisticsListWidget->addItem(item);
742 m_ui->m_statisticsListWidget->addItem(item);
749 m_ui->m_statisticsListWidget->addItem(item);
757 m_ui->m_statisticsListWidget->addItem(item);
761 m_ui->m_statisticsListWidget->addItem(item);
765 m_ui->m_statisticsListWidget->addItem(item);
770 m_ui->m_statisticsListWidget->addItem(item);
774 m_ui->m_statisticsListWidget->addItem(item);
778 m_ui->m_statisticsListWidget->addItem(item);
786 m_ui->m_statisticsListWidget->addItem(item);
790 m_ui->m_statisticsListWidget->addItem(item);
795 m_ui->m_statisticsListWidget->addItem(item);
799 m_ui->m_statisticsListWidget->addItem(
"");
802 int lastRow =
m_ui->m_statisticsListWidget->count() - 1;
803 delete m_ui->m_statisticsListWidget->item(lastRow);
878 std::unique_ptr<te::da::DataSetType> toSchema = toLayer->getSchema();
903 std::unique_ptr<te::da::DataSetType> toSchema = toLayer->getSchema();
905 std::vector<te::dt::Property*> props = toSchema->getProperties();
906 std::vector<te::dt::Property*> pkProps = toSchema->getPrimaryKey()->getProperties();
908 std::vector<std::string> inputNames;
909 std::vector<std::string> outputNames;
910 for(std::size_t i = 0; i < props.size(); ++i)
913 for(std::size_t j = 0; j < pkProps.size(); ++j)
915 if(props[i]->getName() == pkProps[j]->getName())
926 outputNames.push_back(props[i]->getName());
930 inputNames.push_back(props[i]->getName());
936 dialog->setWindowTitle(tr(
"Vector To Vector"));
938 QBoxLayout* vLayout =
new QBoxLayout(QBoxLayout::TopToBottom, dialog);
945 vLayout->addWidget(d);
947 QDialogButtonBox* bbox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
948 connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
949 connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
950 vLayout->addWidget(bbox);
952 int res = dialog->exec();
954 if(res == QDialog::Accepted)
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void onTargetFileToolButtonPressed()
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.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
void setStatisticalSummary()
boost::shared_ptr< DataSource > DataSourcePtr
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
void onOkPushButtonClicked()
virtual const char * what() const
It outputs the exception message.
bool isValidPropertyType(const int type)
void onTargetDatasourceToolButtonPressed()
bool isPoint(te::gm::GeomType type)
bool isNumProperty(const int type)
te::map::AbstractLayerPtr getCurrentToLayer()
te::map::AbstractLayerPtr getCurrentFromLayer()
std::map< std::string, std::vector< te::attributefill::OperationType > > getSelections()
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
VectorToVectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void onToLayerComboBoxCurrentIndexChanged(int index)
static te::dt::Date ds(2010, 01, 01)
void setFunctionsByLayer(te::map::AbstractLayerPtr layer)
It models a property definition.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
void onStatisticsListWidgetItemPressed(QListWidgetItem *item)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void onFromLayerComboBoxCurrentIndexChanged(int index)
std::unique_ptr< Ui::VectorToVectorDialogForm > m_ui
User interface.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
bool isPolygon(te::gm::GeomType type)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::vector< std::string > m_outputAttributes
void onRejectAllComboBoxChanged(int index)
int getType() const
It returns the property data type.
te::map::AbstractLayerPtr m_outLayer
void onSelectAllComboBoxChanged(int index)
te::gm::GeomType getCurrentToLayerGeomType()
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
A class that represents a data source component.
bool isClassType(const int type)
TEATTRIBUTEFILLEXPORT std::string GetOperationFullName(const int &e)
Gets the full name of the operation as string.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
OperationType
Define grouping operations type.
Raster to vector attributefill dialog.
void onCancelPushButtonClicked()
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
void onSelectAttrToolButtonPressed()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.