27 #include "../../../classification/ROI.h" 28 #include "../../../classification/ROISet.h" 29 #include "../../../dataaccess/utils/Utils.h" 30 #include "../../../geometry/Coord2D.h" 31 #include "../../../geometry/Geometry.h" 32 #include "../../../geometry/GeometryProperty.h" 33 #include "../../../geometry/MultiPolygon.h" 34 #include "../../../geometry/Point.h" 35 #include "../../../geometry/Utils.h" 36 #include "../../../dataaccess/dataset/DataSetType.h" 37 #include "../../../dataaccess/dataset/DataSetAdapter.h" 38 #include "../../../dataaccess/dataset/DataSetTypeConverter.h" 39 #include "../../../dataaccess/datasource/DataSourceFactory.h" 40 #include "../../../se/PolygonSymbolizer.h" 41 #include "../../../se/Fill.h" 42 #include "../../../se/Rule.h" 43 #include "../../../se/Style.h" 44 #include "../../../se/Symbolizer.h" 45 #include "../../../se/Utils.h" 46 #include "../../widgets/Utils.h" 47 #include "../canvas/Canvas.h" 48 #include "../canvas/MapDisplay.h" 49 #include "../rp/RpToolsWidget.h" 50 #include "../utils/ColorPickerToolButton.h" 52 #include "ui_ROIManagerWidgetForm.h" 55 #include <QFileDialog> 56 #include <QGridLayout> 57 #include <QMessageBox> 64 #include <boost/uuid/random_generator.hpp> 65 #include <boost/filesystem.hpp> 66 #include <boost/uuid/uuid_io.hpp> 70 #define ROI_TREE_ITEM 0 71 #define ROI_POLYGON_TREE_ITEM 1 75 m_ui(new
Ui::ROIManagerWidgetForm),
76 m_mapDisplay(nullptr),
82 m_ui->m_openLayerROIToolButton->setIcon(QIcon::fromTheme(
"folder-open"));
83 m_ui->m_fileDialogToolButton->setIcon(QIcon::fromTheme(
"folder-open"));
84 m_ui->m_removeROIToolButton->setIcon(QIcon::fromTheme(
"edit-deletetool"));
85 m_ui->m_exportROISetToolButton->setIcon(QIcon::fromTheme(
"document-export"));
86 m_ui->m_addROIToolButton->setIcon(QIcon::fromTheme(
"list-add"));
90 m_colorPicker->setFixedSize(70, 24);
91 m_colorPicker->setColor(QColor(255, 255, 0, 128));
94 QGridLayout* colorPickerLayout =
new QGridLayout(m_ui->m_colorWidget);
95 colorPickerLayout->setContentsMargins(0, 0, 0, 0);
96 colorPickerLayout->addWidget(m_colorPicker);
98 QGridLayout* layout =
new QGridLayout(m_ui->m_navigatorWidget);
100 layout->addWidget(m_navigator.get(), 0, 0);
101 layout->setContentsMargins(0,0,0,0);
102 layout->setSizeConstraint(QLayout::SetMinimumSize);
105 connect(m_ui->m_openLayerROIToolButton, SIGNAL(clicked()),
this, SLOT(onOpenLayerROIToolButtonClicked()));
106 connect(m_ui->m_addROIToolButton, SIGNAL(clicked()),
this, SLOT(onAddROIToolButtonClicked()));
107 connect(m_ui->m_removeROIToolButton, SIGNAL(clicked()),
this, SLOT(onRemoveROIToolButtonClicked()));
108 connect(m_ui->m_fileDialogToolButton, SIGNAL(clicked()),
this, SLOT(onFileDialogToolButtonClicked()));
109 connect(m_ui->m_exportROISetToolButton, SIGNAL(clicked()),
this, SLOT(onExportROISetToolButtonClicked()));
111 connect(m_ui->m_layerROIComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onLayerComboBoxChanged(
int)));
112 connect(m_ui->m_layerROIComboBox, SIGNAL(activated(
int)),
this, SLOT(onLayerComboBoxChanged(
int)));
152 m_ui->m_layerROIComboBox->clear();
154 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
156 while(it != layerList.end())
160 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
162 if(dsType->hasGeom())
164 if(dsType->getProperties().size() == 5 &&
169 m_ui->m_layerROIComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
199 std::map<std::string, te::cl::ROI*> roiMap =
m_rs->
getROISet();
200 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
202 while(it != roiMap.end())
206 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
207 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
211 canvasInstance.setPolygonContourWidth(2);
212 canvasInstance.setPolygonContourColor(rgba);
213 canvasInstance.setPolygonFillColor(
te::color::RGBAColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue(), 80));
215 while(itPoly != polyMap.end())
222 canvasInstance.draw(poly);
230 if(!
m_ui->m_roiSetTreeWidget->selectedItems().isEmpty())
236 std::string
id = item->data(0, Qt::UserRole).toString().toUtf8().data();
240 std::string label = parent->text(0).toUtf8().data();
248 canvasInstance.setPolygonContourWidth(1);
249 canvasInstance.setPolygonContourColor(rgba);
250 canvasInstance.setPolygonFillColor(rgba);
255 canvasInstance.draw(p);
265 "Shape Files (*.shp *.SHP)");
267 if(inputFile.isEmpty())
270 boost::filesystem::path uri(inputFile.toUtf8().data());
272 QFileInfo inf(inputFile);
276 std::string fileName = inf.baseName().toUtf8().data();
278 std::string dsInf(
"file://" + uri.string());
284 std::unique_ptr<te::da::DataSetType> dsType = dsPtr->getDataSetType(fileName);
286 if(dsType->hasGeom())
288 if(!(dsType->getProperties().size() == 5 &&
293 QMessageBox::warning(
this, tr(
"Classifier"), tr(
"The layer informed does not have ROI properties."));
299 QMessageBox::warning(
this, tr(
"Classifier"), tr(
"The layer informed does not have geometries."));
303 std::unique_ptr<te::da::DataSet>
ds = dsPtr->getDataSet(fileName);
307 std::unique_ptr<te::da::DataSetTypeConverter> converter(
309 dsPtr->getCapabilities(),
310 dsPtr->getEncoding()));
314 std::unique_ptr<te::da::DataSet> dsLayer = dsPtr->getDataSet(fileName);
329 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error extracting ROISet Information. Invalid layer."));
333 std::map<std::string, te::cl::ROI*> roiMap = importedROISet->
getROISet();
334 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
338 QMessageBox::warning(
this, tr(
"Warning"), tr(
"The samples imported does not intersects the raster extent."));
342 m_ui->m_layerROIComboBox->clear();
344 m_ui->m_layerROIComboBox->addItem(inf.baseName());
346 m_ui->m_roiSetTreeWidget->clear();
350 while(it != roiMap.end())
354 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
355 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
359 pix.fill(QColor(roi->
getColor().c_str()).rgba());
363 item->setText(0, roi->
getLabel().c_str());
364 item->setIcon(0, icon);
366 m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
368 while(itPoly != polyMap.end())
373 QString sampleCounter;
375 QString sampleName(tr(
"Sample"));
377 fullName.append(sampleName);
378 fullName.append(
" - ");
379 fullName.append(sampleCounter);
382 subItem->setText(0, fullName);
383 subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
384 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
385 item->addChild(subItem);
386 item->setExpanded(
true);
396 m_rs = importedROISet;
403 if(
m_ui->m_labelROILineEdit->text().isEmpty())
405 QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Label is empty."));
410 std::string label =
m_ui->m_labelROILineEdit->text().toUtf8().data();
423 std::map<std::string, te::cl::ROI*>::iterator it =
m_rs->
getROISet().find(label);
427 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Duplicated label is not allowed."));
440 item->setText(0, roi->
getLabel().c_str());
441 item->setIcon(0, icon);
443 m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
445 m_ui->m_labelROILineEdit->clear();
450 if (
m_ui->m_roiSetTreeWidget->selectedItems().empty())
452 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a item first."));
460 std::string label = item->text(0).toUtf8().data();
467 std::string
id = item->data(0, Qt::UserRole).toString().toUtf8().data();
471 std::string label = parent->text(0).toUtf8().data();
477 parent->removeChild(item);
492 if (fileName.isEmpty())
495 QFileInfo
file(fileName);
499 if(file.suffix().isEmpty())
500 fileName.append(
".shp");
502 m_ui->m_roiSetNameLineEdit->setText(fileName);
517 std::string
id = item->data(0, Qt::UserRole).toString().toUtf8().data();
521 std::string label = parent->text(0).toUtf8().data();
529 canvasInstance.setPolygonContourWidth(1);
530 canvasInstance.setPolygonContourColor(rgba);
531 canvasInstance.setPolygonFillColor(rgba);
533 canvasInstance.draw(p);
540 QVariant varLayer =
m_ui->m_layerROIComboBox->itemData(index, Qt::UserRole);
546 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
550 std::unique_ptr<te::da::DataSetType> dsType = dsPtr->getDataSetType(layer->getTitle());
554 std::unique_ptr<te::da::DataSetTypeConverter> converter(
556 dsPtr->getCapabilities(),
557 dsPtr->getEncoding()));
561 std::unique_ptr<te::da::DataSet> dsLayer = dsPtr->getDataSet(layer->getTitle());
576 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error extracting ROISet Information. Invalid layer."));
580 std::map<std::string, te::cl::ROI*> roiMap = importedROISet->
getROISet();
581 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
585 QMessageBox::warning(
this, tr(
"Warning"), tr(
"The samples imported does not intersects the raster extent."));
589 m_ui->m_roiSetTreeWidget->clear();
593 while(it != roiMap.end())
597 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
598 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
602 pix.fill(QColor(roi->
getColor().c_str()).rgba());
606 item->setText(0, roi->
getLabel().c_str());
607 item->setIcon(0, icon);
609 m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
611 while(itPoly != polyMap.end())
616 QString sampleCounter;
618 QString sampleName(tr(
"Sample"));
620 fullName.append(sampleName);
621 fullName.append(
" - ");
622 fullName.append(sampleCounter);
625 subItem->setText(0, fullName);
626 subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
627 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
628 item->addChild(subItem);
629 item->setExpanded(
true);
639 m_rs = importedROISet;
646 if(
m_ui->m_roiSetNameLineEdit->text().isEmpty())
648 QMessageBox::warning(
this, tr(
"Warning"), tr(
"File name not defined."));
651 std::string fileName =
m_ui->m_roiSetNameLineEdit->text().toUtf8().data();
655 QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Set is empty."));
667 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error exporting ROI Set."));
671 QMessageBox::information(
this, tr(
"Classifier"), tr(
"ROI Set exported successfully."));
692 if(symb->
getType() ==
"PolygonSymbolizer")
719 if (
m_ui->m_roiSetTreeWidget->selectedItems().empty())
721 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
729 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
733 std::string label = item->text(0).toUtf8().data();
736 bool repaint =
false;
746 static boost::uuids::basic_random_generator<boost::mt19937> gen;
747 boost::uuids::uuid u = gen();
748 std::string
id = boost::uuids::to_string(u);
756 QString sampleCounter;
758 QString sampleName(tr(
"Sample"));
760 fullName.append(sampleName);
761 fullName.append(
" - ");
762 fullName.append(sampleCounter);
765 subItem->setText(0, fullName);
766 subItem->setData(0, Qt::UserRole, QVariant(
id.c_str()));
767 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
768 item->setExpanded(
true);
770 int value = item->childCount();
775 item->addChild(subItem);
780 m_ui->m_roiSetTreeWidget->repaint();
789 std::map<std::string, te::cl::ROI*> roiMap = rs->
getROISet();
790 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
792 while(it != roiMap.end())
796 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
797 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
799 while(itPoly != polyMap.end())
821 if(
m_ui->m_roiSetTreeWidget->selectedItems().empty())
823 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
831 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
836 std::string label = item->text(0).toUtf8().data();
839 bool repaint =
false;
844 static boost::uuids::basic_random_generator<boost::mt19937> gen;
845 boost::uuids::uuid u = gen();
846 std::string
id = boost::uuids::to_string(u);
854 QString sampleCounter;
856 QString sampleName(tr(
"Sample"));
858 fullName.append(sampleName);
859 fullName.append(
" - ");
860 fullName.append(sampleCounter);
863 subItem->setText(0, fullName);
864 subItem->setData(0, Qt::UserRole, QVariant(
id.c_str()));
865 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
866 item->setExpanded(
true);
868 int value = item->childCount();
872 item->addChild(subItem);
877 m_ui->m_roiSetTreeWidget->repaint();
886 canvasInstance.
clear();
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
te::cl::ROI * getROI(std::string label)
Gets a ROI from this set.
const Fill * getFill() const
Gets the Fill associates with the PolygonSymbolizer.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
void transform(int srid)
It converts the coordinate values of the geometry to the new spatial reference system.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A Symbolizer describes how a feature is to appear on a map.
double m_urx
Upper right corner x-coordinate.
void addPolygon(te::gm::Polygon *p, std::string id)
Add a new region into this ROI.
static te::dt::Date ds(2010, 01, 01)
#define TE_CL_ROI_GEOM_ID_NAME
This mark defines the geom id attribute name.
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
void addROI(te::cl::ROI *roi)
Add a new ROI to this set.
void exportToFile(std::string fileName, int srid)
Export the ROISet to a shapefile.
A ROISet is a set of ROI's.
An converter for DataSetType.
Rule * getRule(std::size_t i) const
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
static te::cl::ROISet * createROISet(std::unique_ptr< te::da::DataSet > ds)
Imports the ROISet from a dataset.
double m_llx
Lower left corner x-coordinate.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
#define TE_CL_ROI_COLOR_NAME
This mark defines the color attribute name.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
#define TE_CL_ROI_LABEL_NAME
This mark defines the label attribute name.
void removeROI(std::string label)
Removes a ROI from this set.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void setOpacity(const std::string &opacity)
A Fill specifies the pattern for filling an area geometry.
void setColor(std::string color)
Set the ROI color using the hexadecimal color name.
A region of interest (often abbreviated ROI), is a selected subset of samples within a dataset identi...
double m_lly
Lower left corner y-coordinate.
Fill * clone() const
It creates a new copy of this object.
void removePolygon(std::string id)
Removes a region from this ROI.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
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.
virtual const std::string & getType() const =0
It returns the symbolizer type.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
std::string getLabel()
Get the ROI label.
void setFill(Fill *f)
A Fill specifies the pattern for filling an area geometry.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
void setSymbolizer(std::size_t i, Symbolizer *s)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
const Symbolizer * getSymbolizer(std::size_t i) const
bool isValid() const
It tells if the rectangle is valid or not.
std::map< std::string, te::cl::ROI * > & getROISet()
Get the roi set map.
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
std::map< std::string, te::gm::Polygon * > & getPolygons()
Get all polygons belongs to this roi.
std::string getColor()
Get the ROI color defined by a hexadecimal color name.