27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/Translator.h"
30 #include "../../common/STLUtils.h"
31 #include "../../dataaccess/dataset/DataSetType.h"
32 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
33 #include "../../dataaccess/datasource/DataSourceInfo.h"
34 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
35 #include "../../dataaccess/datasource/DataSourceManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/utils/Utils.h"
38 #include "../../datatype/Enums.h"
39 #include "../../datatype/Property.h"
40 #include "../../geometry/Geometry.h"
41 #include "../../geometry/GeometryProperty.h"
42 #include "../../maptools/AbstractLayer.h"
43 #include "../../maptools/DataSetLayer.h"
44 #include "../../memory/DataSet.h"
45 #include "../../memory/DataSetItem.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 "../../srs/Config.h"
50 #include "../Exception.h"
51 #include "../BufferMemory.h"
53 #include "../BufferOp.h"
54 #include "../BufferQuery.h"
55 #include "ui_BufferDialogForm.h"
59 #include <QFileDialog>
61 #include <QListWidget>
62 #include <QListWidgetItem>
63 #include <QMessageBox>
70 #include <boost/algorithm/string.hpp>
71 #include <boost/filesystem.hpp>
72 #include <boost/lexical_cast.hpp>
73 #include <boost/uuid/random_generator.hpp>
74 #include <boost/uuid/uuid_io.hpp>
78 m_ui(new
Ui::BufferDialogForm),
86 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-buffer-hint").pixmap(112,48));
88 QSize iconSize(96, 48);
90 m_ui->m_withoutBoundRadioButton->setIconSize(iconSize);
91 m_ui->m_withoutBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-without-boundaries"));
93 m_ui->m_withBoundRadioButton->setIconSize(iconSize);
94 m_ui->m_withBoundRadioButton->setIcon(QIcon::fromTheme(
"buffer-with-boundaries"));
96 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
97 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
100 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
101 m_ui->m_fixedDistanceLineEdit->setValidator(
new QDoubleValidator(
this));
111 connect(
m_ui->m_ruleOnlyInRadioButton, SIGNAL(toggled(
bool)),
this, SLOT(
onRuleInToggled()));
121 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
122 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_buffer.html");
133 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
135 while(it != m_layers.end())
137 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
138 if(dsType->hasGeom())
139 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
146 for(
int i=1; i <= 10; ++i)
147 m_ui->m_levelsNumComboBox->addItem(QString::number(i));
152 m_ui->m_fromAttDistanceComboBox->clear();
154 for(std::size_t i = 0; i < properties.size(); ++i)
169 m_ui->m_fromAttDistanceComboBox->addItem(properties[i]->getName().c_str());
172 if(m_ui->m_fromAttDistanceComboBox->count() > 0)
177 m_ui->m_fromAttRadioButton->setEnabled(
false);
182 if(m_ui->m_ruleInOutRadioButton->isChecked())
184 else if(m_ui->m_ruleOnlyOutRadioButton->isChecked())
192 if(m_ui->m_withoutBoundRadioButton->isChecked())
200 return m_outputLayer;
205 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
206 std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toStdString();
208 while(it != m_layers.end())
210 if(layerID == it->get()->getId().c_str())
213 m_selectedLayer = selectedLayer;
214 std::auto_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
216 if(schema->size() == 0)
220 m_properties.clear();
222 const std::vector<te::dt::Property*>& properties = schema->getProperties();
225 setAttributesForDistance(m_properties);
236 m_ui->m_ruleInOutRadioButton->setDisabled(
true);
237 m_ui->m_ruleOnlyInRadioButton->setDisabled(
true);
238 m_ui->m_ruleOnlyOutRadioButton->setChecked(
true);
242 m_ui->m_ruleInOutRadioButton->setEnabled(
true);
243 m_ui->m_ruleOnlyInRadioButton->setEnabled(
true);
244 m_ui->m_ruleInOutRadioButton->setChecked(
true);
255 m_ui->m_fixedDistanceLineEdit->setEnabled(
true);
256 m_ui->m_fromAttDistanceComboBox->setEnabled(
false);
261 m_ui->m_fromAttDistanceComboBox->setEnabled(
true);
262 m_ui->m_fixedDistanceLineEdit->setEnabled(
false);
267 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-inside-outside").pixmap(150,60));
272 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer_only-outside").pixmap(150,60));
277 m_ui->m_ruleImgLabel->setPixmap(QIcon::fromTheme(
"buffer-only-inside").pixmap(150,60));
282 m_ui->m_copyColumnsCheckBox->setChecked(
false);
283 m_ui->m_copyColumnsCheckBox->setEnabled(
false);
288 m_ui->m_copyColumnsCheckBox->setEnabled(
true);
293 m_ui->m_newLayerNameLineEdit->clear();
294 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
298 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
300 if(dsPtrList.empty())
303 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
305 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
307 m_outputDatasource = *it;
314 m_ui->m_newLayerNameLineEdit->clear();
315 m_ui->m_repositoryLineEdit->clear();
317 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
318 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
320 if(fileName.isEmpty())
323 boost::filesystem::path outfile(fileName.toStdString());
324 std::string aux = outfile.leaf().string();
325 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
326 aux = outfile.string();
327 m_ui->m_repositoryLineEdit->setText(aux.c_str());
330 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
335 if(m_ui->m_layersComboBox->currentText().isEmpty())
337 QMessageBox::information(
this,
"Buffer",
"Select an input layer.");
345 QMessageBox::information(
this,
"Buffer",
"Can not execute this operation on this type of layer.");
351 if(m_ui->m_onlySelectedCheckBox->isChecked())
353 oidSet = m_selectedLayer->getSelected();
356 QMessageBox::information(
this,
"Buffer",
"Select the layer objects to perform the buffer operation.");
362 if (!inDataSource.get())
364 QMessageBox::information(
this,
"Buffer",
"The selected input data source can not be accessed.");
369 double fixedDistance;
370 std::string propDistance =
"";
371 if(m_ui->m_fixedRadioButton->isChecked())
373 fixedDistance = m_ui->m_fixedDistanceLineEdit->text().toDouble();
374 if (fixedDistance <= 0)
376 QMessageBox::information(
this,
"Buffer",
"Fixed distance value should be greater than 0.");
383 int i = m_ui->m_fromAttDistanceComboBox->currentIndex();
384 propDistance = m_ui->m_fromAttDistanceComboBox->itemText(i).toStdString();
388 if(m_ui->m_repositoryLineEdit->text().isEmpty())
390 QMessageBox::information(
this,
"Buffer",
"Select a repository for the resulting layer.");
395 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
397 QMessageBox::information(
this,
"Buffer",
"Define a name for the resulting layer.");
401 int bufferPolygonRule = getPolygonRule();
402 int bufferBoundariesRule = getBoundariesRule();
403 bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
404 int levels = m_ui->m_levelsNumComboBox->currentText().toInt();
405 std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
417 boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
419 if(boost::filesystem::exists(uri))
421 QMessageBox::information(
this,
"Buffer",
"Output file already exists. Remove it or select a new name and try again.");
425 std::size_t idx = outputdataset.find(
".");
426 if(idx != std::string::npos)
427 outputdataset = outputdataset.substr(0,idx);
429 std::map<std::string, std::string> dsinfo;
430 dsinfo[
"URI"] = uri.string();
433 dsOGR->setConnectionInfo(dsinfo);
436 if(dsOGR->dataSetExists(outputdataset))
438 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.");
446 this->setCursor(Qt::WaitCursor);
463 bufferOp->
setOutput(dsOGR, outputdataset);
464 bufferOp->
setParams(fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels);
469 res = bufferOp->
run();
474 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
481 boost::uuids::basic_random_generator<boost::mt19937> gen;
482 boost::uuids::uuid u = gen();
483 std::string
id = boost::uuids::to_string(u);
486 ds->setConnInfo(dsinfo);
487 ds->setTitle(uri.stem().string());
488 ds->setAccessDriver(
"OGR");
490 ds->setDescription(uri.string());
496 m_outputDatasource = ds;
503 QMessageBox::information(
this,
"Buffer",
"The selected output datasource can not be accessed.");
506 if (aux->dataSetExists(outputdataset))
508 QMessageBox::information(
this,
"Buffer",
"Dataset already exists. Remove it or select a new name and try again. ");
511 this->setCursor(Qt::WaitCursor);
533 bufferOp->setInput(inDataSource, dsLayer->
getDataSetName(), converter);
534 bufferOp->setOutput(aux, outputdataset);
535 bufferOp->setParams(fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels);
537 if (!bufferOp->paramsAreValid())
540 res = bufferOp->run();
544 this->setCursor(Qt::ArrowCursor);
545 QMessageBox::information(
this,
"Buffer",
"Error: could not generate the buffer.");
558 m_outputLayer = converter(dt);
560 catch(
const std::exception& e)
562 this->setCursor(Qt::ArrowCursor);
563 QMessageBox::information(
this,
"Buffer", e.what());
565 #ifdef TERRALIB_LOGGER_ENABLED
566 std::string str =
"Buffer - ";
568 te::common::Logger::logDebug(
"vp", str.c_str());
569 #endif //TERRALIB_LOGGER_ENABLED
576 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 setAttributesForDistance(std::vector< te::dt::Property * > properties)
std::auto_ptr< Ui::BufferDialogForm > m_ui
BufferDialog(QWidget *parent=0, Qt::WindowFlags f=0)
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Utility functions for the data access module.
void onFixedDistanceToggled()
const std::string & getDataSetName() const
void onAttDistanceToggled()
void onOkPushButtonClicked()
boost::shared_ptr< DataSetType > DataSetTypePtr
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.
A dialog buffer operation.
A class that models the description of a dataset.
void onLayerComboBoxChanged(int index)
void onCancelPushButtonClicked()
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetTypeConverter > converter, const te::da::ObjectIdSet *oidSet=0)
const QueryCapabilities & getQueryCapabilities() const
void onTargetFileToolButtonPressed()
An converter for DataSetType.
The buffer is generated only outside of the polygons.
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
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.
void setParams(const double &distance, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels)
static std::auto_ptr< DataSource > make(const std::string &dsType)
void onWithBoundToggled()
virtual bool paramsAreValid()
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
bool supportsSpatialSQLDialect() const
The buffer is generated Inside and outside of the polygons.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
void onRuleInOutToggled()
bool supportsPreparedQueryAPI() const
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.
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
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...
void onWithoutBoundToggled()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
The boundaries between buffers will be dissolved.