21 #include <boost/property_tree/ptree.hpp> 24 #include "../../../color/ColorBar.h" 25 #include "../../../common/Globals.h" 26 #include "../../../common/STLUtils.h" 27 #include "../../../core/translator/Translator.h" 28 #include "../../../dataaccess/dataset/DataSet.h" 29 #include "../../../dataaccess/datasource/DataSourceManager.h" 30 #include "../../../dataaccess/query_h.h" 31 #include "../../../dataaccess/utils/Utils.h" 32 #include "../../../maptools/GroupingAlgorithms.h" 33 #include "../../../maptools/Utils.h" 34 #include "../../../se.h" 35 #include "../../../se/SymbolizerColorFinder.h" 36 #include "../../../se/Utils.h" 37 #include "../../../srs/SpatialReferenceSystemManager.h" 38 #include "../../widgets/utils/FileDialog.h" 39 #include "../../widgets/datasource/selector/DataSourceSelectorDialog.h" 40 #include "../colorbar/ColorBar.h" 41 #include "../colorbar/ColorCatalogWidget.h" 42 #include "../se/LineSymbolizerWidget.h" 43 #include "../se/PointSymbolizerWidget.h" 44 #include "../se/PolygonSymbolizerWidget.h" 45 #include "../se/SymbologyPreview.h" 47 #include "ui_RasterizationWizardPageForm.h" 50 #include <QDialogButtonBox> 51 #include <QFileDialog> 52 #include <QMessageBox> 56 #include <boost/algorithm/string.hpp> 57 #include <boost/filesystem.hpp> 58 #include <boost/lexical_cast.hpp> 59 #include <boost/property_tree/json_parser.hpp> 63 #define NO_TITLE "No Value" 72 m_ui.reset(
new Ui::RasterizationWizardPageForm);
76 m_ui->m_tableWidget->resizeColumnsToContents();
78 m_ui->m_precSpinBox->setValue(6);
80 QGridLayout* l =
new QGridLayout(
m_ui->m_colorBarWidget);
81 l->setContentsMargins(0, 0, 0, 0);
86 this->setTitle(tr(
"Rasterization"));
87 this->setSubTitle(tr(
"Define the rasterization parameters."));
119 m_ui->m_layerLineEdit->setText(
m_layer->getTitle().c_str());
124 m_ui->m_layerSRIDLabel->setText(sridName.c_str());
129 std::string dsId =
m_layer->getDataSourceId();
131 std::unique_ptr<te::da::DataSetType> dst =
m_layer->getSchema();
141 dist->push_back(propName);
146 order->push_back(obi);
153 std::unique_ptr<te::da::DataSet> result = source->query(select);
155 result->moveBeforeFirst();
157 std::vector<std::string> classes;
159 while (result->moveNext())
161 std::string className = result->getValue(attrName)->toString();
163 classes.push_back(className);
175 int reply = QMessageBox::question(
this, tr(
"Edit Legend"), tr(
"Manual changes will be lost. Continue?"), QMessageBox::Yes | QMessageBox::Cancel);
177 if (reply != QMessageBox::Yes)
181 int prec =
m_ui->m_precSpinBox->value();
183 std::string attr =
m_ui->m_attrComboBox->currentText().toUtf8().data();
184 int attrIdx =
m_ui->m_attrComboBox->currentIndex();
185 int attrType =
m_ui->m_attrComboBox->itemData(attrIdx).toInt();
196 std::vector<std::string> vec;
204 catch (
const std::exception& e)
206 QMessageBox::warning(
this, tr(
"Rasterization"), QString::fromUtf8(e.what()));
246 int curRow =
m_ui->m_tableWidget->currentRow();
247 int curCol =
m_ui->m_tableWidget->currentColumn();
253 std::vector<te::se::Symbolizer*> symbVec = rule->
getSymbolizers();
256 QBoxLayout* layout =
new QBoxLayout(QBoxLayout::TopToBottom, dialog);
258 QDialogButtonBox* bbox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
262 if (symbVec[0]->getType() ==
"PolygonSymbolizer")
268 else if (symbVec[0]->getType() ==
"LineSymbolizer")
274 else if (symbVec[0]->getType() ==
"PointSymbolizer")
281 layout->addWidget(symbWidget);
282 layout->addWidget(bbox);
284 connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
285 connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
287 if (dialog->exec() == QDialog::Rejected)
293 if (symbVec[0]->getType() ==
"PolygonSymbolizer")
299 else if (symbVec[0]->getType() ==
"LineSymbolizer")
305 else if (symbVec[0]->getType() ==
"PointSymbolizer")
317 QTableWidgetItem* newItem =
new QTableWidgetItem(icon,
"");
318 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
320 m_ui->m_tableWidget->setItem(curRow, 0, newItem);
334 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Open..."),
335 QString(), tr(
"LEG (*.leg *.LEG);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
337 if (fileName.isEmpty())
340 m_ui->m_tableWidget->setRowCount(0);
342 boost::property_tree::ptree pt;
343 boost::property_tree::json_parser::read_json(fileName.toUtf8().data(), pt);
345 boost::property_tree::ptree legend = pt.get_child(
"Legend");
347 std::string attrName = legend.get<std::string>(
"Attribute");
348 std::string precision = legend.get<std::string>(
"Precision");
350 m_ui->m_attrComboBox->setCurrentIndex(
m_ui->m_attrComboBox->findText(attrName.c_str()));
351 m_ui->m_precSpinBox->setValue(boost::lexical_cast<double>(precision));
353 std::vector<std::vector<std::string> > items;
355 for(boost::property_tree::ptree::value_type &v: legend.get_child(
"Items"))
357 std::vector<std::string> item;
358 item.push_back(v.second.get<std::string>(
"ClassName"));
359 item.push_back(v.second.get<std::string>(
"Red"));
360 item.push_back(v.second.get<std::string>(
"Green"));
361 item.push_back(v.second.get<std::string>(
"Blue"));
363 items.push_back(item);
366 m_ui->m_tableWidget->setRowCount(static_cast<int>(items.size()));
368 for (std::size_t i = 0; i < items.size(); ++i)
370 m_ui->m_tableWidget->setItem(static_cast<int>(i), 0,
new QTableWidgetItem(items[i][0].c_str()));
371 m_ui->m_tableWidget->setItem(static_cast<int>(i), 1,
new QTableWidgetItem(items[i][1].c_str()));
372 m_ui->m_tableWidget->setItem(static_cast<int>(i), 2,
new QTableWidgetItem(items[i][2].c_str()));
373 m_ui->m_tableWidget->setItem(static_cast<int>(i), 3,
new QTableWidgetItem(items[i][3].c_str()));
376 color.setRgb(boost::lexical_cast<int>(items[i][1]), boost::lexical_cast<int>(items[i][2]), boost::lexical_cast<int>(items[i][3]));
381 p.fillRect(0, 0, 12, 24, color);
382 p.fillRect(12, 0, 12, 24, color);
383 p.setBrush(Qt::transparent);
385 p.drawRect(0, 0, 23, 23);
389 QTableWidgetItem* item =
new QTableWidgetItem(icon,
"");
391 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
392 m_ui->m_tableWidget->setItem(static_cast<int>(i), 4, item);
395 QTableWidgetItem* item =
new QTableWidgetItem();
396 item->setCheckState(Qt::Checked);
397 m_ui->m_tableWidget->setItem(static_cast<int>(i), 5, item);
406 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
407 QString(), tr(
"LEG (*.leg *.LEG);;"),
nullptr, QFileDialog::DontConfirmOverwrite);
416 std::unique_ptr<te::map::LayerSchema> dsType(
m_layer->getSchema());
418 std::size_t idx=std::string::npos;
420 for (std::size_t t = 0; t < dsType->getProperties().size(); ++t)
422 if (dsType->getProperty(t)->getName() == attrName)
429 std::unique_ptr<te::da::DataSet>
ds(
m_layer->getData());
431 ds->moveBeforeFirst();
433 while (
ds->moveNext())
435 if (!
ds->isNull(idx))
436 vec.push_back(
ds->getAsString(idx));
448 int legendSize =
static_cast<int>(
m_legend.size());
450 std::vector<te::color::RGBAColor> colorVec;
452 if (meanTitle.empty())
461 for (
size_t t = 0; t <
m_legend.size(); ++t)
463 std::string ruleName = *
m_legend[t]->getName();
465 if (ruleName != meanTitle)
480 for (
size_t t = 0; t < lowerColorVec.size(); ++t)
481 colorVec.push_back(lowerColorVec[t]);
483 colorVec.push_back(meanColor);
485 for (
size_t t = 0; t < upperColorVec.size(); ++t)
486 colorVec.push_back(upperColorVec[t]);
489 if (colorVec.size() !=
m_legend.size())
494 for (
size_t t = 0; t < colorVec.size(); ++t)
496 std::vector<te::se::Symbolizer*> symbVec;
500 symbVec.push_back(s);
502 m_legend[t]->setSymbolizers(symbVec);
511 std::string* ruleName =
new std::string(
NO_TITLE);
518 std::vector<te::se::Symbolizer*> symbVec;
520 symbVec.push_back(s);
531 m_ui->m_tableWidget->setRowCount(0);
534 list.append(tr(
"Class"));
535 list.append(tr(
"R"));
536 list.append(tr(
"G"));
537 list.append(tr(
"B"));
538 list.append(tr(
"Color"));
539 list.append(tr(
"Select"));
541 m_ui->m_tableWidget->setColumnCount(6);
542 m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
562 for (std::size_t t = 0; t <
m_legend.size(); ++t)
566 int newrow =
m_ui->m_tableWidget->rowCount();
567 m_ui->m_tableWidget->insertRow(newrow);
572 std::string ruleValue;
574 QTableWidgetItem* item =
new QTableWidgetItem(QString::fromUtf8(ruleValue.c_str()));
575 item->setFlags(Qt::ItemIsEnabled);
576 m_ui->m_tableWidget->setItem(newrow, 0, item);
579 const std::vector<te::se::Symbolizer*>& ss = rule->
getSymbolizers();
586 QTableWidgetItem* item =
new QTableWidgetItem(QString::number(color.
getRed()));
587 m_ui->m_tableWidget->setItem(newrow, 1, item);
592 QTableWidgetItem* item =
new QTableWidgetItem(QString::number(color.
getGreen()));
593 m_ui->m_tableWidget->setItem(newrow, 2, item);
598 QTableWidgetItem* item =
new QTableWidgetItem(QString::number(color.
getBlue()));
599 m_ui->m_tableWidget->setItem(newrow, 3, item);
604 const std::vector<te::se::Symbolizer*>& ss = rule->
getSymbolizers();
607 QTableWidgetItem* item =
new QTableWidgetItem(icon,
"");
608 item->setFlags(Qt::ItemIsEnabled);
609 m_ui->m_tableWidget->setItem(newrow, 4, item);
614 QTableWidgetItem* item =
new QTableWidgetItem();
615 item->setCheckState(Qt::Checked);
616 m_ui->m_tableWidget->setItem(newrow, 5, item);
630 m_ui->m_tableWidget->resizeColumnsToContents();
644 QString curValue =
m_ui->m_attrComboBox->currentText();
646 m_ui->m_attrComboBox->clear();
648 std::unique_ptr<te::map::LayerSchema> dsType(
m_layer->getSchema());
650 for (
size_t t = 0; t < dsType->getProperties().size(); ++t)
672 if (curValue.isEmpty() ==
false)
674 int idx =
m_ui->m_attrComboBox->findText(curValue);
677 m_ui->m_attrComboBox->setCurrentIndex(idx);
683 int size =
m_ui->m_tableWidget->rowCount();
685 for (
int i = 0; i < size; ++i)
687 QTableWidgetItem* item =
m_ui->m_tableWidget->item(i, 5);
688 item->setCheckState(Qt::Checked);
694 int size =
m_ui->m_tableWidget->rowCount();
696 for (
int i = 0; i < size; ++i)
698 QTableWidgetItem* item =
m_ui->m_tableWidget->item(i, 5);
699 item->setCheckState(Qt::Unchecked);
705 if (
m_ui->m_resXLineEdit->text().isEmpty())
711 QMessageBox::warning(
this, tr(
"Cellular Spaces"), tr(
"Invalid bounding box."));
715 double resX =
m_ui->m_resXLineEdit->text().toDouble();
718 m_ui->m_colsLineEdit->setText(QString::number(maxCols));
723 if (
m_ui->m_resYLineEdit->text().isEmpty())
729 QMessageBox::warning(
this, tr(
"Cellular Spaces"), tr(
"Invalid bounding box."));
733 double resY =
m_ui->m_resXLineEdit->text().toDouble();
737 m_ui->m_rowsLineEdit->setText(QString::number(maxRows));
752 return m_ui->m_resXLineEdit->text().toDouble();
757 return m_ui->m_resYLineEdit->text().toDouble();
773 m_ui->m_newLayerNameLineEdit->clear();
774 m_ui->m_repositoryLineEdit->clear();
784 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
789 QMessageBox::warning(
this, tr(
"File information"), tr(
"Output layer is invalid."));
793 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
794 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
797 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
802 if (
m_ui->m_repositoryLineEdit->text().isEmpty())
805 return m_ui->m_repositoryLineEdit->text().toUtf8().data();
810 return m_ui->m_attrComboBox->currentText().toUtf8().data();
815 std::map<std::string, std::vector<int> > result;
817 for (
int i = 0; i <
m_ui->m_tableWidget->rowCount(); ++i)
819 if (
m_ui->m_tableWidget->item(i, 5)->checkState() != Qt::Checked)
823 v.push_back(static_cast<int>(i+1));
824 v.push_back(
m_ui->m_tableWidget->item(i, 1)->text().toInt());
825 v.push_back(
m_ui->m_tableWidget->item(i, 2)->text().toInt());
826 v.push_back(
m_ui->m_tableWidget->item(i, 3)->text().toInt());
828 result[
m_ui->m_tableWidget->item(i, 0)->text().toUtf8().data()] = v;
836 bool hasErrors =
false;
845 errors +=
" - " + std::string(
TE_TR(
"Layer Invalid."));
850 if (
m_ui->m_attrComboBox->currentText().isEmpty())
855 errors +=
" - " + std::string(
TE_TR(
"Attribute not selected."));
860 if (
m_ui->m_resXLineEdit->text().isEmpty() ||
m_ui->m_resYLineEdit->text().isEmpty())
865 errors +=
" - " + std::string(
TE_TR(
"Resolution not informed."));
870 if (
m_ui->m_repositoryLineEdit->text().isEmpty())
875 errors +=
" - " + std::string(
TE_TR(
"Output repository not informed."));
880 if (
m_ui->m_tableWidget->rowCount() < 1)
885 errors +=
" - " + std::string(
TE_TR(
"No legend was created. Choose the attribute and apply."));
892 std::string msg = std::string(
TE_TR(
"Some errors accured:\n\n"));
901 return m_ui->m_tableWidget;
906 int rowCount =
m_ui->m_tableWidget->rowCount();
914 boost::property_tree::ptree pt;
915 boost::property_tree::ptree legend;
917 std::string attrName =
m_ui->m_attrComboBox->currentText().toUtf8().data();
918 std::string precision =
m_ui->m_precSpinBox->text().toUtf8().data();
920 legend.add(
"Attribute", attrName);
921 legend.add(
"Precision", precision);
923 boost::property_tree::ptree items;
925 for (
int i = 0; i <
m_ui->m_tableWidget->rowCount(); ++i)
927 std::string className =
m_ui->m_tableWidget->item(i, 0)->text().toUtf8().data();
928 std::string r =
m_ui->m_tableWidget->item(i, 1)->text().toUtf8().data();
929 std::string g =
m_ui->m_tableWidget->item(i, 2)->text().toUtf8().data();
930 std::string
b =
m_ui->m_tableWidget->item(i, 3)->text().toUtf8().data();
932 boost::property_tree::ptree item;
933 item.add(
"ClassName", className);
935 item.add(
"Green", g);
938 items.add_child(
"Item", item);
941 legend.add_child(
"Items", items);
943 pt.add_child(
"Legend", legend);
945 boost::property_tree::write_json(path, pt);
void onApplyPushButtonClicked()
void onResYLineEditEditingFinished()
const Fill * getFill() const
Gets the Fill associates with the PolygonSymbolizer.
TESEEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
It gets the RGBA color from the Stroke element.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void onSelectAllPushButtonClicked()
An abstract class that models a source of data in a query.
te::gm::Envelope getEnvelope()
int getRed() const
It returns the red component color value (a value from 0 to 255).
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
A class that models the name of a dataset used in a From clause.
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
boost::shared_ptr< DataSource > DataSourcePtr
boost::ptr_vector< Expression > Distinct
A class that models a Distinct clause on a query.
A class that models the name of any property of an object.
A Symbolizer describes how a feature is to appear on a map.
std::unique_ptr< Ui::RasterizationWizardPageForm > m_ui
virtual const char * what() const
It outputs the exception message.
std::map< std::string, std::vector< int > > getInformations()
void onAttrComboBoxActivated(int idx)
TEMAPEXPORT void GroupingByUniqueValues(std::string attrName, std::vector< std::string > &inputValues, int dataType, std::vector< te::se::Rule * > &rules, int precision)
It groups the values using the unique value algorithm.
void buildSymbolizer(std::string meanTitle="")
void setName(std::string *name)
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
double m_urx
Upper right corner x-coordinate.
~RasterizationWizardPage()
int getGreen() const
It returns the green component color value (a value from 0 to 255).
const std::vector< te::color::RGBAColor > & getUpperMeanSlices(const int &n)
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
void onResXLineEditEditingFinished()
void onUnselectAllPushButtonClicked()
static te::dt::Date ds(2010, 01, 01)
void setFilter(te::fe::Filter *f)
const te::fe::Filter * getFilter() const
#define TE_TR(message)
It marks a string in order to get translated.
void applyPushButtonClicked()
It models a property definition.
te::da::DataSourceInfoPtr getDataSourceInfo()
RasterizationWizardPage(QWidget *parent=0)
This is an abstract class that models a query expression.
bool outputDataSourceToFile()
te::color::ColorBar * m_cb
Terralib color bar objetc.
const std::vector< te::color::RGBAColor > & getLowerMeanSlices(const int &n)
TEFEEXPORT te::fe::Filter * CreateFilterByUniqueValue(const std::string &attrName, const std::string &value)
double m_llx
Lower left corner x-coordinate.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
void onSavePushButtonClicked()
std::vector< std::string > getDistinctClasses(const std::string &attrName)
te::qt::widgets::ColorCatalogWidget * m_colorBar
Widget used to pick a color.
void onLoadPushButtonClicked()
te::map::AbstractLayerPtr m_layer
TerraLib layer auto ptr.
void setDistinct(Distinct *d)
If Distinct is specified, all duplicate rows are removed from the result set (one row is kept from ea...
void updateUi(bool loadColorBar=false)
Updates the widget form based on internal fill element.
A Fill specifies the pattern for filling an area geometry.
void getDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
const te::color::RGBAColor & getMeanSlice()
void setSymbolizers(const std::vector< Symbolizer * > &symbs)
void setOrderBy(OrderBy *o)
It sets the list of expressions used to sort the output result.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Select models a query to be used when retrieving data from a DataSource.
void onTargetFileToolButtonPressed()
A Symbology Enconding visitor that finds a color given a symbolizer element. If you want to use this ...
void saveLegend(const std::string &path)
const std::vector< te::color::RGBAColor > & getSlices(const int &n)
It generates color bar.
const std::vector< Symbolizer * > & getSymbolizers() const
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
double m_lly
Lower left corner y-coordinate.
std::string getAttributeName()
int getType() const
It returns the property data type.
void createStringNullGroupingItem(int count)
void find(const te::se::Symbolizer *symbolizer)
It find the color based on given symbolizer.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
double m_ury
Upper right corner y-coordinate.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
void onTableWidgetItemChanged(QTableWidgetItem *item)
It models the concept of color bar.
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
const SvgParameter * getColor() const
void onTableWidgetItemDoubleClicked(QTableWidgetItem *item)
void setLayer(te::map::AbstractLayerPtr layer)
A class that can be used in an ORDER BY clause to sort the items of a resulting query.
te::color::RGBAColor getColor()
Get the color.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::string getRepositoryName()
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...
std::vector< te::se::Rule * > m_legend
Rule items.
bool isValid() const
It tells if the rectangle is valid or not.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void setFrom(From *f)
It sets the list of source information.
QTableWidget * getTableWidget()
static const std::string sm_nanStr
Not a number string value.
const std::string & getName() const
It returns the property name.
TEFEEXPORT void GetFilterUniqueValue(const te::fe::Filter *filter, std::string &value)