27 #include "../../../../common/Exception.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../dataaccess.h"
30 #include "../../../../geometry/GeometryProperty.h"
31 #include "../../../../maptools/DataSetLayer.h"
32 #include "../../../../qt/widgets/datasource/selector/DataSourceSelectorWidget.h"
33 #include "../../../../qt/widgets/datasource/selector/DataSourceSelectorWizardPage.h"
34 #include "../../../../qt/widgets/layer/utils/DataSet2Layer.h"
35 #include "../../../../qt/widgets/help/HelpPushButton.h"
36 #include "../../../../qt/widgets/rp/Utils.h"
37 #include "../../../../qt/widgets/utils/ScopedCursor.h"
38 #include "../../../../qt/af/ApplicationController.h"
39 #include "../../../../qt/af/Project.h"
40 #include "../../../../qt/af/events/LayerEvents.h"
41 #include "../../../../raster/Utils.h"
42 #include "../../../../terralib4/DataSource.h"
43 #include "../../../../terralib4/ThemeInfo.h"
44 #include "../../../../se/ChannelSelection.h"
45 #include "../../../../se/ColorMap.h"
46 #include "../../../../se/FeatureTypeStyle.h"
47 #include "../../../../se/Fill.h"
48 #include "../../../../se/PolygonSymbolizer.h"
49 #include "../../../../se/RasterSymbolizer.h"
50 #include "../../../../se/Rule.h"
51 #include "../../../../se/SelectedChannel.h"
52 #include "../../../../se/Stroke.h"
53 #include "../../../../se/Style.h"
54 #include "../../../../se/Symbolizer.h"
55 #include "../../../../se/Utils.h"
63 #include "ui_TL4ConverterWizardForm.h"
64 #include "ui_TL4ConnectorWizardPageForm.h"
65 #include "ui_TL4LayerSelectionWizardPageForm.h"
66 #include "ui_TL4RasterFolderSelectionWizardPageForm.h"
67 #include "ui_TL4FinalPageWizardPageForm.h"
68 #include "ui_TL4ThemeSelectionWizardPageForm.h"
74 #include <boost/filesystem.hpp>
75 #include <boost/lexical_cast.hpp>
79 #include <QMessageBox>
80 #include <QTableWidgetItem>
81 #include <QGridLayout>
84 #include <terralib4/kernel/TeLegendEntry.h>
85 #include <terralib4/kernel/TeRasterTransform.h>
86 #include <terralib4/kernel/TeTheme.h>
90 m_hasNonRaster(false),
93 m_ui(new Ui::TL4ConverterWizardForm)
101 m_connectorPage->setSubTitle(tr(
"Connect to a TerraLib 4.x database."));
119 m_resolveNamePage->setSubTitle(tr(
"Some layer names clashes with target data source names. Please, give a new name for the layers showed below"));
125 displayLayout->setContentsMargins(0,0,0,0);
128 labels <<
"" << tr(
"Source Names") << tr(
"Target Names");
133 m_finalPage->setSubTitle(tr(
"Select the TerraLib 4.x Layer converted that you want to create a TerraLib 5 Project Layer."));
137 m_themeSelection->setSubTitle(tr(
"Select the TerraLib 4.x Theme of converted Layers that you want to create a TerraLib 5 Project Layer, with informations like Visual and Grouping."));
148 connect(this->button(QWizard::NextButton), SIGNAL(pressed()),
this, SLOT(
next()));
149 connect(this->button(QWizard::BackButton), SIGNAL(pressed()),
this, SLOT(
back()));
150 connect(this->button(QWizard::FinishButton), SIGNAL(pressed()),
this, SLOT(
finish()));
151 connect(this->button(QWizard::CommitButton), SIGNAL(pressed()),
this, SLOT(
commit()));
155 this->setButton(QWizard::HelpButton, helpButton);
166 if(currentId() == PAGE_TERRALIB4_CONNECTOR)
167 return PAGE_LAYER_SELECTION;
169 if(currentId() == PAGE_LAYER_SELECTION)
172 return PAGE_DATASOURCE_SELECTOR;
175 return PAGE_RASTERFOLDER_SELECTOR;
177 return PAGE_LAYER_SELECTION;
180 if(currentId() == PAGE_DATASOURCE_SELECTOR)
183 return PAGE_RASTERFOLDER_SELECTOR;
185 return PAGE_NAME_RESOLVE_SELECTOR;
188 if(currentId() == PAGE_RASTERFOLDER_SELECTOR)
189 return PAGE_NAME_RESOLVE_SELECTOR;
191 if(currentId() == PAGE_NAME_RESOLVE_SELECTOR)
192 return PAGE_FINALPAGE;
194 if(currentId() == PAGE_FINALPAGE)
195 return PAGE_THEME_SELECTION;
202 int current_page_id = currentId();
204 if(current_page_id == PAGE_TERRALIB4_CONNECTOR)
206 if(!validTerraLib4Connection())
211 std::vector<std::string> layers = tl4Ds->
getTL4Layers();
212 std::vector<std::string> tables = tl4Ds->
getTL4Tables();
214 m_layerSelectionPage->setDatasets(layers, tables);
217 else if(current_page_id == PAGE_LAYER_SELECTION)
219 if(!validLayerSelection())
222 else if(current_page_id == PAGE_DATASOURCE_SELECTOR)
224 m_targetDataSource = *m_datasourceSelectorPage->getSelectorWidget()->getSelecteds().begin();
226 else if(current_page_id == PAGE_RASTERFOLDER_SELECTOR)
228 m_rasterFolderPath = m_rasterFolderSelectionPage->getPath();
230 else if(current_page_id == PAGE_NAME_RESOLVE_SELECTOR)
237 if(nextId() == PAGE_NAME_RESOLVE_SELECTOR)
241 std::vector<QListWidgetItem*> selectedLayerItems = m_layerSelectionPage->getCheckedItems();
243 m_resolveNameTableWidget->clearContents();
244 m_resolveNameTableWidget->setRowCount(selectedLayerItems.size());
251 bool hasConflicts =
false;
253 for(std::size_t i = 0; i < selectedLayerItems.size(); ++i)
255 std::string targetDatasetName = selectedLayerItems[i]->text().toStdString();
258 std::auto_ptr<te::da::DataSetType> input_dataset_type(m_tl4Database->getDataSetType(selectedLayerItems[i]->text().toStdString()));
260 if(input_dataset_type->hasRaster())
262 QTableWidgetItem *conflictItem = 0;
264 if(boost::filesystem::exists(m_rasterFolderPath +
"/" + targetDatasetName +
".tif"))
268 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"delete"),
"");
272 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
275 conflictItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
276 m_resolveNameTableWidget->setItem(i, 0, conflictItem);
281 QTableWidgetItem *conflictItem = 0;
283 if(tl5ds->dataSetExists(targetDatasetName))
287 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"delete"),
"");
291 conflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
294 conflictItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
295 m_resolveNameTableWidget->setItem(i, 0, conflictItem);
298 QTableWidgetItem *oldNameItem =
new QTableWidgetItem(selectedLayerItems[i]->text(), selectedLayerItems[i]->type());
299 oldNameItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
300 m_resolveNameTableWidget->setItem(i, 1, oldNameItem);
302 QTableWidgetItem *newNameItem =
new QTableWidgetItem(targetDatasetName.c_str(), selectedLayerItems[i]->type());
303 m_resolveNameTableWidget->setItem(i, 2, newNameItem);
306 m_resolveNameTableWidget->resizeColumnsToContents();
307 m_resolveNameTableWidget->sortByColumn(1, Qt::AscendingOrder);
311 m_resolveNamePage->setTitle(tr(
"Resolve Name Conflicts"));
312 m_resolveNamePage->setSubTitle(tr(
"Some layer names clash with target data source dataset names. Please, give a new name for the layers showed below"));
316 m_resolveNamePage->setTitle(tr(
"No Name Conflicts"));
317 m_resolveNamePage->setSubTitle(tr(
"You can change the layer names in the target data source"));
321 catch(
const te::da::Exception& e)
323 QMessageBox::warning(
this, tr(
"Warning"), e.what());
328 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid this page!"));
337 std::map<std::string, std::string> connInfo = m_connectorPage->getConnInfo();
343 m_tl4Database->setConnectionInfo(connInfo);
344 m_tl4Database->open();
346 catch(
const te::da::Exception& e)
348 QMessageBox::warning(
this, tr(
"Warning"), e.what());
353 QMessageBox::warning(
this, tr(
"Warning"), tr(
"A connection to the informed Terralib 4.x database could not be established. Please, verify the informed parameters."));
362 if(!m_layerSelectionPage->hasChecked())
365 QMessageBox::warning(
this,
367 tr(
"Please, select at least one layer for conversion!"));
371 std::vector<std::string> layersNames = m_layerSelectionPage->getChecked();
374 m_hasNonRaster =
false;
381 for(std::size_t i = 0; i < layersNames.size(); ++i)
383 std::auto_ptr<te::da::DataSetType> dst(m_tl4Database->getDataSetType(layersNames[i]));
388 m_hasNonRaster =
true;
391 catch(
const te::da::Exception& e)
393 QMessageBox::warning(
this, tr(
"Warning"), e.what());
398 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid layer selection!"));
407 bool hasConflict =
false;
417 catch(
const te::da::Exception& e)
419 QMessageBox::warning(
this, tr(
"Warning"), e.what());
424 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
428 int nrows = m_resolveNameTableWidget->rowCount();
430 for(
int i = 0; i != nrows; ++i)
433 QTableWidgetItem* item_source = m_resolveNameTableWidget->item(i, 1);
438 std::string sourceName = item_source->text().toStdString();
441 QTableWidgetItem* item_target = m_resolveNameTableWidget->item(i, 2);
446 std::string targetName = item_target->text().toStdString();
453 std::auto_ptr<te::da::DataSetType> input_dataset_type(m_tl4Database->getDataSetType(sourceName));
455 if(input_dataset_type->hasRaster())
458 if(boost::filesystem::exists(m_rasterFolderPath +
"/" + targetName +
".tif"))
464 QTableWidgetItem *nonconflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
466 m_resolveNameTableWidget->setItem(i, 0, nonconflictItem);
472 if(tl5ds->dataSetExists(targetName))
478 QTableWidgetItem *nonconflictItem =
new QTableWidgetItem(QIcon::fromTheme(
"check"),
"");
480 m_resolveNameTableWidget->setItem(i, 0, nonconflictItem);
484 catch(
const te::da::Exception& e)
486 QMessageBox::warning(
this, tr(
"Warning"), e.what());
491 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not valid layer names in target data source!"));
498 QString errMsg(tr(
"There still have name conflicts. Please, resolve the indicated conflicts before continue!"));
500 QMessageBox::warning(
this, tr(
"TerraLib 4.x Converter"), errMsg);
510 int rowCount = m_resolveNameTableWidget->rowCount();
512 for(
int i = 0; i < rowCount; ++i)
514 QString targetNameInTable = m_resolveNameTableWidget->item(i, 2)->text();
516 if(targetName.c_str() == targetNameInTable)
517 return m_resolveNameTableWidget->item(i, 1)->text().toStdString();
526 int rowCount = m_resolveNameTableWidget->rowCount();
528 for(
int i = 0; i < rowCount; ++i)
530 QString oName = m_resolveNameTableWidget->item(i, 1)->text();
532 if(originalName.c_str() == oName)
533 return m_resolveNameTableWidget->item(i, 2)->text().toStdString();
551 if(!validLayerNames())
558 std::vector<std::pair<std::string, std::string> > problematicDatasets;
559 std::vector<std::string> successfulDatasets;
568 catch(
const te::da::Exception& e)
571 QMessageBox::warning(
this, tr(
"Warning"), e.what());
577 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
581 int nrows = m_resolveNameTableWidget->rowCount();
583 for(
int i = 0; i != nrows; ++i)
586 QTableWidgetItem* item_source = m_resolveNameTableWidget->item(i, 1);
591 std::string sourceName = item_source->text().toStdString();
594 QTableWidgetItem* item_target = m_resolveNameTableWidget->item(i, 2);
599 std::string targetName = item_target->text().toStdString();
606 std::auto_ptr<te::da::DataSetType> input_dataset_type(m_tl4Database->getDataSetType(sourceName));
608 if(input_dataset_type->hasRaster())
611 std::auto_ptr<te::da::DataSet> ds = m_tl4Database->getDataSet(sourceName);
613 std::auto_ptr<te::rst::Raster> raster = ds->getRaster(
"Raster");
615 std::string newName = m_rasterFolderPath +
"/" + targetName +
".tif";
619 successfulDatasets.push_back(targetName);
624 input_dataset_type->setName(targetName);
626 std::auto_ptr<te::da::DataSetTypeConverter> dt_adapter(
new te::da::DataSetTypeConverter(input_dataset_type.get(), tl5ds->getCapabilities()));
628 std::auto_ptr<te::da::DataSet> ds(m_tl4Database->getDataSet(sourceName));
632 const std::vector<std::vector<std::size_t> >& indexes = dt_adapter->getConvertedPropertyIndexes();
633 const std::vector<te::da::AttributeConverter>& funcs = dt_adapter->getConverters();
639 for(std::size_t i = 0; i < type->
size(); ++i)
646 ds_adapter->add(p->
getName(), p->
getType(), indexes[i], conversor);
650 ds_adapter->add(p->
getName(), p->
getType(), indexes[i], funcs[i]);
658 if(finalSrid == 4979)
661 ds_adapter->setSRID(finalSrid);
663 std::map<std::string, std::string> opt;
665 ds_adapter->moveBeforeFirst();
667 te::da::Create(tl5ds.get(), dt_adapter->getResult(), ds_adapter.get(), opt);
669 successfulDatasets.push_back(targetName);
674 std::pair<std::string, std::string> dproblem;
675 dproblem.first = sourceName;
676 dproblem.second = e.
what();
678 problematicDatasets.push_back(dproblem);
682 std::pair<std::string, std::string> dproblem;
683 dproblem.first = sourceName;
684 dproblem.second =
TE_TR(
"unknown problem in conversion!");
686 problematicDatasets.push_back(dproblem);
691 if(!problematicDatasets.empty())
693 QString error(tr(
"Some TerraLib 4.x Layers could not be converted: \n\n"));
696 for(std::size_t i = 0; i < problematicDatasets.size(); ++i)
698 error.append(QString(
" - ") + problematicDatasets[i].first.c_str() + QString(
""));
699 details.append(problematicDatasets[i].first.c_str() + QString(
":\n"));
700 details.append(problematicDatasets[i].second.c_str() + QString(
"\n\n"));
703 QMessageBox message(QMessageBox::Warning, tr(
"TerraLib 4.x Converter"), error, QMessageBox::Ok,
this);
704 message.setDetailedText(details);
712 m_finalPage->setDataSets(successfulDatasets);
714 std::vector<::terralib4::ThemeInfo> themes = tl4Ds->
getTL4Themes();
716 std::vector<::terralib4::ThemeInfo> convertedThemes;
717 for(std::size_t i = 0; i < themes.size(); ++i)
719 for(std::size_t j = 0; j < successfulDatasets.size(); ++j)
721 if(themes[i].m_layerName == getOriginalName(successfulDatasets[j]))
723 convertedThemes.push_back(themes[i]);
728 m_themeSelection->setThemes(convertedThemes);
735 std::vector<std::string> selected = m_finalPage->getSelected();
744 catch(
const te::da::Exception& e)
747 QMessageBox::warning(
this, tr(
"Warning"), e.what());
753 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Could not connect to TerraLib 5 data source!"));
761 for(std::size_t i = 0; i < selected.size(); ++i)
765 std::auto_ptr<te::da::DataSetType> sourceDt = m_tl4Database->getDataSetType(getOriginalName(selected[i]));
767 if(sourceDt->hasRaster())
769 std::map<std::string, std::string> connInfo;
770 connInfo[
"URI"] = m_rasterFolderPath +
"/" + selected[i] +
".tif";
778 std::auto_ptr<te::da::DataSetType> dsType = outDataSource->getDataSetType(selected[i]);
782 layer = converter(dt);
790 std::vector<::terralib4::ThemeInfo> themes = m_themeSelection->getThemes();
792 for(std::size_t i = 0; i < themes.size(); ++i)
796 std::string newName = getNewName(themes[i].m_layerName);
798 std::auto_ptr<te::da::DataSetType> sourceDt = m_tl4Database->getDataSetType(newName);
806 if(sourceDt->hasRaster())
808 std::map<std::string, std::string> connInfo;
809 connInfo[
"URI"] = m_rasterFolderPath +
"/" + themes[i].
m_name +
".tif";
817 if(theme->grouping().groupMode_ != TeNoGrouping)
825 std::string band =
"0";
849 std::auto_ptr<te::da::DataSetType> dst = outDataSource->getDataSetType(getNewName(themes[i].m_layerName));
855 layer = converter(dstPtr);
856 layer->setTitle(themes[i].m_name);
863 if(theme->grouping().groupMode_ != TeNoGrouping)
867 layer->setStyle(style->
clone());
876 catch(
const te::da::Exception& e)
879 QMessageBox::warning(
this, tr(
"Warning"), e.what());
885 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Automatic layer creation failed!"));
892 QMessageBox::warning(
this,
893 tr(
"TerraLib 4.x Converter"),
894 tr(
"This option is not implemented yet!\nWe will provide it soon!"));
Property * getProperty(std::size_t i) const
It returns the i-th property.
This event signals that a new layer was created.
A selected channel to be display.
te::color::RGBAColor Convert2TerraLib5(TeColor color)
std::auto_ptr< te::qt::widgets::DataSourceSelectorWizardPage > m_datasourceSelectorPage
boost::shared_ptr< DataSetType > DataSetTypePtr
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
CharEncoding
Supported charsets (character encoding).
std::string getNewName(const std::string &originalName)
te::map::Grouping * GetGrouping(TeTheme *theme)
std::auto_ptr< TL4ThemeSelectionWizardPage > m_themeSelection
std::string * m_name
It allows the style to be referenced. Names must be unique in the context in which they are defined...
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
std::auto_ptr< Ui::TL4ConverterWizardForm > m_ui
virtual const char * what() const
It outputs the exception message.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster &rin, const std::string &uri, const std::string &rType=std::string("GDAL"))
Create a new raster from existing one.
bool validateCurrentPage()
te::se::ChannelSelection * getChannelSelection() const
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo theme)
void setGrayChannel(SelectedChannel *c)
#define TE_TR(message)
It marks a string in order to get translated.
It models a property definition.
An converter for DataSetType.
A wizard page that provides the capability of connecting to a TerraLib 4.x database.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
std::auto_ptr< QWizardPage > m_resolveNamePage
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
static std::auto_ptr< DataSource > make(const std::string &dsType)
void setColorCompositionType(ColorCompositionType cct)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
std::size_t size() const
It returns the number of properties of the CompositeProperty.
std::vector< std::string > getTL4Tables()
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::auto_ptr< TL4ConnectorWizardPage > m_connectorPage
virtual Style * clone() const =0
It creates a new copy of this object.
int getType() const
It returns the property data type.
std::vector<::terralib4::ThemeInfo > getTL4Themes()
void setColorMap(ColorMap *c)
void setSourceChannelName(const std::string &name)
int getLayerSRID(const std::string &layerName)
std::auto_ptr< QTableWidget > m_resolveNameTableWidget
bool validTerraLib4Connection()
TL4ConverterWizard(QWidget *parent=0, Qt::WindowFlags f=0)
bool validLayerSelection()
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::se::ColorMap * GetRasterGrouping(TeTheme *theme)
SelectedChannel * getGrayChannel() const
std::auto_ptr< TL4FinalPageWizardPage > m_finalPage
std::string getOriginalName(const std::string &targetName)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::auto_ptr< TL4LayerSelectionWizardPage > m_layerSelectionPage
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
std::auto_ptr< TL4RasterFolderSelectionWizardPage > m_rasterFolderSelectionPage
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...
std::vector< std::string > getTL4Layers()
const std::string & getName() const
It returns the property name.