27 #include "../../dataaccess/dataset/ObjectId.h" 28 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 29 #include "../../dataaccess/utils/Utils.h" 30 #include "../../geometry/Geometry.h" 31 #include "../../geometry/Utils.h" 32 #include "../../qt/widgets/canvas/Canvas.h" 33 #include "../../qt/widgets/Utils.h" 34 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 35 #include "../MakeGeometryValid.h" 37 #include "ui_CheckGeomValidityDialogForm.h" 41 #include <boost/lexical_cast.hpp> 44 #include <QMessageBox> 46 #include <QTableWidget> 47 #include <QTableWidgetItem> 52 te::vp::CheckGeomValidityDialog::CheckGeomValidityDialog(
QWidget* parent, Qt::WindowFlags f)
54 m_ui(new
Ui::CheckGeomValidityDialogForm),
55 m_mapDisplay(
nullptr),
60 m_ui->m_invalidTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
61 m_ui->m_invalidTableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
62 m_ui->m_invalidTableWidget->horizontalHeader()->setStretchLastSection(
true);
64 connect(m_ui->m_verifyPushButton, SIGNAL(clicked()),
this, SLOT(onVerifyPushButtonClicked()));
65 connect(m_ui->m_fixPushButton, SIGNAL(clicked()),
this, SLOT(onFixPushButtonClicked()));
66 connect(m_ui->m_invalidTableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)),
this, SLOT(onTableWidgetItemDoubleClicked(QTableWidgetItem*)));
68 m_ui->m_helpPushButton->setPageReference(
"widgets/utils/check_geometry_validity.html");
78 for (std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin(); it != layers.end(); ++it)
80 if(it->get()->isValid() && !it->get()->getSchema()->hasRaster())
81 m_ui->m_layersComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(*it));
86 int index =
m_ui->m_layersComboBox->findText(QString::fromUtf8(selectedLayer->getTitle().c_str()));
87 m_ui->m_layersComboBox->setCurrentIndex(index);
93 if (
m_ui->m_layersComboBox->count() < 1)
96 m_ui->m_invalidTableWidget->setRowCount(0);
98 QVariant var =
m_ui->m_layersComboBox->itemData(
m_ui->m_layersComboBox->currentIndex(), Qt::UserRole);
101 std::unique_ptr<te::da::DataSetType> schema =
m_currentLayer->getSchema();
102 std::unique_ptr<te::da::DataSet> data =
m_currentLayer->getData();
110 std::string propertyName = pk->
getProperties()[0]->getName();
111 std::size_t propertyPosition = schema->getPropertyPosition(propertyName);
115 m_oidSet->addProperty(propertyName, propertyPosition, propertyType);
117 list.append(propertyName.c_str());
120 list.append(tr(
"Message"));
122 m_ui->m_invalidTableWidget->setColumnCount(list.size());
123 m_ui->m_invalidTableWidget->setHorizontalHeaderLabels(list);
128 std::size_t size = data->size();
134 data->moveBeforeFirst();
138 while (data->moveNext())
151 if (data->isNull(pos))
154 std::unique_ptr<te::gm::Geometry> geom = data->getGeometry(pos);
161 m_ui->m_invalidTableWidget->insertRow(count);
163 QTableWidgetItem *msgItem =
new QTableWidgetItem(err.
m_message.c_str());
164 msgItem->setData(Qt::UserRole, QVariant::fromValue(err));
165 msgItem->setFlags(Qt::ItemIsEnabled);
174 QTableWidgetItem *idItem =
new QTableWidgetItem(data->getAsString(pk->
getProperties()[0]->getName()).c_str());
175 idItem->setFlags(Qt::ItemIsEnabled);
177 m_ui->m_invalidTableWidget->setItem(count, 0, idItem);
180 m_ui->m_invalidTableWidget->setItem(count, 1, msgItem);
187 m_ui->m_invalidTableWidget->insertRow(count);
189 QTableWidgetItem *msgItem =
new QTableWidgetItem(e.
what());
190 msgItem->setFlags(Qt::NoItemFlags);
194 QTableWidgetItem *idItem =
new QTableWidgetItem(data->getAsString(pk->
getProperties()[0]->getName()).c_str());
195 idItem->setFlags(Qt::NoItemFlags);
197 m_ui->m_invalidTableWidget->setItem(count, 0, idItem);
200 m_ui->m_invalidTableWidget->setItem(count, 1, msgItem);
207 m_ui->m_fixPushButton->setEnabled(
true);
209 m_ui->m_fixPushButton->setEnabled(
false);
214 QApplication::setOverrideCursor(Qt::WaitCursor);
219 std::string errorMessage;
225 bool success =
false;
233 QApplication::setOverrideCursor(Qt::ArrowCursor);
235 QMessageBox::warning(
this, tr(
"Check Geometry Validity"), errorMessage.c_str());
236 m_ui->m_verifyPushButton->setFocus();
237 m_ui->m_fixPushButton->setEnabled(
false);
242 catch (
const std::exception& e)
244 QApplication::setOverrideCursor(Qt::ArrowCursor);
246 QMessageBox::warning(
this, tr(
"Check Geometry Validity"), e.what());
247 m_ui->m_verifyPushButton->setFocus();
248 m_ui->m_fixPushButton->setEnabled(
false);
253 m_ui->m_invalidTableWidget->setRowCount(0);
255 QApplication::setOverrideCursor(Qt::ArrowCursor);
257 if(errorMessage.empty())
259 QMessageBox::information(
this, tr(
"Check Geometry Validity"), tr(
"The fix was concluded successfully. Verify the layer again!"));
263 QMessageBox::information(
this, tr(
"Check Geometry Validity"), tr(
"The operation was concluded. But some warnings had occurred.") + QString(errorMessage.c_str()));
266 m_ui->m_verifyPushButton->setFocus();
267 m_ui->m_fixPushButton->setEnabled(
false);
274 double auxX = (currEnv.
m_urx - currEnv.
m_llx) / 2;
275 double auxY = (currEnv.
m_ury - currEnv.
m_lly) / 2;
277 int row = item->row();
281 if(
m_ui->m_invalidTableWidget->columnCount() == 1)
282 var =
m_ui->m_invalidTableWidget->item(row, 0)->data(Qt::UserRole);
284 var =
m_ui->m_invalidTableWidget->item(row, 1)->data(Qt::UserRole);
298 catch (
const std::exception & e)
301 QMessageBox::warning(
this, tr(
"Check Geometry Validity"), e.what());
345 llCanvas.setX(pointCanvas.x() - 10);
346 llCanvas.setY(pointCanvas.y() - 10);
349 urCanvas.setX(pointCanvas.x() + 10);
350 urCanvas.setY(pointCanvas.y() + 10);
352 QPointF llGeo = matrix.inverted().map(llCanvas);
353 QPointF urGeo = matrix.inverted().map(urCanvas);
361 canvas->
draw(newGeom);
382 painter->setOpacity(Qt::transparent);
383 painter->drawImage(0, 0, img, 0, 0, envWidth, envHeight);
A dialog used to check geometries validity.
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
boost::shared_ptr< DataSource > DataSourcePtr
virtual const char * what() const
It outputs the exception message.
This class can be used to inform the progress of a task.
~CheckGeomValidityDialog()
Destructor.
double m_urx
Upper right corner x-coordinate.
std::unique_ptr< te::gm::Point > m_currentCoord
void addValue(te::dt::AbstractData *data)
It adds a property value to uniquely identify a data set element.
bool isActive() const
Verify if the task is active.
te::qt::widgets::MapDisplay * m_mapDisplay
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
std::unique_ptr< Ui::CheckGeomValidityDialogForm > m_ui
void setTotalSteps(int value)
Set the task total stepes.
double m_llx
Lower left corner x-coordinate.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
void ObjectId()
ObjectId example.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void onFixPushButtonClicked()
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
This class represents an unique id for a data set element.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) Q_DECLARE_METATYPE(te
void onVerifyPushButtonClicked()
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
void setLayers(std::list< te::map::AbstractLayerPtr > layers, te::map::AbstractLayerPtr selectedLayer=0)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static bool makeValid(const te::da::DataSourcePtr dataSource, const std::string &dataSetName, std::string &errorMessage, te::da::ObjectIdSet *oidSet=0)
This method gets the datasource capabilities and calls the specific function to fix geometry...
te::map::AbstractLayerPtr m_currentLayer
double m_lly
Lower left corner y-coordinate.
void setMapDisplay(te::qt::widgets::MapDisplay *md)
double m_ury
Upper right corner y-coordinate.
It describes a primary key (pk) constraint.
TEGEOMEXPORT bool CheckValidity(const Geometry *geom, te::gm::TopologyValidationError &error)
It check geometry validity using GEOS.
void onTableWidgetItemDoubleClicked(QTableWidgetItem *item)
This struct contains informations about GEOS TopologyValidationError.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onDisplayPaintEvent(QPainter *painter)
std::unique_ptr< te::da::ObjectIdSet > m_oidSet
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
std::unique_ptr< QPixmap > m_markPixmap