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 "../../../se/PolygonSymbolizer.h"
37 #include "../../../se/Fill.h"
38 #include "../../../se/Rule.h"
39 #include "../../../se/Style.h"
40 #include "../../../se/Symbolizer.h"
41 #include "../../../se/Utils.h"
42 #include "../canvas/Canvas.h"
43 #include "../canvas/MapDisplay.h"
44 #include "../rp/RasterNavigatorWidget.h"
45 #include "../utils/ColorPickerToolButton.h"
47 #include "ui_ROIManagerWidgetForm.h"
50 #include <QFileDialog>
51 #include <QGridLayout>
52 #include <QMessageBox>
59 #include <boost/uuid/random_generator.hpp>
60 #include <boost/uuid/uuid_io.hpp>
64 #define ROI_TREE_ITEM 0
65 #define ROI_POLYGON_TREE_ITEM 1
69 m_ui(new Ui::ROIManagerWidgetForm),
75 m_ui->m_openLayerROIToolButton->setIcon(QIcon::fromTheme(
"folder-open"));
76 m_ui->m_removeROIToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
77 m_ui->m_exportROISetToolButton->setIcon(QIcon::fromTheme(
"document-export"));
78 m_ui->m_addROIToolButton->setIcon(QIcon::fromTheme(
"list-add"));
79 m_ui->m_vectorLayerToolButton->setIcon(QIcon::fromTheme(
"map-draw"));
87 QGridLayout* colorPickerLayout =
new QGridLayout(
m_ui->m_colorWidget);
88 colorPickerLayout->setContentsMargins(0, 0, 0, 0);
91 QGridLayout* layout =
new QGridLayout(
m_ui->m_navigatorWidget);
94 layout->setContentsMargins(0,0,0,0);
95 layout->setSizeConstraint(QLayout::SetMinimumSize);
109 connect(
m_ui->m_roiSetTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,
int)),
this, SLOT(
onROITreItemClicked(QTreeWidgetItem*,
int)));
117 if(m_vectorLayer.get())
119 m_vectorLayer->setVisibility(m_vectorLayerVisibility);
135 m_ui->m_layerROIComboBox->clear();
136 m_ui->m_vectorLayerComboBox->clear();
138 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
140 while(it != layerList.end())
144 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
146 if(dsType->hasGeom())
151 m_ui->m_vectorLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
154 if(dsType->getProperties().size() == 5 &&
159 m_ui->m_layerROIComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
171 m_navigator->set(layer);
193 std::map<std::string, te::cl::ROI*> roiMap = m_rs->getROISet();
194 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
196 while(it != roiMap.end())
200 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
201 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
205 canvasInstance.setPolygonContourWidth(2);
206 canvasInstance.setPolygonContourColor(rgba);
207 canvasInstance.setPolygonFillColor(
te::color::RGBAColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue(), 80));
209 while(itPoly != polyMap.end())
213 canvasInstance.draw(poly);
221 if(!m_ui->m_roiSetTreeWidget->selectedItems().isEmpty())
223 QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
227 std::string
id = item->data(0, Qt::UserRole).
toString().toStdString();
229 QTreeWidgetItem* parent = item->parent();
231 std::string label = parent->text(0).toStdString();
239 canvasInstance.setPolygonContourWidth(1);
240 canvasInstance.setPolygonContourColor(rgba);
241 canvasInstance.setPolygonFillColor(rgba);
243 canvasInstance.draw(p);
247 mapDisplay->repaint();
252 int idxLayer = m_ui->m_layerROIComboBox->currentIndex();
253 QVariant varLayer = m_ui->m_layerROIComboBox->itemData(idxLayer, Qt::UserRole);
256 std::auto_ptr<te::da::DataSet> ds = layer->getData();
261 m_ui->m_roiSetTreeWidget->clear();
271 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error extracting ROISet Information. Invalid layer."));
275 std::map<std::string, te::cl::ROI*> roiMap = m_rs->getROISet();
276 std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
278 while(it != roiMap.end())
282 std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
283 std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
287 pix.fill(QColor(roi->
getColor().c_str()));
290 QTreeWidgetItem* item =
new QTreeWidgetItem(m_ui->m_roiSetTreeWidget,
ROI_TREE_ITEM);
291 item->setText(0, roi->
getLabel().c_str());
292 item->setIcon(0, icon);
294 m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
296 while(itPoly != polyMap.end())
303 QString sampleCounter;
304 sampleCounter.setNum(m_sampleCounter);
305 QString sampleName(tr(
"Sample"));
307 fullName.append(sampleName);
308 fullName.append(
" - ");
309 fullName.append(sampleCounter);
312 subItem->setText(0, fullName);
313 subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
314 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
315 item->addChild(subItem);
316 item->setExpanded(
true);
323 emit roiSetChanged(m_rs);
330 if(m_ui->m_labelROILineEdit->text().isEmpty())
332 QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Label is empty."));
337 std::string label = m_ui->m_labelROILineEdit->text().toStdString();
338 std::string color = m_colorPicker->getColor().name().toStdString();
355 pix.fill(m_colorPicker->getColor());
358 QTreeWidgetItem* item =
new QTreeWidgetItem(m_ui->m_roiSetTreeWidget,
ROI_TREE_ITEM);
359 item->setText(0, roi->
getLabel().c_str());
360 item->setIcon(0, icon);
362 m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
364 m_ui->m_labelROILineEdit->clear();
366 emit roiSetChanged(m_rs);
371 if(m_ui->m_roiSetTreeWidget->selectedItems().empty())
373 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a item first."));
377 QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
381 std::string label = item->text(0).toStdString();
382 m_rs->removeROI(label);
388 std::string
id = item->data(0, Qt::UserRole).toString().toStdString();
390 QTreeWidgetItem* parent = item->parent();
392 std::string label = parent->text(0).toStdString();
398 parent->removeChild(item);
401 if(m_rs && m_rs->getROISet().empty())
408 emit roiSetChanged(m_rs);
413 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save ROI Set to File"),
"", tr(
"Shape Files (*.shp *.SHP)"));
415 if (fileName.isEmpty())
418 QFileInfo file(fileName);
420 if(file.suffix().isEmpty())
421 fileName.append(
".shp");
423 m_ui->m_roiSetNameLineEdit->setText(fileName);
439 std::string
id = item->data(0, Qt::UserRole).toString().toStdString();
441 QTreeWidgetItem* parent = item->parent();
443 std::string label = parent->text(0).toStdString();
451 canvasInstance.setPolygonContourWidth(1);
452 canvasInstance.setPolygonContourColor(rgba);
453 canvasInstance.setPolygonFillColor(rgba);
455 canvasInstance.draw(p);
457 mapDisplay->repaint();
463 if(m_ui->m_roiSetNameLineEdit->text().isEmpty())
465 QMessageBox::warning(
this, tr(
"Warning"), tr(
"File name not defined."));
468 std::string fileName = m_ui->m_roiSetNameLineEdit->text().toStdString();
470 if(m_rs->getROISet().empty())
472 QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Set is empty."));
475 int srid = m_layer->getSRID();
479 m_rs->exportToFile(fileName, srid);
483 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error exporting ROI Set."));
487 QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Set exported successfully."));
494 int idxLayer = m_ui->m_vectorLayerComboBox->currentIndex();
495 QVariant varLayer = m_ui->m_vectorLayerComboBox->itemData(idxLayer, Qt::UserRole);
498 m_vectorLayer = layer;
499 m_vectorLayerVisibility = m_layer->getVisibility();
506 m_symb = symb->
clone();
508 if(symb->
getType() ==
"PolygonSymbolizer")
520 m_navigator->setVectorial(m_vectorLayer);
521 m_navigator->hidePickerTool(
false);
525 m_navigator->removeVectorial();
526 m_navigator->hidePickerTool(
true);
537 if(m_ui->m_roiSetTreeWidget->selectedItems().empty())
539 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
543 QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
547 QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
551 std::string label = item->text(0).toStdString();
557 static boost::uuids::basic_random_generator<boost::mt19937> gen;
558 boost::uuids::uuid u = gen();
559 std::string
id = boost::uuids::to_string(u);
567 QString sampleCounter;
568 sampleCounter.setNum(m_sampleCounter);
569 QString sampleName(tr(
"Sample"));
571 fullName.append(sampleName);
572 fullName.append(
" - ");
573 fullName.append(sampleCounter);
576 subItem->setText(0, fullName);
577 subItem->setData(0, Qt::UserRole, QVariant(
id.c_str()));
578 subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
579 item->addChild(subItem);
580 item->setExpanded(
true);
583 emit roiSetChanged(m_rs);
590 if(!m_ui->m_vectorLayerToolButton->isChecked())
595 int idxLayer = m_ui->m_vectorLayerComboBox->currentIndex();
596 QVariant varLayer = m_ui->m_vectorLayerComboBox->itemData(idxLayer, Qt::UserRole);
608 if(!reprojectedEnvelope.
intersects(layer->getExtent()))
615 std::auto_ptr<const te::map::LayerSchema> schema(layer->getSchema());
616 if(!schema->hasGeom())
631 while(dataset->moveNext())
633 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gp->
getName()));
635 if(g->contains(&point) || g->crosses(geometryFromEnvelope.get()) || geometryFromEnvelope->contains(g.get()))
const Fill * getFill() const
Gets the Fill associates with the PolygonSymbolizer.
MultiPolygon is a MultiSurface whose elements are Polygons.
#define TE_CL_ROI_LABEL_NAME
This mark defines the label attribute name.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
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 ...
A Symbolizer describes how a feature is to appear on a map.
static te::cl::ROISet * createROISet(std::auto_ptr< te::da::DataSet > ds)
Imports the ROISet from a dataset.
double m_urx
Upper right corner x-coordinate.
void addPolygon(te::gm::Polygon *p, std::string id)
Add a new region into this ROI.
An utility struct for representing 2D coordinates.
A ROISet is a set of ROI's.
Rule * getRule(std::size_t i) const
Coord2D getCenter() const
It returns the rectangle's center coordinate.
double m_llx
Lower left corner x-coordinate.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
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.
#define TE_CL_ROI_GEOM_ID_NAME
This mark defines the geom id attribute name.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
std::string toString() const
It returns the data value in a WKT representation.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
std::string getLabel()
Get the ROI label.
Symbolizer * clone() const
It creates a new copy of this object.
void setFill(Fill *f)
A Fill specifies the pattern for filling an area geometry.
void setSymbolizer(std::size_t i, Symbolizer *s)
#define TE_CL_ROI_COLOR_NAME
This mark defines the color attribute name.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
virtual const std::string & getType() const =0
It returns the symbolizer type.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
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
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.
const std::string & getName() const
It returns the property name.
std::string getColor()
Get the ROI color defined by a hexadecimal color name.