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_fileDialogToolButton->setIcon(QIcon::fromTheme(
"folder-open"));
 
   77   m_ui->m_removeROIToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
 
   78   m_ui->m_exportROISetToolButton->setIcon(QIcon::fromTheme(
"document-export"));
 
   79   m_ui->m_addROIToolButton->setIcon(QIcon::fromTheme(
"list-add"));
 
   80   m_ui->m_vectorLayerToolButton->setIcon(QIcon::fromTheme(
"map-draw"));
 
   88   QGridLayout* colorPickerLayout = 
new QGridLayout(
m_ui->m_colorWidget);
 
   89   colorPickerLayout->setContentsMargins(0, 0, 0, 0);
 
   92   QGridLayout* layout = 
new QGridLayout(
m_ui->m_navigatorWidget);
 
   95   layout->setContentsMargins(0,0,0,0);
 
   96   layout->setSizeConstraint(QLayout::SetMinimumSize);
 
  110   connect(
m_ui->m_roiSetTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, 
int)), 
this, SLOT(
onROITreItemClicked(QTreeWidgetItem*, 
int)));
 
  118   if(m_vectorLayer.get())
 
  120     m_vectorLayer->setVisibility(m_vectorLayerVisibility);
 
  136   m_ui->m_layerROIComboBox->clear();
 
  137   m_ui->m_vectorLayerComboBox->clear();
 
  139   std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
 
  141   while(it != layerList.end())
 
  145     std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
 
  147     if(dsType->hasGeom())
 
  152         m_ui->m_vectorLayerComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
 
  155       if(dsType->getProperties().size() == 5 &&
 
  160         m_ui->m_layerROIComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
 
  172   m_navigator->set(layer);
 
  194   std::map<std::string, te::cl::ROI*> roiMap = m_rs->getROISet();
 
  195   std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
 
  197   while(it != roiMap.end())
 
  201     std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
 
  202     std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
 
  206     canvasInstance.setPolygonContourWidth(2);
 
  207     canvasInstance.setPolygonContourColor(rgba);
 
  208     canvasInstance.setPolygonFillColor(
te::color::RGBAColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue(), 80));
 
  210     while(itPoly != polyMap.end())
 
  214       canvasInstance.draw(poly);
 
  222   if(!m_ui->m_roiSetTreeWidget->selectedItems().isEmpty())
 
  224     QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
 
  228       std::string 
id = item->data(0, Qt::UserRole).
toString().toStdString();
 
  230       QTreeWidgetItem* parent = item->parent();
 
  232       std::string label = parent->text(0).toStdString();
 
  240       canvasInstance.setPolygonContourWidth(1);
 
  241       canvasInstance.setPolygonContourColor(rgba);
 
  242       canvasInstance.setPolygonFillColor(rgba);
 
  244       canvasInstance.draw(p);
 
  248   mapDisplay->repaint();
 
  253   int idxLayer = m_ui->m_layerROIComboBox->currentIndex();
 
  254   QVariant varLayer = m_ui->m_layerROIComboBox->itemData(idxLayer, Qt::UserRole);
 
  260   std::auto_ptr<te::da::DataSet> ds = layer->getData();
 
  265   m_ui->m_roiSetTreeWidget->clear();
 
  275     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error extracting ROISet Information. Invalid layer."));
 
  279   std::map<std::string, te::cl::ROI*> roiMap = m_rs->getROISet();
 
  280   std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
 
  282   while(it != roiMap.end())
 
  286     std::map<std::string, te::gm::Polygon*> polyMap = roi->
getPolygons();
 
  287     std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
 
  291     pix.fill(QColor(roi->
getColor().c_str()));
 
  294     QTreeWidgetItem* item = 
new QTreeWidgetItem(m_ui->m_roiSetTreeWidget, 
ROI_TREE_ITEM);
 
  295     item->setText(0, roi->
getLabel().c_str());
 
  296     item->setIcon(0, icon);
 
  298     m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
 
  300     while(itPoly != polyMap.end())
 
  305       QString sampleCounter;
 
  306       sampleCounter.setNum(m_sampleCounter);
 
  307       QString sampleName(tr(
"Sample"));
 
  309       fullName.append(sampleName);
 
  310       fullName.append(
" - ");
 
  311       fullName.append(sampleCounter);
 
  314       subItem->setText(0, fullName);
 
  315       subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
 
  316       subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
 
  317       item->addChild(subItem);
 
  318       item->setExpanded(
true);
 
  325   emit roiSetChanged(m_rs);
 
  332   if(m_ui->m_labelROILineEdit->text().isEmpty())
 
  334     QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Label is empty."));
 
  339   std::string label = m_ui->m_labelROILineEdit->text().toStdString();
 
  340   std::string color = m_colorPicker->getColor().name().toStdString();
 
  357   pix.fill(m_colorPicker->getColor());
 
  360   QTreeWidgetItem* item = 
new QTreeWidgetItem(m_ui->m_roiSetTreeWidget, 
ROI_TREE_ITEM);
 
  361   item->setText(0, roi->
getLabel().c_str());
 
  362   item->setIcon(0, icon);
 
  364   m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
 
  366   m_ui->m_labelROILineEdit->clear();
 
  368   emit roiSetChanged(m_rs);
 
  373   if(m_ui->m_roiSetTreeWidget->selectedItems().empty())
 
  375     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a item first."));
 
  379   QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
 
  383     std::string label = item->text(0).toStdString();
 
  384     m_rs->removeROI(label);
 
  390     std::string 
id = item->data(0, Qt::UserRole).toString().toStdString();
 
  392     QTreeWidgetItem* parent = item->parent();
 
  394     std::string label = parent->text(0).toStdString();
 
  400     parent->removeChild(item);
 
  403   if(m_rs && m_rs->getROISet().empty())
 
  410   emit roiSetChanged(m_rs);
 
  415   QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save ROI Set to File"), 
"", tr(
"Shape Files (*.shp *.SHP)"));
 
  417   if (fileName.isEmpty())
 
  420   QFileInfo file(fileName);
 
  422   if(file.suffix().isEmpty())
 
  423     fileName.append(
".shp");
 
  425   m_ui->m_roiSetNameLineEdit->setText(fileName);
 
  441   std::string 
id = item->data(0, Qt::UserRole).toString().toStdString();
 
  443   QTreeWidgetItem* parent = item->parent();
 
  445   std::string label = parent->text(0).toStdString();
 
  453   canvasInstance.setPolygonContourWidth(1);
 
  454   canvasInstance.setPolygonContourColor(rgba);
 
  455   canvasInstance.setPolygonFillColor(rgba);
 
  457   canvasInstance.draw(p);
 
  459   mapDisplay->repaint();
 
  465   if(m_ui->m_roiSetNameLineEdit->text().isEmpty())
 
  467     QMessageBox::warning(
this, tr(
"Warning"), tr(
"File name not defined."));
 
  470   std::string fileName = m_ui->m_roiSetNameLineEdit->text().toStdString();
 
  472   if(m_rs->getROISet().empty())
 
  474     QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Set is empty."));
 
  477   int srid = m_layer->getSRID();
 
  481     m_rs->exportToFile(fileName, srid);
 
  485     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Error exporting ROI Set."));
 
  489   QMessageBox::warning(
this, tr(
"Warning"), tr(
"ROI Set exported successfully."));
 
  496     int idxLayer = m_ui->m_vectorLayerComboBox->currentIndex();
 
  497     QVariant varLayer = m_ui->m_vectorLayerComboBox->itemData(idxLayer, Qt::UserRole);
 
  500     m_vectorLayer = layer;
 
  501     m_vectorLayerVisibility = m_layer->getVisibility();
 
  508     m_symb = symb->
clone();
 
  510     if(symb->
getType() == 
"PolygonSymbolizer")
 
  522     m_navigator->setVectorial(m_vectorLayer);
 
  523     m_navigator->hidePickerTool(
false);
 
  527     m_navigator->removeVectorial();
 
  528     m_navigator->hidePickerTool(
true);
 
  539   if(m_ui->m_roiSetTreeWidget->selectedItems().empty())
 
  541     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
 
  545   QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
 
  549     QMessageBox::warning(
this, tr(
"Warning"), tr(
"Select a ROI item first."));
 
  553   std::string label = item->text(0).toStdString();
 
  556   bool repaint = 
false;
 
  561     static boost::uuids::basic_random_generator<boost::mt19937> gen;
 
  562     boost::uuids::uuid u = gen();
 
  563     std::string 
id = boost::uuids::to_string(u);
 
  571     QString sampleCounter;
 
  572     sampleCounter.setNum(m_sampleCounter);
 
  573     QString sampleName(tr(
"Sample"));
 
  575     fullName.append(sampleName);
 
  576     fullName.append(
" - ");
 
  577     fullName.append(sampleCounter);
 
  580     subItem->setText(0, fullName);
 
  581     subItem->setData(0, Qt::UserRole, QVariant(
id.c_str()));
 
  582     subItem->setIcon(0, QIcon::fromTheme(
"file-vector"));
 
  583     item->setExpanded(
true);
 
  585     int value = item->childCount();
 
  589     item->addChild(subItem);
 
  593     m_ui->m_roiSetTreeWidget->repaint();
 
  595   emit roiSetChanged(m_rs);
 
  602   if(!m_ui->m_vectorLayerToolButton->isChecked())
 
  607   int idxLayer = m_ui->m_vectorLayerComboBox->currentIndex();
 
  608   QVariant varLayer = m_ui->m_vectorLayerComboBox->itemData(idxLayer, Qt::UserRole);
 
  620   if(!reprojectedEnvelope.
intersects(layer->getExtent()))
 
  627     std::auto_ptr<const te::map::LayerSchema> schema(layer->getSchema());
 
  628     if(!schema->hasGeom())
 
  643     while(dataset->moveNext())
 
  645       std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gp->
getName()));
 
  647       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.