27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/Translator.h"
30 #include "../../common/STLUtils.h"
31 #include "../../dataaccess/dataset/DataSetType.h"
32 #include "../../dataaccess/dataset/ObjectIdSet.h"
33 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../../dataaccess/datasource/DataSourceInfo.h"
35 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../dataaccess/utils/Utils.h"
39 #include "../../datatype/Enums.h"
40 #include "../../datatype/Property.h"
41 #include "../../geometry/GeometryProperty.h"
42 #include "../../maptools/AbstractLayer.h"
43 #include "../../postgis/Transactor.h"
44 #include "../../qt/af/Utils.h"
45 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
46 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
47 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
48 #include "../../qt/widgets/utils/DoubleListWidget.h"
49 #include "../../statistics/core/Utils.h"
50 #include "../Config.h"
51 #include "../Exception.h"
54 #include "ui_ConfigInputLayerDialogForm.h"
57 #include <QFileDialog>
58 #include <QGridLayout>
59 #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>
72 m_ui(new Ui::ConfigInputLayerDialogForm),
80 QGridLayout* displayLayout =
new QGridLayout(
m_ui->m_widget);
81 displayLayout->addWidget(
m_widget.get());
83 m_widget->setLeftLabel(
"Available Attributes");
84 m_widget->setRightLabel(
"Selected Attributes");
104 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
106 while(it != m_layers.end())
108 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
109 if(dsType->hasGeom())
115 m_ui->m_inputLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
124 return m_selectedLayer;
134 m_widget->clearInputValues();
135 m_widget->clearOutputValues();
137 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
138 std::string layerID = m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
140 while(it != m_layers.end())
142 if(layerID == it->get()->getId().c_str())
145 m_selectedLayer = selectedLayer;
146 std::auto_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
147 const std::vector<te::dt::Property*>& properties = schema->getProperties();
148 std::vector<std::string> propNames;
150 for(std::size_t i=0; i < properties.size(); ++i)
153 propNames.push_back(properties[i]->getName());
155 m_widget->setInputValues(propNames);
166 if(dlg.exec()!=QDialog::Accepted)
179 QMessageBox::information(
this,
"Help",
"Under development");
187 QMessageBox::information(
this,
"Address Geocoding",
"Can not execute this operation on this type of layer.");
192 if(!m_dataSource.get())
194 QMessageBox::information(
this,
"Address Geocoding",
"The selected input data source can not be accessed.");
197 m_selectedProps = m_widget->getOutputValues();
198 if(m_selectedProps.empty())
200 QMessageBox::information(
this,
"Address Geocoding",
"Select at least one attribute.");
205 std::auto_ptr<te::da::DataSetType> schema = m_selectedLayer->getSchema();
206 const std::vector<te::dt::Property*>& properties = schema->getProperties();
208 bool addNewColumn =
true;
209 for(std::size_t i = 0; i < properties.size(); ++i)
211 std::string name = properties[i]->getName();
212 if(name ==
"tsvector")
213 addNewColumn =
false;
217 if(addNewColumn ==
true)
219 std::auto_ptr<te::da::DataSourceTransactor> trans = m_dataSource->getTransactor();
220 std::string alterTable =
"ALTER TABLE "+ m_selectedLayer->getTitle() +
" ADD tsvector tsvector";
221 trans->execute(alterTable);
227 std::string updateTable =
"UPDATE " + m_selectedLayer->getTitle() +
" SET tsvector = to_tsvector('english', ";
229 for(std::size_t selProps = 0; selProps < m_selectedProps.size(); ++selProps)
232 updateTable +=
" "+ m_selectedProps[selProps];
234 updateTable +=
"||' '||"+ m_selectedProps[selProps];
239 m_dataSource->execute(updateTable);
242 unsigned dot = m_selectedLayer->getTitle().find_last_of(
".");
243 std::string table = m_selectedLayer->getTitle().substr(dot+1);
246 std::string dropIndex =
"DROP INDEX IF EXISTS " + table +
"_idx";
247 m_dataSource->execute(dropIndex);
250 std::string createIndex =
"CREATE INDEX "+ table +
"_idx ON "+ m_selectedLayer->getTitle() +
" USING GIN(tsvector)";
252 m_dataSource->execute(createIndex);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Associates address number.
boost::shared_ptr< DataSource > DataSourcePtr
const std::string & getDataSourceId() const
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
void setLayer(te::map::AbstractLayerPtr layer)
A layer with reference to a dataset.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr