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 "../../common/UnitsOfMeasureManager.h" 33 #include "../../dataaccess/dataset/DataSetType.h" 34 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 35 #include "../../dataaccess/datasource/DataSourceInfo.h" 36 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 37 #include "../../dataaccess/datasource/DataSourceManager.h" 38 #include "../../dataaccess/datasource/DataSourceFactory.h" 39 #include "../../dataaccess/utils/Utils.h" 40 #include "../../datatype/Enums.h" 41 #include "../../datatype/Property.h" 42 #include "../../geometry/Geometry.h" 43 #include "../../geometry/GeometryProperty.h" 44 #include "../../maptools/AbstractLayer.h" 45 #include "../../maptools/DataSetLayer.h" 46 #include "../../memory/DataSet.h" 47 #include "../../memory/DataSetItem.h" 48 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 49 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 50 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 51 #include "../../qt/widgets/srs/SRSManagerDialog.h" 52 #include "../../qt/widgets/utils/FileDialog.h" 53 #include "../../srs/SpatialReferenceSystemManager.h" 54 #include "../Exception.h" 55 #include "../BufferMemory.h" 57 #include "../BufferOp.h" 58 #include "../BufferQuery.h" 59 #include "ui_BufferDialogForm.h" 63 #include <QFileDialog> 65 #include <QListWidget> 66 #include <QListWidgetItem> 67 #include <QMessageBox> 74 #include <boost/algorithm/string.hpp> 75 #include <boost/filesystem.hpp> 76 #include <boost/lexical_cast.hpp> 77 #include <boost/uuid/random_generator.hpp> 78 #include <boost/uuid/uuid_io.hpp> 82 m_ui(new
Ui::BufferDialogForm),
84 m_selectedLayer(nullptr)
90 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-buffer-hint").pixmap(112,48));
92 QSize iconSize(96, 48);
94 m_ui->m_withoutBoundRadioButton->setIconSize(iconSize);
95 m_ui->m_withoutBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-without-boundaries"));
97 m_ui->m_withBoundRadioButton->setIconSize(iconSize);
98 m_ui->m_withBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-with-boundaries"));
100 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
101 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
104 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
105 m_ui->m_fixedDistanceLineEdit->setValidator(
new QDoubleValidator(
this));
116 connect(
m_ui->m_ruleOnlyInRadioButton, SIGNAL(toggled(
bool)),
this, SLOT(
onRuleInToggled()));
126 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
127 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_buffer.html");
136 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
140 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
141 if(dsType.get() && dsType->hasGeom())
142 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
149 for(
int i=1; i <= 10; ++i)
150 m_ui->m_levelsNumComboBox->addItem(QString::number(i));
155 m_ui->m_fromAttDistanceComboBox->clear();
157 for(std::size_t i = 0; i < properties.size(); ++i)
171 m_ui->m_fromAttDistanceComboBox->addItem(properties[i]->getName().c_str());
174 if(
m_ui->m_fromAttDistanceComboBox->count() > 0)
176 m_ui->m_fromAttRadioButton->setEnabled(
true);
179 m_ui->m_fromAttRadioButton->setEnabled(
false);
184 if(
m_ui->m_ruleInOutRadioButton->isChecked())
186 else if(
m_ui->m_ruleOnlyOutRadioButton->isChecked())
194 if(
m_ui->m_withoutBoundRadioButton->isChecked())
207 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
208 std::string layerID =
m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
212 if(layerID == it->get()->getId())
216 std::unique_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
218 if(schema->size() == 0)
224 const std::vector<te::dt::Property*>& properties = schema->getProperties();
238 m_ui->m_ruleInOutRadioButton->setEnabled(
true);
239 m_ui->m_ruleOnlyInRadioButton->setEnabled(
true);
240 m_ui->m_ruleOnlyOutRadioButton->setEnabled(
true);
242 m_ui->m_ruleInOutRadioButton->setChecked(
true);
244 m_ui->m_okPushButton->setEnabled(
true);
249 m_ui->m_ruleInOutRadioButton->setDisabled(
true);
250 m_ui->m_ruleOnlyInRadioButton->setDisabled(
true);
252 m_ui->m_ruleOnlyOutRadioButton->setEnabled(
true);
253 m_ui->m_ruleOnlyOutRadioButton->setChecked(
true);
256 m_ui->m_okPushButton->setEnabled(
true);
261 m_ui->m_ruleInOutRadioButton->setDisabled(
true);
262 m_ui->m_ruleOnlyInRadioButton->setDisabled(
true);
264 m_ui->m_ruleOnlyOutRadioButton->setEnabled(
true);
265 m_ui->m_ruleOnlyOutRadioButton->setChecked(
true);
268 m_ui->m_okPushButton->setEnabled(
true);
272 QMessageBox::information(
this,
"Buffer",
"The geometry type ("+ QString(
te::gm::Geometry::getGeomTypeString(geomProp->getGeometryType()).c_str()) +
") is not supported to execute this operation.");
273 m_ui->m_okPushButton->setDisabled(
true);
284 std::string unitSymbol = unitPtr.get()->getSymbol();
285 m_ui->m_unitLabel->setText(unitSymbol.c_str());
291 m_ui->m_layerSRIDLabel->setText(
"No SRS defined");
292 m_ui->m_resSRIDLabel->setText(
"No SRS defined");
303 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
304 m_ui->m_fromAttDistanceComboBox->setEnabled(
false);
309 m_ui->m_fromAttDistanceComboBox->setEnabled(
true);
310 m_ui->m_fixedDistanceLineEdit->setEnabled(
false);
316 srsDialog.setWindowTitle(tr(
"Choose the SRS"));
318 if(srsDialog.exec() == QDialog::Rejected)
325 m_ui->m_resSRIDLabel->setText(
"No SRS defined");
330 m_ui->m_resSRIDLabel->setText(name.c_str());
333 std::string unitSymbol = unitPtr.get()->getSymbol();
334 m_ui->m_unitLabel->setText(unitSymbol.c_str());
340 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
358 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer_only-outside").pixmap(150,60));
361 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-line-outside").pixmap(150,60));
364 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-point-outside").pixmap(150,60));
369 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-only-inside").pixmap(150,60));
374 m_ui->m_copyColumnsCheckBox->setChecked(
false);
375 m_ui->m_copyColumnsCheckBox->setEnabled(
false);
380 m_ui->m_copyColumnsCheckBox->setEnabled(
true);
385 m_ui->m_newLayerNameLineEdit->clear();
386 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
390 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
392 if(dsPtrList.empty())
395 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
397 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
406 m_ui->m_newLayerNameLineEdit->clear();
407 m_ui->m_repositoryLineEdit->clear();
415 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
419 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
420 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
423 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
428 if(
m_ui->m_layersComboBox->currentText().isEmpty())
430 QMessageBox::information(
this,
"Buffer",
"Select an input layer.");
438 QMessageBox::information(
this,
"Buffer",
"Can not execute this operation on this type of layer.");
444 if(
m_ui->m_onlySelectedCheckBox->isChecked())
449 QMessageBox::information(
this,
"Buffer",
"Select the layer objects to perform the buffer operation.");
456 if (!inDataSource.get())
458 QMessageBox::information(
this,
"Buffer",
"The selected input data source can not be accessed.");
464 int attributePosition = -1;
466 if(
m_ui->m_fixedAtRadioButton->isChecked())
468 distance =
m_ui->m_fixedDistanceLineEdit->text().toDouble();
471 QMessageBox::information(
this,
"Buffer",
"Fixed distance value should be greater than 0.");
478 std::string propDistance;
479 int i =
m_ui->m_fromAttDistanceComboBox->currentIndex();
480 propDistance =
m_ui->m_fromAttDistanceComboBox->itemText(i).toUtf8().data();
482 std::unique_ptr<const te::map::LayerSchema> schema(
m_selectedLayer->getSchema());
489 int reply = QMessageBox::question(
this, tr(
"Buffer"),
490 tr(
"The buffer operation will be calculated with Geographic SRS. Would you like to continue?"),
491 QMessageBox::No, QMessageBox::Yes);
493 if(reply == QMessageBox::No)
500 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
502 QMessageBox::information(
this,
"Buffer",
"Select a repository for the resulting layer.");
507 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
509 QMessageBox::information(
this,
"Buffer",
"Define a name for the resulting layer.");
515 bool copyInputColumns =
m_ui->m_copyColumnsCheckBox->isChecked();
516 int levels =
m_ui->m_levelsNumComboBox->currentText().toInt();
517 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
528 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
532 QMessageBox::information(
this,
"Buffer",
"Output file already exists. Remove it or select a new name and try again.");
536 std::size_t idx = outputdataset.find(
".");
537 if(idx != std::string::npos)
538 outputdataset = outputdataset.substr(0,idx);
540 std::string dsinfo(
"file://");
541 dsinfo += uri.string();
546 if(dsOGR->dataSetExists(outputdataset))
548 QMessageBox::information(
this,
"Buffer",
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
556 this->setCursor(Qt::WaitCursor);
573 bufferOp->
setOutput(dsOGR, outputdataset);
574 bufferOp->
setParams(distance,
m_newSRID, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, attributePosition);
579 res = bufferOp->
run();
584 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
591 boost::uuids::basic_random_generator<boost::mt19937> gen;
592 boost::uuids::uuid u = gen();
593 std::string
id = boost::uuids::to_string(u);
596 ds->setConnInfo(dsinfo);
597 ds->setTitle(uri.stem().string());
598 ds->setAccessDriver(
"OGR");
600 ds->setDescription(uri.string());
613 QMessageBox::information(
this,
"Buffer",
"The selected output datasource can not be accessed.");
616 if (aux->dataSetExists(outputdataset))
618 QMessageBox::information(
this,
"Buffer",
"Dataset already exists. Remove it or select a new name and try again. ");
621 this->setCursor(Qt::WaitCursor);
643 bufferOp->setInput(inDataSource, dsLayer->
getDataSetName(), std::move(converter), oidSet);
644 bufferOp->setOutput(aux, outputdataset);
645 bufferOp->setParams(distance,
m_newSRID, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, attributePosition);
647 if (!bufferOp->paramsAreValid())
650 res = bufferOp->run();
654 this->setCursor(Qt::ArrowCursor);
655 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
670 catch(
const std::exception& e)
672 this->setCursor(Qt::ArrowCursor);
673 QMessageBox::information(
this,
"Buffer", e.what());
675 std::string str =
"Vector Processing - Buffer - ";
682 this->setCursor(Qt::ArrowCursor);
te::map::AbstractLayerPtr m_selectedLayer
Layer used for buffer.
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setAttributesForDistance(std::vector< te::dt::Property * > properties)
std::vector< te::dt::Property * > m_properties
Properties related to the selected Layer.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
BufferDialog(QWidget *parent=0, Qt::WindowFlags f=0)
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void onFixedDistanceToggled()
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
virtual bool run()=0
It executes the operation.
void onAttDistanceToggled()
void onOkPushButtonClicked()
boost::shared_ptr< DataSetType > DataSetTypePtr
std::unique_ptr< Ui::BufferDialogForm > m_ui
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
The boundaries between buffers will not be dissolved.
An abstract class to compute the buffer memory and buffer query operation.
A dialog buffer operation.
A class that models the description of a dataset.
void onLayerComboBoxChanged(int index)
virtual const char * what() const
It outputs the exception message.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
void setParams(const double &distance, const int &newSrid, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels, const int &attributePosition=-1)
It sets the input parameters that will be consumed to execute the operation.
void onCancelPushButtonClicked()
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
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
It sets the input data will be calculated.
int m_newSRID
newSRID to compure buffer Area.
void onTargetFileToolButtonPressed()
An converter for DataSetType.
The buffer is generated only outside of the polygons.
void onSrsToolButtonClicked()
static SpatialReferenceSystemManager & 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 setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
The buffer is generated only inside of the polygons.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onWithBoundToggled()
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
virtual bool paramsAreValid()
It verifies if the parameters are valid.
bool IsProjectionLatLong(const int &srid)
A concrete class to compute the buffer operation.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the output parameters that will be used to persist operation result.
bool supportsSpatialSQLDialect() const
Utility functions for the data access module.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
The buffer is generated Inside and outside of the polygons.
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
const std::string & getDataSetName() const
void onRuleInOutToggled()
bool supportsPreparedQueryAPI() const
te::map::AbstractLayerPtr m_outputLayer
Generated Layer.
#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.
void onTargetDatasourceToolButtonPressed()
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
A layer with reference to a dataset.
static std::string getGeomTypeString(const int &gId)
It returns the TerraLib geometry type string given a type id.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::map::AbstractLayerPtr getLayer()
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
A concrete class to compute the buffer operation.
virtual const std::string & getDataSourceId() const
void onWithoutBoundToggled()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
The boundaries between buffers will be dissolved.