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.size() <= 0)
 
  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   QMessageBox::information(
this, 
"Help", 
"Under development");
 
  340   if(m_ui->m_layersComboBox->currentText().isEmpty())
 
  342     QMessageBox::information(
this, 
"Buffer", 
"Select an input layer.");
 
  350     QMessageBox::information(
this, 
"Buffer", 
"Can not execute this operation on this type of layer.");
 
  356   if(m_ui->m_onlySelectedCheckBox->isChecked())
 
  358     oidSet = m_selectedLayer->getSelected();
 
  361       QMessageBox::information(
this, 
"Buffer", 
"Select the layer objects to perform the buffer operation.");
 
  367   if (!inDataSource.get())
 
  369     QMessageBox::information(
this, 
"Buffer", 
"The selected input data source can not be accessed.");
 
  374   double fixedDistance;
 
  375   std::string propDistance = 
"";
 
  376   if(m_ui->m_fixedRadioButton->isChecked())
 
  378     fixedDistance = m_ui->m_fixedDistanceLineEdit->text().toDouble();
 
  379     if (fixedDistance <= 0)
 
  381       QMessageBox::information(
this, 
"Buffer", 
"Fixed distance value should be greater than 0.");
 
  388     int i = m_ui->m_fromAttDistanceComboBox->currentIndex();
 
  389     propDistance = m_ui->m_fromAttDistanceComboBox->itemText(i).toStdString();
 
  393   if(m_ui->m_repositoryLineEdit->text().isEmpty())
 
  395     QMessageBox::information(
this, 
"Buffer", 
"Select a repository for the resulting layer.");
 
  400   if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
 
  402     QMessageBox::information(
this, 
"Buffer", 
"Define a name for the resulting layer.");
 
  406   int bufferPolygonRule = getPolygonRule();
 
  407   int bufferBoundariesRule = getBoundariesRule();
 
  408   bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
 
  409   int levels = m_ui->m_levelsNumComboBox->currentText().toInt();
 
  410   std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
 
  422       boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
 
  424       if(boost::filesystem::exists(uri))
 
  426         QMessageBox::information(
this, 
"Buffer", 
"Output file already exists. Remove it or select a new name and try again.");
 
  430       std::size_t idx = outputdataset.find(
".");
 
  431       if(idx != std::string::npos)
 
  432         outputdataset = outputdataset.substr(0,idx);
 
  434       std::map<std::string, std::string> dsinfo;
 
  435       dsinfo[
"URI"] = uri.string();
 
  438       dsOGR->setConnectionInfo(dsinfo);
 
  441       if(dsOGR->dataSetExists(outputdataset))
 
  443         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.");
 
  447       this->setCursor(Qt::WaitCursor);
 
  464       bufferOp->
setOutput(dsOGR, outputdataset);
 
  465       bufferOp->
setParams(fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels);
 
  470         res = bufferOp->
run();
 
  475         QMessageBox::information(
this, 
"Buffer", 
"Error: could not generate the buffer.");
 
  482       boost::uuids::basic_random_generator<boost::mt19937> gen;
 
  483       boost::uuids::uuid u = gen();
 
  484       std::string 
id = boost::uuids::to_string(u);
 
  487       ds->setConnInfo(dsinfo);
 
  488       ds->setTitle(uri.stem().string());
 
  489       ds->setAccessDriver(
"OGR");
 
  491       ds->setDescription(uri.string());
 
  497       m_outputDatasource = ds;
 
  504         QMessageBox::information(
this, 
"Buffer", 
"The selected output datasource can not be accessed.");
 
  507       if (aux->dataSetExists(outputdataset))
 
  509         QMessageBox::information(
this, 
"Buffer", 
"Dataset already exists. Remove it or select a new name and try again. ");
 
  512       this->setCursor(Qt::WaitCursor);
 
  529       bufferOp->
setParams(fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels);
 
  534         res = bufferOp->
run();
 
  538         this->setCursor(Qt::ArrowCursor);
 
  539         QMessageBox::information(
this, 
"Buffer", 
"Error: could not generate the buffer.");
 
  552     m_outputLayer = converter(dt);
 
  554   catch(
const std::exception& e)
 
  556     this->setCursor(Qt::ArrowCursor);
 
  557     QMessageBox::information(
this, 
"Buffer", e.what());
 
  559 #ifdef TERRALIB_LOGGER_ENABLED 
  560     std::string str = 
"Buffer - ";
 
  562     te::common::Logger::logDebug(
"vp", str.c_str());
 
  563 #endif //TERRALIB_LOGGER_ENABLED 
  570   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
 
void onHelpPushButtonClicked()
 
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...
 
const QueryCapabilities & getQueryCapabilities() const 
 
void onTargetFileToolButtonPressed()
 
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()
 
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::auto_ptr< te::da::DataSetType > inDsetType, const te::da::ObjectIdSet *oidSet=0)
 
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()
 
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.