28 #include "../../../../common/STLUtils.h" 29 #include "../../../../dataaccess/datasource/DataSourceFactory.h" 30 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h" 31 #include "../../../../dataaccess/datasource/DataSourceManager.h" 32 #include "../../../../dataaccess/datasource/DataSourceTransactor.h" 33 #include "../../../../dataaccess/dataset/ObjectIdSet.h" 34 #include "../../../../dataaccess/utils/Utils.h" 35 #include "../../../../datatype/Utils.h" 36 #include "../../../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 37 #include "../../../../qt/widgets/property/NewPropertyWidget.h" 38 #include "../../layer/utils/DataSet2Layer.h" 40 #include "ui_SaveSelectedObjectsWidgetForm.h" 43 #include <QFileDialog> 44 #include <QMessageBox> 47 #include <boost/filesystem.hpp> 48 #include <boost/lexical_cast.hpp> 49 #include <boost/uuid/random_generator.hpp> 50 #include <boost/uuid/uuid_io.hpp> 55 m_ui(new
Ui::SaveSelectedObjectsWidgetForm)
59 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
80 QString msg = tr(
"Invalid layer selected!");
81 QMessageBox::warning(
this,
"Save layer as:", msg);
97 m_ui->m_layerNameLineEdit->setText(QString(
m_layer->getDataSetName().c_str()));
100 m_ui->m_layerSRIDLabel->setText(QString(boost::lexical_cast<std::string>(
m_srid).c_str()));
108 m_ui->m_NumSelectedObjLabel->setText(QString(boost::lexical_cast<std::string>(num).c_str()));
114 std::unique_ptr<te::da::DataSourceTransactor> t = dataSource->
getTransactor();
116 std::map<std::string, std::string> options;
120 if (dataSource->
getType() ==
"OGR")
127 std::string name = dataSetType->
getName();
128 dataSource->
add(dataSetType->
getName(), dataSet, options);
135 t->createDataSet(dataSetType, options);
139 std::string name = dataSetType->
getName();
140 t->add(dataSetType->
getName(), dataSet, options);
151 catch (std::exception& e)
167 errorMessage =
"Select at least one object from selected layer.";
173 errorMessage =
"Define the data source first.";
177 if (
m_ui->m_newLayerNameLineEdit->text().isEmpty())
179 errorMessage =
"Layer name not defined.";
184 if (!inDataSource.get())
186 errorMessage =
"The selected input data source can not be accessed.";
190 std::string dsTypeName =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
194 std::unique_ptr<te::da::DataSet> dataSet = inDataSource->getDataSet(
m_layer->getTitle(),
m_oidSet);
196 std::map<std::string, std::string> nopt;
198 std::unique_ptr<te::map::LayerSchema> schema =
m_layer->getSchema();
200 std::vector<te::dt::Property*> propsVec = schema->getProperties();
202 for (std::size_t i = 0; i < propsVec.size(); ++i)
203 dsType->add(propsVec[i]->clone());
212 newPk->
setName(dsTypeName +
"_pk");
213 dsType->setPrimaryKey(newPk);
220 save(outputDataSource.get(), dataSet.get(), dsType.get());
233 m_ui->m_newLayerNameLineEdit->clear();
234 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
239 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
241 if (dsPtrList.size() <= 0)
244 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
246 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
252 outputDataSource->open();
259 m_ui->m_newLayerNameLineEdit->clear();
260 m_ui->m_repositoryLineEdit->clear();
262 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."), QString(), tr(
"Shapefile (*.shp *.SHP);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
264 if (fileName.isEmpty())
267 boost::filesystem::path outfile(fileName.toUtf8().data());
269 m_ui->m_repositoryLineEdit->setText(outfile.string().c_str());
271 m_ui->m_newLayerNameLineEdit->setText(outfile.leaf().string().c_str());
273 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
278 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
280 const std::string dsInfo(
"file://" + uri.string());
285 boost::uuids::basic_random_generator<boost::mt19937> gen;
286 boost::uuids::uuid u = gen();
287 std::string id_ds = boost::uuids::to_string(u);
290 dsInfoPtr->setConnInfo(dsInfo);
291 dsInfoPtr->setTitle(uri.stem().string());
292 dsInfoPtr->setAccessDriver(
"OGR");
293 dsInfoPtr->setType(
"OGR");
294 dsInfoPtr->setDescription(uri.string());
295 dsInfoPtr->setId(id_ds);
303 outputDataSource->open();
virtual void setName(const std::string &name)
It sets the constraint name.
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)
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
virtual void add(const std::string &datasetName, DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void setExpression(te::da::Expression *expression, bool isClauseIn)
It set the expression that can be used to retrieve the data set that contains the all indentified ele...
virtual std::string getType() const =0
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
Constraint * clone()
It returns a clone of the object.
std::size_t size() const
It returns the object id set size.
static te::dt::TimeDuration dt(20, 30, 50, 11)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A dataset is the unit of information manipulated by the data access module of TerraLib.
It describes a primary key (pk) constraint.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
A class that represents a data source component.
Expression * getExpressionByInClause(const std::string source="") const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.