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/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 "../../geometry/GeometryProperty.h" 43 #include "../../maptools/AbstractLayer.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/FileDialog.h" 49 #include "../Config.h" 50 #include "../Exception.h" 51 #include "../LineToPolygonMemory.h" 52 #include "../LineToPolygonOp.h" 53 #include "../LineToPolygonQuery.h" 55 #include "ui_LineToPolygonDialogForm.h" 58 #include <QFileDialog> 59 #include <QMessageBox> 63 #include <boost/algorithm/string.hpp> 64 #include <boost/filesystem.hpp> 65 #include <boost/uuid/random_generator.hpp> 66 #include <boost/uuid/uuid_io.hpp> 70 m_ui(new
Ui::LineToPolygonDialogForm),
72 m_selectedLayer(nullptr),
79 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-line-polygon-hint").pixmap(112,48));
80 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
92 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
93 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_lineToPolygon.html");
102 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
106 std::unique_ptr<te::map::LayerSchema> layerSchema = it->get()->getSchema();
119 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
132 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
134 std::string layerID =
m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
138 if(layerID == it->get()->getId())
151 m_ui->m_newLayerNameLineEdit->clear();
152 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
156 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
158 if(dsPtrList.empty())
161 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
163 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
172 m_ui->m_newLayerNameLineEdit->clear();
173 m_ui->m_repositoryLineEdit->clear();
181 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,
"Line to polygon",
"Select input layer.");
203 QMessageBox::information(
this,
"Line to polygon",
"Can not execute this operation on this type of layer.");
207 if(
m_ui->m_onlySelectedCheckBox->isChecked())
212 QMessageBox::information(
this,
"Line to polygon",
"Select the layer objects to perform the polygon to line operation.");
218 if(!inDataSource.get())
220 QMessageBox::information(
this,
"Line to polygon",
"The selected input data source can not be accessed.");
224 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
226 QMessageBox::information(
this,
"Line to polygon",
"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,
"Line to polygon",
"Define a name for the resulting layer.");
246 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
249 QMessageBox::information(
this,
"Line to polygon",
"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,
"Line to polygon",
"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 line2polygonOp->
setParams(
m_ui->m_forceCloseCheckBox->isChecked());
287 line2polygonOp->
setOutput(dsOGR, outputDataSet);
292 res = line2polygonOp->
run();
296 this->setCursor(Qt::ArrowCursor);
298 QMessageBox::information(
this,
"Line to polygon",
"Error: Error in operation.");
303 delete line2polygonOp;
306 boost::uuids::basic_random_generator<boost::mt19937> gen;
307 boost::uuids::uuid u = gen();
308 std::string id_ds = boost::uuids::to_string(u);
311 ds->setConnInfo(dsinfo);
312 ds->setTitle(uri.stem().string());
313 ds->setAccessDriver(
"OGR");
315 ds->setDescription(uri.string());
328 QMessageBox::information(
this,
"Line to polygon",
"The selected output datasource can not be accessed.");
332 if(dsOGR->dataSetExists(outputDataSet))
334 QMessageBox::information(
this,
"Line to polygon",
"Dataset already exists. Remove ir or select a new name and try again.");
342 this->setCursor(Qt::WaitCursor);
354 line2polygonOp->
setParams(
m_ui->m_forceCloseCheckBox->isChecked());
355 line2polygonOp->
setOutput(dsOGR, outputDataSet);
360 res = line2polygonOp->
run();
362 delete line2polygonOp;
366 this->setCursor(Qt::ArrowCursor);
367 QMessageBox::information(
this,
"Line to polygon",
"Error in operation.");
378 catch(
const std::exception& e)
380 this->setCursor(Qt::ArrowCursor);
382 QMessageBox::information(
this,
"Line to polygon", e.what());
384 std::string str =
"Vector Processing - Line to polygon - ";
391 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.
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.
LineToPolygonDialog(QWidget *parent=0, Qt::WindowFlags f=0)
te::map::AbstractLayerPtr m_outLayer
Resulting layer.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
std::unique_ptr< Ui::LineToPolygonDialogForm > m_ui
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.
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 setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
void setParams(bool forceClose=false)
An converter for DataSetType.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
te::map::AbstractLayerPtr m_selectedLayer
Layer used for operation.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void onCancelPushButtonClicked()
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onOkPushButtonClicked()
void onLayerComboBoxChanged(int index)
void onTargetFileToolButtonPressed()
bool supportsSpatialSQLDialect() const
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
const std::string & getDataSetName() const
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
bool supportsPreparedQueryAPI() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
#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.
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
virtual bool paramsAreValid()
A dialog for line to polygon operation.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::map::AbstractLayerPtr getLayer()
void onTargetDatasourceToolButtonPressed()