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 "../../dataaccess/dataset/DataSetTypeConverter.h" 32 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 33 #include "../../dataaccess/datasource/DataSourceFactory.h" 34 #include "../../dataaccess/datasource/DataSourceManager.h" 35 #include "../../dataaccess/utils/Utils.h" 36 #include "../../datatype/Enums.h" 37 #include "../../geometry/GeometryProperty.h" 38 #include "../../maptools/AbstractLayer.h" 39 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 40 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 41 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 42 #include "../../qt/widgets/Utils.h" 43 #include "../../qt/widgets/utils/FileDialog.h" 44 #include "../../raster/Band.h" 45 #include "../../raster/BandProperty.h" 46 #include "../../raster/Grid.h" 47 #include "../../raster/RasterProperty.h" 48 #include "../Config.h" 49 #include "../Exception.h" 50 #include "../RasterToVector.h" 52 #include "ui_RasterToVectorDialogForm.h" 55 #include <QFileDialog> 56 #include <QIntValidator> 57 #include <QMessageBox> 60 #include <boost/filesystem.hpp> 61 #include <boost/lexical_cast.hpp> 62 #include <boost/uuid/random_generator.hpp> 63 #include <boost/uuid/uuid_io.hpp> 67 m_ui(new
Ui::RasterToVectorDialogForm),
73 m_ui->m_noDataLineEdit->setValidator(
new QIntValidator);
76 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"raster-vector-hint").pixmap(112,48));
77 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
82 connect(
m_ui->m_noDataCheckBox, SIGNAL(toggled(
bool)),
m_ui->m_noDataLineEdit, SLOT(setEnabled(
bool)));
90 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
91 m_ui->m_helpPushButton->setPageReference(
"plugins/attributefill/attrfill_raster_to_vector.html");
101 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
105 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
106 if (dsType->hasRaster())
108 m_ui->m_inRasterComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
110 if (dsType->hasGeom())
118 m_ui->m_inVectorComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
132 std::vector<unsigned int> vecBands;
134 for(
int i = 0; i <
m_ui->m_bandsListWidget->count(); ++i)
136 if(
m_ui->m_bandsListWidget->isItemSelected(
m_ui->m_bandsListWidget->item(i)))
138 vecBands.push_back(i);
146 std::vector<te::stat::StatisticalSummary> vecStatistics;
148 for(
int i = 0; i <
m_ui->m_statisticsListWidget->count(); ++i)
150 if(
m_ui->m_statisticsListWidget->isItemSelected(
m_ui->m_statisticsListWidget->item(i)))
204 return vecStatistics;
209 return !
m_ui->m_statisticsListWidget->selectedItems().isEmpty();
214 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
216 std::string layerID =
m_ui->m_inRasterComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
220 if(layerID == it->get()->getId())
226 m_ui->m_bandsListWidget->clear();
228 std::unique_ptr<te::da::DataSetType> dsType =
m_rasterLayer->getSchema();
229 std::unique_ptr<te::da::DataSet> dsRaster =
m_rasterLayer->getData();
233 std::unique_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->
getName());
234 std::size_t n_bands = raster->getNumberOfBands();
236 double noDataValue = raster->getBand(0)->getProperty()->m_noDataValue;
238 if(noDataValue == std::numeric_limits<double>::max())
240 m_ui->m_noDataLineEdit->setText(
241 boost::lexical_cast<std::string>(noDataValue).c_str());
244 for(std::size_t
b = 0;
b < n_bands; ++
b)
245 m_ui->m_bandsListWidget->addItem(boost::lexical_cast<std::string>(
b).c_str());
251 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
253 std::string layerID =
m_ui->m_inVectorComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
257 if(layerID == it->get()->getId())
260 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
262 m_ui->m_statisticsListWidget->clear();
268 m_ui->m_statisticsListWidget->addItem(
"Minimum value");
269 m_ui->m_statisticsListWidget->addItem(
"Maximum value");
270 m_ui->m_statisticsListWidget->addItem(
"Mean");
271 m_ui->m_statisticsListWidget->addItem(
"Sum of values");
272 m_ui->m_statisticsListWidget->addItem(
"Total number of values");
273 m_ui->m_statisticsListWidget->addItem(
"Total not null values");
274 m_ui->m_statisticsListWidget->addItem(
"Standard deviation");
275 m_ui->m_statisticsListWidget->addItem(
"Variance");
276 m_ui->m_statisticsListWidget->addItem(
"Skewness");
277 m_ui->m_statisticsListWidget->addItem(
"Kurtosis");
278 m_ui->m_statisticsListWidget->addItem(
"Amplitude");
279 m_ui->m_statisticsListWidget->addItem(
"Median");
280 m_ui->m_statisticsListWidget->addItem(
"Coefficient variation");
281 m_ui->m_statisticsListWidget->addItem(
"Mode");
282 m_ui->m_statisticsListWidget->addItem(
"Percent of each class by area");
285 m_ui->m_textureCheckBox->setEnabled(
true);
289 m_ui->m_statisticsListWidget->addItem(
"Value");
292 m_ui->m_textureCheckBox->setChecked(
false);
293 m_ui->m_textureCheckBox->setEnabled(
false);
302 m_ui->m_newLayerNameLineEdit->clear();
303 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
307 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
309 if(dsPtrList.empty())
312 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
314 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
323 m_ui->m_newLayerNameLineEdit->clear();
324 m_ui->m_repositoryLineEdit->clear();
332 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
336 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
337 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
340 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
345 if(
m_ui->m_inRasterComboBox->count() == 0)
347 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Select an input raster layer."));
351 if(
m_ui->m_inVectorComboBox->count() == 0)
353 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Select an input vector layer."));
357 std::unique_ptr<te::da::DataSet> rasterDataSet =
m_rasterLayer->getData();
361 std::unique_ptr<te::rst::Raster> inputRst = rasterDataSet->getRaster(rpos);
363 std::string sridMessage;
368 QMessageBox::information(
this, tr(
"Raster to Vector"), sridMessage.c_str());
374 if(
m_ui->m_noDataCheckBox->isChecked())
376 if(!
m_ui->m_noDataLineEdit->text().isEmpty())
378 double noDataValue =
m_ui->m_noDataLineEdit->text().toDouble();
388 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Can not execute this operation on this type of layer."));
394 if(
m_ui->m_onlySelectedCheckBox->isChecked())
399 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Select the layer objects to perform the raster to vector operation."));
405 if (!inVectorDataSource.get())
407 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"The selected vector data source can not be accessed."));
414 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Select at least one band."));
418 std::vector<te::stat::StatisticalSummary> vecStatistics;
427 if (isValueOptionSelected ==
false && vecStatistics.empty() &&
m_texture ==
false)
429 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Select at least one statistic operation or select the texture checkbox."));
433 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
435 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Define a repository for the result."));
439 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
441 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Define a name for the resulting layer."));
445 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
456 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
460 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Output file already exists. Remove it or select a new name and try again."));
464 std::size_t idx = outputdataset.find(
".");
465 if (idx != std::string::npos)
466 outputdataset=outputdataset.substr(0,idx);
468 std::string dsinfo(
"file://" + uri.string());
472 if (dsOGR->dataSetExists(outputdataset))
474 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again."));
478 std::unique_ptr<te::da::DataSetTypeConverter> converterVector(
480 inVectorDataSource->getCapabilities(),
481 inVectorDataSource->getEncoding()));
485 this->setCursor(Qt::WaitCursor);
491 converterVector.release(),
496 m_ui->m_boxPixelRadioButton->isChecked(),
499 rst2vec->
setOutput(dsOGR, outputdataset);
504 res = rst2vec->
run();
508 this->setCursor(Qt::ArrowCursor);
510 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Error: could not generate the operation."));
518 boost::uuids::basic_random_generator<boost::mt19937> gen;
519 boost::uuids::uuid u = gen();
520 std::string id_ds = boost::uuids::to_string(u);
523 ds->setConnInfo(dsinfo);
524 ds->setTitle(uri.stem().string());
525 ds->setAccessDriver(
"OGR");
527 ds->setDescription(uri.string());
540 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"The selected output datasource can not be accessed."));
544 if (aux->dataSetExists(outputdataset))
546 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Dataset already exists. Remove it or select a new name and try again."));
549 this->setCursor(Qt::WaitCursor);
551 std::unique_ptr<te::da::DataSetTypeConverter> converterVector(
553 inVectorDataSource->getCapabilities(),
554 inVectorDataSource->getEncoding()));
560 rst2vec->setInput(inputRst.get(),
563 converterVector.release(),
566 rst2vec->setParams(vecBands,
568 m_ui->m_boxPixelRadioButton->isChecked(),
571 rst2vec->setOutput(aux, outputdataset);
573 if (!rst2vec->paramsAreValid())
576 res = rst2vec->run();
582 this->setCursor(Qt::ArrowCursor);
583 QMessageBox::information(
this, tr(
"Raster to Vector"), tr(
"Error: could not generate the operation."));
597 catch(
const std::exception& e)
599 this->setCursor(Qt::ArrowCursor);
601 QMessageBox::information(
this, tr(
"Raster to Vector"), e.what());
603 #ifdef TERRALIB_LOGGER_ENABLED 605 #endif // TERRALIB_LOGGER_ENABLED 610 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.
Raster to vector attributefill dialog.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
void setInput(te::rst::Raster *inRaster, te::da::DataSourcePtr inVectorDsrc, std::string inVectorName, te::da::DataSetTypeConverter *inVectorDsType, const te::da::ObjectIdSet *oidSet=0)
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
std::vector< unsigned int > getSelectedBands()
Get the selected bands based on selected QListWidgetItem.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A raster band description.
te::map::AbstractLayerPtr m_vectorLayer
Vector layer.
virtual const char * what() const
It outputs the exception message.
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
te::map::AbstractLayerPtr m_outLayer
Generated Layer.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsName)
static te::dt::Date ds(2010, 01, 01)
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Percente of each class by area.
void onTargetDatasourceToolButtonPressed()
An converter for DataSetType.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
static DataSourceManager & 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...
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
void onTargetFileToolButtonPressed()
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void setParams(std::vector< unsigned int > bands, std::vector< te::stat::StatisticalSummary > statSum, bool iteratorByBox, bool texture)
bool getValueOption()
Get the based on selected QListWidgetItem.
void onVectorComboBoxChanged(int index)
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
const std::string & getDataSetName() const
A class that represents a data source component.
A layer with reference to a dataset.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void onOkPushButtonClicked()
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::vector< te::stat::StatisticalSummary > getSelectedStatistics()
Get the selected statistics based on selected QListWidgetItem.
std::unique_ptr< Ui::RasterToVectorDialogForm > m_ui
User interface.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onRasterComboBoxChanged(int index)
virtual const std::string & getDataSourceId() const
void onCancelPushButtonClicked()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::map::AbstractLayerPtr m_rasterLayer
Raster layer.
RasterToVectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
const std::string & getName() const
It returns the property name.