27 #include "../../common/progress/ProgressManager.h"
28 #include "../../common/Translator.h"
29 #include "../../common/STLUtils.h"
30 #include "../../dataaccess/dataset/DataSetType.h"
31 #include "../../dataaccess/datasource/DataSourceInfo.h"
32 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
33 #include "../../dataaccess/datasource/DataSourceManager.h"
34 #include "../../dataaccess/datasource/DataSourceFactory.h"
35 #include "../../dataaccess/utils/Utils.h"
36 #include "../../datatype/Enums.h"
37 #include "../../datatype/Property.h"
38 #include "../../geometry/Geometry.h"
39 #include "../../geometry/GeometryProperty.h"
40 #include "../../maptools/AbstractLayer.h"
41 #include "../../maptools/DataSetLayer.h"
42 #include "../../memory/DataSet.h"
43 #include "../../memory/DataSetItem.h"
44 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
45 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
46 #include "../../srs/Config.h"
47 #include "../Config.h"
48 #include "../Exception.h"
49 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
52 #include "ui_BufferDialogForm.h"
53 #include "VectorProcessingConfig.h"
57 #include <QtCore/QList>
58 #include <QtCore/QSize>
59 #include <QtGui/QFileDialog>
60 #include <QtGui/QListWidget>
61 #include <QtGui/QListWidgetItem>
62 #include <QtGui/QMessageBox>
68 #include <boost/algorithm/string.hpp>
69 #include <boost/filesystem.hpp>
70 #include <boost/lexical_cast.hpp>
71 #include <boost/uuid/random_generator.hpp>
72 #include <boost/uuid/uuid_io.hpp>
76 m_ui(new Ui::BufferDialogForm),
84 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(VP_IMAGES
"/vp-buffer-hint").pixmap(112,48));
86 QSize iconSize(96, 48);
88 m_ui->m_withoutBoundRadioButton->setIconSize(iconSize);
89 m_ui->m_withoutBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-without-boundaries"));
91 m_ui->m_withBoundRadioButton->setIconSize(iconSize);
92 m_ui->m_withBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-with-boundaries"));
94 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
95 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
98 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
99 m_ui->m_fixedDistanceLineEdit->setValidator(
new QDoubleValidator(
this));
110 connect(
m_ui->m_ruleOnlyInRadioButton, SIGNAL(toggled(
bool)),
this, SLOT(
onRuleInToggled()));
120 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
121 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_buffer.html");
132 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
134 while(it != m_layers.end())
136 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
137 if(dsType->hasGeom())
138 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
145 for(
int i=1; i <= 10; ++i)
146 m_ui->m_levelsNumComboBox->addItem(QString::number(i));
151 m_ui->m_fromAttDistanceComboBox->clear();
153 for(std::size_t i = 0; i < properties.size(); ++i)
168 m_ui->m_fromAttDistanceComboBox->addItem(properties[i]->getName().c_str());
171 if(m_ui->m_fromAttDistanceComboBox->count() > 0)
176 m_ui->m_fromAttRadioButton->setEnabled(
false);
181 if(m_ui->m_ruleInOutRadioButton->isChecked())
183 else if(m_ui->m_ruleOnlyOutRadioButton->isChecked())
191 if(m_ui->m_withoutBoundRadioButton->isChecked())
199 return m_outputLayer;
204 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
205 std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toStdString();
207 while(it != m_layers.end())
209 if(layerID == it->get()->getId().c_str())
212 m_selectedLayer = selectedLayer;
213 std::auto_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
215 if(schema->size() == 0)
219 m_properties.clear();
221 const std::vector<te::dt::Property*>& properties = schema->getProperties();
224 setAttributesForDistance(m_properties);
235 m_ui->m_ruleInOutRadioButton->setDisabled(
true);
236 m_ui->m_ruleOnlyInRadioButton->setDisabled(
true);
237 m_ui->m_ruleOnlyOutRadioButton->setChecked(
true);
241 m_ui->m_ruleInOutRadioButton->setEnabled(
true);
242 m_ui->m_ruleOnlyInRadioButton->setEnabled(
true);
243 m_ui->m_ruleInOutRadioButton->setChecked(
true);
256 m_ui->m_layersComboBox->clear();
259 filteredLayers = m_layers;
261 std::list<te::map::AbstractLayerPtr>::iterator it = filteredLayers.begin();
263 while(it != filteredLayers.end())
265 if(it->get()->getSchema()->hasGeom())
266 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
273 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
274 m_ui->m_fromAttDistanceComboBox->setEnabled(
false);
279 m_ui->m_fromAttDistanceComboBox->setEnabled(
true);
280 m_ui->m_fixedDistanceLineEdit->setEnabled(
false);
285 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
290 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer_only-outside").pixmap(150,60));
295 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-only-inside").pixmap(150,60));
300 m_ui->m_copyColumnsCheckBox->setChecked(
false);
301 m_ui->m_copyColumnsCheckBox->setEnabled(
false);
306 m_ui->m_copyColumnsCheckBox->setEnabled(
true);
311 m_ui->m_newLayerNameLineEdit->clear();
312 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
316 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
318 if(dsPtrList.size() <= 0)
321 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
323 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
325 m_outputDatasource = *it;
332 m_ui->m_newLayerNameLineEdit->clear();
333 m_ui->m_repositoryLineEdit->clear();
335 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
336 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
338 if(fileName.isEmpty())
341 boost::filesystem::path outfile(fileName.toStdString());
342 std::string aux = outfile.leaf().string();
343 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
344 aux = outfile.string();
345 m_ui->m_repositoryLineEdit->setText(aux.c_str());
348 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
353 QMessageBox::information(
this,
"Help",
"Under development");
358 if(m_ui->m_layersComboBox->currentText().isEmpty())
360 QMessageBox::information(
this,
"Buffer",
"Select an input layer.");
368 QMessageBox::information(
this,
"Buffer",
"Can not execute this operation on this type of layer.");
373 if (!inDataSource.get())
375 QMessageBox::information(
this,
"Buffer",
"The selected input data source can not be accessed.");
380 double fixedDistance;
381 std::string propDistance =
"";
382 if(m_ui->m_fixedRadioButton->isChecked())
384 fixedDistance = m_ui->m_fixedDistanceLineEdit->text().toDouble();
385 if (fixedDistance <= 0)
387 QMessageBox::information(
this,
"Buffer",
"Fixed distance value should be greater than 0.");
394 int i = m_ui->m_fromAttDistanceComboBox->currentIndex();
395 propDistance = m_ui->m_fromAttDistanceComboBox->itemText(i).toStdString();
399 if(m_ui->m_repositoryLineEdit->text().isEmpty())
401 QMessageBox::information(
this,
"Buffer",
"Select a repository for the resulting layer.");
406 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
408 QMessageBox::information(
this,
"Buffer",
"Define a name for the resulting layer.");
412 int bufferPolygonRule = getPolygonRule();
413 int bufferBoundariesRule = getBoundariesRule();
414 bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
415 int levels = m_ui->m_levelsNumComboBox->currentText().toInt();
416 std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
428 boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
430 if(boost::filesystem::exists(uri))
432 QMessageBox::information(
this,
"Buffer",
"Output file already exists. Remove it or select a new name and try again.");
436 std::size_t idx = outputdataset.find(
".");
437 if(idx != std::string::npos)
438 outputdataset = outputdataset.substr(0,idx);
440 std::map<std::string, std::string> dsinfo;
441 dsinfo[
"URI"] = uri.string();
444 dsOGR->setConnectionInfo(dsinfo);
447 if(dsOGR->dataSetExists(outputdataset))
449 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.");
453 this->setCursor(Qt::WaitCursor);
457 bufferBoundariesRule,
468 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
473 boost::uuids::basic_random_generator<boost::mt19937> gen;
474 boost::uuids::uuid u = gen();
475 std::string
id = boost::uuids::to_string(u);
478 ds->setConnInfo(dsinfo);
479 ds->setTitle(uri.stem().string());
480 ds->setAccessDriver(
"OGR");
482 ds->setDescription(uri.string());
488 m_outputDatasource = ds;
495 QMessageBox::information(
this,
"Buffer",
"The selected output datasource can not be accessed.");
498 if (aux->dataSetExists(outputdataset))
500 QMessageBox::information(
this,
"Buffer",
"Dataset already exists. Remove it or select a new name and try again. ");
503 this->setCursor(Qt::WaitCursor);
507 bufferBoundariesRule,
516 this->setCursor(Qt::ArrowCursor);
517 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
528 m_outputLayer = converter(dt);
530 catch(
const std::exception& e)
532 this->setCursor(Qt::ArrowCursor);
533 QMessageBox::information(
this,
"Buffer", e.what());
539 this->setCursor(Qt::ArrowCursor);
void onAttDistanceToggled()
void onRuleInOutToggled()
A layer with reference to a dataset.
const std::string & getDataSetName() const
void onHelpPushButtonClicked()
void onFixedDistanceToggled()
A dialog for selecting a data source.
void onWithoutBoundToggled()
void onFilterLineEditTextChanged(const QString &text)
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
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...
void setAttributesForDistance(std::vector< te::dt::Property * > properties)
std::list< te::map::AbstractLayerPtr > GetFilteredLayers(std::string text, std::list< te::map::AbstractLayerPtr > layers)
Get a list of AbstractLayer filtered by the name;.
A class that represents a data source component.
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
static std::auto_ptr< DataSource > make(const std::string &dsType)
const std::string & getDataSourceId() const
void onWithBoundToggled()
BufferDialog(QWidget *parent=0, Qt::WindowFlags f=0)
std::auto_ptr< Ui::BufferDialogForm > m_ui
The boundaries between buffers will be dissolved.
Utility functions for the data access module.
The buffer is generated only outside of the polygons.
void onTargetDatasourceToolButtonPressed()
te::map::AbstractLayerPtr getLayer()
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
The buffer is generated Inside and outside of the polygons.
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
A class that models the description of a dataset.
void onLayerComboBoxChanged(int index)
boost::shared_ptr< DataSetType > DataSetTypePtr
The boundaries between buffers will not be dissolved.
The buffer is generated only inside of the polygons.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
Buffer Vector Processing functions.
void onOkPushButtonClicked()
static T & getInstance()
It returns a reference to the singleton instance.
void onCancelPushButtonClicked()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
A dialog buffer operation.
void onTargetFileToolButtonPressed()
TEVPEXPORT bool Buffer(const std::string &inDataset, te::da::DataSource *inDatasource, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels, const std::string &outDataset, te::da::DataSource *outDatasource, const double &fixedDistance=0, const std::string &fromAttDistance="")
Executes the Buffer Geographical Operation and persists the result as a dataset in a given output dat...