27 #include "../../common/progress/ProgressManager.h" 28 #include "../../core/filesystem/FileSystem.h" 29 #include "../../core/logger/Logger.h" 30 #include "../../core/translator/Translator.h" 31 #include "../../common/STLUtils.h" 32 #include "../../dataaccess/dataset/DataSetType.h" 33 #include "../../dataaccess/dataset/DataSetTypeConverter.h" 34 #include "../../dataaccess/dataset/ObjectIdSet.h" 35 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 36 #include "../../dataaccess/datasource/DataSourceInfo.h" 37 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 38 #include "../../dataaccess/datasource/DataSourceFactory.h" 39 #include "../../dataaccess/datasource/DataSourceManager.h" 40 #include "../../dataaccess/utils/Utils.h" 41 #include "../../datatype/Enums.h" 42 #include "../../datatype/Property.h" 43 #include "../../geometry/GeometryProperty.h" 44 #include "../../maptools/AbstractLayer.h" 45 #include "../../qt/af/Utils.h" 46 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 47 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 48 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 49 #include "../../qt/widgets/utils/FileDialog.h" 50 #include "../Config.h" 51 #include "../Exception.h" 52 #include "../PolygonToLineMemory.h" 53 #include "../PolygonToLineOp.h" 54 #include "../PolygonToLineQuery.h" 56 #include "ui_PolygonToLineDialogForm.h" 59 #include <QFileDialog> 60 #include <QMessageBox> 64 #include <boost/algorithm/string.hpp> 65 #include <boost/filesystem.hpp> 66 #include <boost/uuid/random_generator.hpp> 67 #include <boost/uuid/uuid_io.hpp> 71 m_ui(new
Ui::PolygonToLineDialogForm),
73 m_selectedLayer(nullptr),
80 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-polygon-line-hint").pixmap(112,48));
81 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
93 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
94 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_polygonToLine.html");
103 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
107 std::unique_ptr<te::map::LayerSchema> layerSchema = it->get()->getSchema();
120 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
133 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
135 std::string layerID =
m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
139 if(layerID == it->get()->getId())
152 m_ui->m_newLayerNameLineEdit->clear();
153 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
157 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
159 if(dsPtrList.empty())
162 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
164 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
173 m_ui->m_newLayerNameLineEdit->clear();
174 m_ui->m_repositoryLineEdit->clear();
182 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
185 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
186 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
189 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
194 if(
m_ui->m_layersComboBox->count() == 0)
196 QMessageBox::information(
this,
"Polygon to line",
"Select input layer.");
203 QMessageBox::information(
this,
"Polygon to line",
"Can not execute this operation on this type of layer.");
207 if(
m_ui->m_onlySelectedCheckBox->isChecked())
212 QMessageBox::information(
this,
"Polygon to line",
"Select the layer objects to perform the polygon to line operation.");
218 if(!inDataSource.get())
220 QMessageBox::information(
this,
"Polygon to line",
"The selected input data source can not be accessed.");
224 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
226 QMessageBox::information(
this,
"Polygon to line",
"Define a repository for the result.");
230 std::string outputDataSet =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
231 if(outputDataSet.empty())
233 QMessageBox::information(
this,
"Polygon to line",
"Define a name for the resulting layer.");
246 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
249 QMessageBox::information(
this,
"Polygon to line",
"Output file already exists. Remove it or select a new name and try again.");
253 std::size_t idx = outputDataSet.find(
".");
254 if (idx != std::string::npos)
255 outputDataSet=outputDataSet.substr(0,idx);
257 std::string dsinfo(
"file://");
258 dsinfo += uri.string();
263 if (dsOGR->dataSetExists(outputDataSet))
265 QMessageBox::information(
this,
"Polygon to Line",
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
273 this->setCursor(Qt::WaitCursor);
286 pol2LineOp->
setOutput(dsOGR, outputDataSet);
291 res = pol2LineOp->
run();
295 this->setCursor(Qt::ArrowCursor);
297 QMessageBox::information(
this,
"Polygon to Line",
"Error: Error in operation.");
305 boost::uuids::basic_random_generator<boost::mt19937> gen;
306 boost::uuids::uuid u = gen();
307 std::string id_ds = boost::uuids::to_string(u);
310 ds->setConnInfo(dsinfo);
311 ds->setTitle(uri.stem().string());
312 ds->setAccessDriver(
"OGR");
314 ds->setDescription(uri.string());
328 QMessageBox::information(
this,
"Polygon to Line",
"The selected output datasource can not be accessed.");
332 if(dsOGR->dataSetExists(outputDataSet))
334 QMessageBox::information(
this,
"Polygon to Line",
"Dataset already exists. Remove ir or select a new name and try again.");
342 this->setCursor(Qt::WaitCursor);
354 pol2LineOp->
setOutput(dsOGR, outputDataSet);
359 res = pol2LineOp->
run();
365 this->setCursor(Qt::ArrowCursor);
366 QMessageBox::information(
this,
"Polygon to Line",
"Error in operation.");
377 catch(
const std::exception& e)
379 this->setCursor(Qt::ArrowCursor);
381 QMessageBox::information(
this,
"Polygon to Line", e.what());
383 std::string str =
"Vector Processing - Polygon to Line - ";
390 this->setCursor(Qt::ArrowCursor);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void onOkPushButtonClicked()
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.
A dialog for polygon to line operation.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
virtual const char * what() const
It outputs the exception message.
virtual bool paramsAreValid()
te::map::AbstractLayerPtr m_selectedLayer
Layer used for operation.
std::unique_ptr< Ui::PolygonToLineDialogForm > m_ui
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
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)
const QueryCapabilities & getQueryCapabilities() const
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
An converter for DataSetType.
te::map::AbstractLayerPtr m_outLayer
Resulting layer.
PolygonToLineDialog(QWidget *parent=0, Qt::WindowFlags f=0)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void onTargetFileToolButtonPressed()
void onLayerComboBoxChanged(int index)
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onCancelPushButtonClicked()
bool supportsSpatialSQLDialect() const
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::map::AbstractLayerPtr getLayer()
const std::string & getDataSetName() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
bool supportsPreparedQueryAPI() const
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
A class that represents a data source component.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
A layer with reference to a dataset.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual const std::string & getDataSourceId() const
void onTargetDatasourceToolButtonPressed()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr