27 #include "../../core/filesystem/FileSystem.h" 28 #include "../../core/logger/Logger.h" 29 #include "../../core/translator/Translator.h" 30 #include "../../common/progress/ProgressManager.h" 31 #include "../../common/STLUtils.h" 32 #include "../../dataaccess/dataset/DataSetType.h" 33 #include "../../dataaccess/dataset/ObjectIdSet.h" 34 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 35 #include "../../dataaccess/datasource/DataSourceInfo.h" 36 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 37 #include "../../dataaccess/datasource/DataSourceFactory.h" 38 #include "../../dataaccess/datasource/DataSourceManager.h" 39 #include "../../dataaccess/utils/Utils.h" 40 #include "../../datatype/Enums.h" 41 #include "../../datatype/Property.h" 42 #include "../../maptools/AbstractLayer.h" 43 #include "../../qt/af/Utils.h" 44 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 45 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 46 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 47 #include "../../qt/widgets/Utils.h" 48 #include "../AddressGeocodingOp.h" 49 #include "../Config.h" 50 #include "../Exception.h" 54 #include "ui_MainWindowDialogForm.h" 57 #include <QFileDialog> 58 #include <QMessageBox> 62 #include <boost/algorithm/string.hpp> 63 #include <boost/filesystem.hpp> 64 #include <boost/uuid/random_generator.hpp> 65 #include <boost/uuid/uuid_io.hpp> 69 m_ui(new
Ui::MainWindowDialogForm),
77 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"addressgeocoding-hint").pixmap(112,48));
78 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
79 m_ui->m_targetDataSourceAddressToolButton->setIcon(QIcon::fromTheme(
"datasource"));
80 m_ui->m_editAddressFileToolButton->setIcon(QIcon::fromTheme(
"preferences-system"));
81 m_ui->m_removeAddressFileToolButton->setIcon(QIcon::fromTheme(
"delete"));
102 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
103 m_ui->m_helpPushButton->setPageReference(
"plugins/addressgeocoding/addressgeocoding.html");
107 std::map<std::string, std::vector<std::string> >::iterator it =
m_mapFields.begin();
111 m_ui->m_inputAddressComboBox->addItem(QString(it->first.c_str()));
124 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
128 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
129 std::vector<te::dt::Property*> properties = dsType->getProperties();
130 for(std::size_t i = 0; i < properties.size(); ++i)
132 std::string name = properties[i]->getName();
133 if(name ==
"tsvector")
134 m_ui->m_inputLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
148 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
150 std::string layerID =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
154 if(layerID == it->get()->getId().c_str())
159 std::unique_ptr<te::da::DataSetType> dsType =
m_selectedLayer->getSchema();
160 std::vector<te::dt::Property*> propVec = dsType->getProperties();
162 m_ui->m_iLeftComboBox->clear();
163 m_ui->m_fLeftComboBox->clear();
164 m_ui->m_iRightComboBox->clear();
165 m_ui->m_fRightComboBox->clear();
167 m_ui->m_iLeftComboBox->addItem(
"");
168 m_ui->m_fLeftComboBox->addItem(
"");
169 m_ui->m_iRightComboBox->addItem(
"");
170 m_ui->m_fRightComboBox->addItem(
"");
174 for(std::size_t i = 0; i < propVec.size(); ++i)
176 type = propVec[i]->getType();
183 m_ui->m_iLeftComboBox->addItem(QString(propVec[i]->getName().c_str()));
184 m_ui->m_fLeftComboBox->addItem(QString(propVec[i]->getName().c_str()));
185 m_ui->m_iRightComboBox->addItem(QString(propVec[i]->getName().c_str()));
186 m_ui->m_fRightComboBox->addItem(QString(propVec[i]->getName().c_str()));
221 if(dlg.exec() == QDialog::Accepted)
225 m_ui->m_inputLayerComboBox->clear();
237 m_ui->m_editAddressFileToolButton->setEnabled(
false);
238 m_ui->m_removeAddressFileToolButton->setEnabled(
false);
244 std::map<std::string, std::vector<std::string> >::iterator it;
246 std::string value =
m_ui->m_inputAddressComboBox->itemText(index).toUtf8().data();
250 std::vector<std::string> vecFields = it->second;
254 for(std::size_t i = 0; i < vecFields.size(); ++i)
256 if(i != 0 && i != 2 && vecFields[i] !=
"")
264 m_ui->m_editAddressFileToolButton->setEnabled(
true);
265 m_ui->m_removeAddressFileToolButton->setEnabled(
true);
272 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open Textual File"),
te::qt::widgets::GetFilePathFromSettings(
"tabular"), tr(
"dBASE (*.dbf *.DBF);; Comma Separated Value (*.csv *.CSV)"),
273 0, QFileDialog::ReadOnly);
277 if (fileName.isEmpty())
285 if(dlg.exec() == QDialog::Accepted)
312 catch(
const std::exception& e)
314 QMessageBox::warning(
this, tr(
"Address Geocoding"), e.what());
325 std::map<std::string, std::vector<std::string> > mapFields;
327 std::map<std::string, std::vector<std::string> >::iterator it;
329 std::string value =
m_ui->m_inputAddressComboBox->currentText().toUtf8().data();
331 it = mapFields.find(value);
333 std::vector<std::string> vecFields = it->second;
342 if(dlg.exec() == QDialog::Accepted)
372 QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
374 sett.beginGroup(
"Address Geocoding");
376 sett.remove(
m_ui->m_inputAddressComboBox->currentText());
377 m_ui->m_inputAddressComboBox->removeItem(
m_ui->m_inputAddressComboBox->currentIndex());
384 m_ui->m_newLayerNameLineEdit->clear();
385 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
389 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
391 if(dsPtrList.size() <= 0)
394 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
396 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
405 m_ui->m_newLayerNameLineEdit->clear();
406 m_ui->m_repositoryLineEdit->clear();
408 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
409 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
411 if (fileName.isEmpty())
414 boost::filesystem::path outfile(fileName.toUtf8().data());
415 std::string aux = outfile.leaf().string();
416 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
417 aux = outfile.string();
418 m_ui->m_repositoryLineEdit->setText(aux.c_str());
421 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
428 QMessageBox::information(
this,
"Address Geocoding",
"Configure an input layer.");
434 QMessageBox::information(
this,
"Address Geocoding",
"Associates the number fields with attributes of input layer.");
440 QMessageBox::information(
this,
"Address Geocoding",
"Configure an input address.");
466 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
475 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
479 QMessageBox::information(
this,
"Address Geocoding",
"Output file already exists. Remove it or select a new name and try again.");
483 std::size_t idx = outputdataset.find(
".");
484 if (idx != std::string::npos)
485 outputdataset=outputdataset.substr(0,idx);
487 std::string dsinfo(
"file://" + uri.string());
490 outputDataSource->open();
491 if (outputDataSource->dataSetExists(outputdataset))
493 QMessageBox::information(
this,
"Address Geocoding",
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
497 this->setCursor(Qt::WaitCursor);
499 addGeoOp->setOutput(outputDataSource,
502 if (!addGeoOp->paramsAreValid())
505 res = addGeoOp->run();
509 this->setCursor(Qt::ArrowCursor);
510 outputDataSource->close();
511 QMessageBox::information(
this,
"Address Geocoding",
"Error: could not generate the address geocoding.");
514 outputDataSource->close();
519 boost::uuids::basic_random_generator<boost::mt19937> gen;
520 boost::uuids::uuid u = gen();
521 std::string id_ds = boost::uuids::to_string(u);
524 ds->setConnInfo(dsinfo);
525 ds->setTitle(uri.stem().string());
526 ds->setAccessDriver(
"OGR");
528 ds->setDescription(uri.string());
540 if (!outputDataSource)
542 QMessageBox::information(
this,
"Address Geocoding",
"The selected output datasource can not be accessed.");
546 if (outputDataSource->dataSetExists(outputdataset))
548 QMessageBox::information(
this,
"Address Geocoding",
"Dataset already exists. Remove it or select a new name and try again.");
551 this->setCursor(Qt::WaitCursor);
553 addGeoOp->setOutput(outputDataSource,
556 if (!addGeoOp->paramsAreValid())
559 res = addGeoOp->run();
565 this->setCursor(Qt::ArrowCursor);
566 outputDataSource->close();
567 QMessageBox::information(
this,
"Address Geocoding",
"Error: could not generate the address geocoding.");
570 outputDataSource->close();
583 catch(
const std::exception& e)
585 this->setCursor(Qt::ArrowCursor);
587 QMessageBox::information(
this,
"Address Geocoding", e.what());
593 this->setCursor(Qt::ArrowCursor);
605 QSettings sett(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
607 sett.beginGroup(
"Address Geocoding");
608 QStringList lst = sett.childGroups();
610 QStringList::iterator it;
612 for(it=lst.begin(); it != lst.end(); ++it)
618 std::vector<std::string> vecFields;
620 std::string fileName = sett.value(
"fileName").toString().toUtf8().data();
621 vecFields.push_back(sett.value(
"filePath").toString().toUtf8().data());
622 vecFields.push_back(sett.value(
"neighborhood").toString().toUtf8().data());
623 vecFields.push_back(sett.value(
"number").toString().toUtf8().data());
624 vecFields.push_back(sett.value(
"postalCode").toString().toUtf8().data());
625 vecFields.push_back(sett.value(
"streetName").toString().toUtf8().data());
626 vecFields.push_back(sett.value(
"streetTitle").toString().toUtf8().data());
627 vecFields.push_back(sett.value(
"streetType").toString().toUtf8().data());
629 mapFields.insert(std::pair<std::string, std::vector<std::string> >(fileName, vecFields));
638 if(QString(filePath.c_str()).isEmpty())
641 QFileInfo info(QString(filePath.c_str()));
645 std::string ogrInfo(
"connection_string=" + filePath);
646 std::string connInfo(
"file://" + filePath);
648 boost::filesystem::path uri(filePath);
649 std::string
file = uri.stem().string();
652 static boost::uuids::basic_random_generator<boost::mt19937> gen;
653 boost::uuids::uuid u = gen();
656 dsInfo->setConnInfo(connInfo);
657 dsInfo->setId(boost::uuids::to_string(u));
658 dsInfo->setTitle(filePath);
659 dsInfo->setDescription(
"");
660 dsInfo->setAccessDriver(
"OGR");
661 dsInfo->setType(
"OGR");
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
std::string m_addressFile
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
void onTargetDatasourceToolButtonPressed()
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
void onTargetFileToolButtonPressed()
std::unique_ptr< Ui::MainWindowDialogForm > m_ui
static te::dt::Date ds(2010, 01, 01)
void onFinalLeftComboBoxChanged(int index)
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
std::string m_initialLeft
std::vector< std::string > m_associatedProps
void onEditAddressToolButtonPressed()
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void onInitialRightComboBoxChanged(int index)
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onOkPushButtonClicked()
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void onRemoveAddressToolButtonPressed()
void onTargetFileAddressToolButtonPressed()
te::map::AbstractLayerPtr m_resultLayer
Generated Layer.
te::map::AbstractLayerPtr m_newColumnLayer
Layer used for tsVector column.
MainWindowDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void GetAddressFilePathToSettings(std::map< std::string, std::vector< std::string > > &mapFields)
void GetAddressDataSource(std::string fileName)
void onAddressComboBoxChanged(int index)
std::string m_streetNumber
void onLayerComboBoxChanged(int index)
void onCancelPushButtonClicked()
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
A class that represents a data source component.
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
A layer with reference to a dataset.
std::map< std::string, std::vector< std::string > > m_mapFields
void onConfigureLayerClicked()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
te::da::DataSourcePtr m_layerDataSource
virtual const std::string & getDataSourceId() const
std::string m_initialRight
void onInitialLeftComboBoxChanged(int index)
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 $
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::da::DataSourcePtr m_addressDataSource
te::map::AbstractLayerPtr m_selectedLayer
List of layers.
void onFinalRightComboBoxChanged(int index)