mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[FEATURE] Possibility to save error messages as shapefile from check
geometry validity tool. Contributed by Salvatore Larosa
This commit is contained in:
parent
677c9ca280
commit
24e259bdb3
@ -830,6 +830,11 @@ sono stati ridotti a %2 dopo la semplificazione</translation>
|
||||
<source>Press Ctrl+C to copy results to the clipboard</source>
|
||||
<translation>Premi Ctrl+C per copiare i risultati negli appunti</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../python/plugins/fTools/tools/frmVisual.ui" line="120"/>
|
||||
<source>Save errors location</source>
|
||||
<translation>Salva posizione errori</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Sum line lengths</source>
|
||||
<translation>Somma lunghezza linee</translation>
|
||||
|
@ -60,7 +60,7 @@ class MarkerErrorGeometry():
|
||||
|
||||
def reset(self):
|
||||
if not self.__marker is None:
|
||||
self.__canvas.scene().removeItem(self.__marker)
|
||||
self.__canvas.scene().removeItem(self.__marker)
|
||||
del self.__marker
|
||||
self.__marker = None
|
||||
|
||||
@ -83,9 +83,10 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
self.tblUnique.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
# populate list of available layers
|
||||
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
|
||||
self.connect(self.tblUnique, SIGNAL("currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)" ),
|
||||
self.connect(self.tblUnique, SIGNAL("currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)" ),
|
||||
self.zoomToError)
|
||||
self.inShape.addItems( myList )
|
||||
self.buttonBox_2.setOrientation(Qt.Horizontal)
|
||||
self.cancel_close = self.buttonBox_2.button(QDialogButtonBox.Close)
|
||||
self.buttonOk = self.buttonBox_2.button(QDialogButtonBox.Ok)
|
||||
self.progressBar.setValue(0)
|
||||
@ -96,12 +97,16 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
settings = QSettings()
|
||||
self.restoreGeometry( settings.value("/fTools/ValidateDialog/geometry").toByteArray() )
|
||||
|
||||
QObject.connect( self.browseShpError, SIGNAL( "clicked()" ), self.outFile )
|
||||
QObject.connect( self.ckBoxShpError, SIGNAL( "stateChanged( int )" ), self.updateGui )
|
||||
self.updateGui()
|
||||
|
||||
def closeEvent(self, e):
|
||||
settings = QSettings()
|
||||
settings.setValue( "/fTools/ValidateDialog/geometry", QVariant(self.saveGeometry()) )
|
||||
QDialog.closeEvent(self, e)
|
||||
del self.marker
|
||||
|
||||
|
||||
def keyPressEvent( self, e ):
|
||||
if ( e.modifiers() == Qt.ControlModifier or \
|
||||
e.modifiers() == Qt.MetaModifier ) and \
|
||||
@ -122,10 +127,37 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
QMessageBox.information( self, self.tr("Error!"), self.tr( "Please specify input vector layer" ) )
|
||||
elif self.cmbField.isVisible() and self.cmbField.currentText() == "":
|
||||
QMessageBox.information( self, self.tr("Error!"), self.tr( "Please specify input field" ) )
|
||||
elif self.ckBoxShpError.isChecked() and self.lineEditShpError.text() == "":
|
||||
QMessageBox.information( self, self.tr( "Error!" ), self.tr( "Please specify output shapefile" ) )
|
||||
else:
|
||||
self.vlayer = ftools_utils.getVectorLayerByName( self.inShape.currentText() )
|
||||
self.validate( self.useSelected.checkState() )
|
||||
|
||||
|
||||
def updateGui( self ):
|
||||
if self.ckBoxShpError.isChecked():
|
||||
self.lineEditShpError.setEnabled( True )
|
||||
self.browseShpError.setEnabled( True )
|
||||
self.tblUnique.setEnabled( False )
|
||||
self.lstCount.setEnabled( False )
|
||||
self.label_2.setEnabled( False )
|
||||
self.label_4.setEnabled( False )
|
||||
self.label_5.setEnabled( False )
|
||||
else:
|
||||
self.lineEditShpError.setEnabled( False )
|
||||
self.browseShpError.setEnabled( False )
|
||||
self.tblUnique.setEnabled( True )
|
||||
self.lstCount.setEnabled( True )
|
||||
self.label_2.setEnabled( True )
|
||||
self.label_4.setEnabled( True )
|
||||
self.label_5.setEnabled( True )
|
||||
|
||||
def outFile( self ):
|
||||
self.lineEditShpError.clear()
|
||||
(self.shapefileName, self.encoding) = ftools_utils.saveDialog( self )
|
||||
if self.shapefileName is None or self.encoding is None:
|
||||
return
|
||||
self.lineEditShpError.setText( QString( self.shapefileName ) )
|
||||
|
||||
def zoomToError(self, curr, prev):
|
||||
if curr is None:
|
||||
return
|
||||
@ -162,11 +194,16 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
mc.refresh()
|
||||
|
||||
def validate( self, mySelection ):
|
||||
self.tblUnique.clearContents()
|
||||
self.tblUnique.setRowCount( 0 )
|
||||
self.lstCount.clear()
|
||||
if not self.ckBoxShpError.isChecked():
|
||||
self.tblUnique.clearContents()
|
||||
self.tblUnique.setRowCount( 0 )
|
||||
self.lstCount.clear()
|
||||
self.shapefileName = None
|
||||
self.encoding = None
|
||||
|
||||
self.buttonOk.setEnabled( False )
|
||||
self.testThread = validateThread( self.iface.mainWindow(), self, self.vlayer, mySelection )
|
||||
|
||||
self.testThread = validateThread( self.iface.mainWindow(), self, self.vlayer, mySelection, self.shapefileName, self.encoding, self.ckBoxShpError.isChecked() )
|
||||
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
|
||||
QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
|
||||
QObject.connect( self.testThread, SIGNAL( "runRange(PyQt_PyObject)" ), self.runRangeFromThread )
|
||||
@ -180,60 +217,73 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
# Remove Marker
|
||||
self.marker.reset()
|
||||
QDialog.reject(self)
|
||||
|
||||
|
||||
def cancelThread( self ):
|
||||
self.testThread.stop()
|
||||
QApplication.restoreOverrideCursor()
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
def runFinishedFromThread( self, output ):
|
||||
|
||||
def runFinishedFromThread( self, success ):
|
||||
self.testThread.stop()
|
||||
QApplication.restoreOverrideCursor()
|
||||
self.buttonOk.setEnabled( True )
|
||||
self.tblUnique.setColumnCount( 2 )
|
||||
count = 0
|
||||
for rec in output:
|
||||
if len(rec[1]) < 1:
|
||||
continue
|
||||
where = None
|
||||
for err in rec[1]: # for each error we find
|
||||
self.tblUnique.insertRow(count)
|
||||
fidItem = QTableWidgetItem( str(rec[0]) )
|
||||
self.tblUnique.setItem( count, 0, fidItem )
|
||||
message = err.what()
|
||||
errItem = QTableWidgetItem( message )
|
||||
if err.hasWhere(): # if there is a location associated with the error
|
||||
errItem.setData(Qt.UserRole, QVariant(err.where()))
|
||||
self.tblUnique.setItem( count, 1, errItem )
|
||||
count += 1
|
||||
self.tblUnique.setHorizontalHeaderLabels( [ self.tr("Feature"), self.tr("Error(s)") ] )
|
||||
self.tblUnique.horizontalHeader().setResizeMode( 0, QHeaderView.ResizeToContents )
|
||||
self.tblUnique.horizontalHeader().show()
|
||||
self.tblUnique.horizontalHeader().setResizeMode( 1, QHeaderView.Stretch )
|
||||
self.tblUnique.resizeRowsToContents()
|
||||
self.lstCount.insert(str(count))
|
||||
if success == "writeShape":
|
||||
extra = ""
|
||||
addToTOC = QMessageBox.question( self, self.tr("Geometry"),
|
||||
self.tr( "Created output shapefile:\n%1\n%2\n\nWould you like to add the new layer to the TOC?" ).arg( unicode( self.shapefileName ) ).arg( extra ),
|
||||
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton )
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr( "Geometry"),
|
||||
self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ) )
|
||||
else:
|
||||
self.tblUnique.setColumnCount( 2 )
|
||||
count = 0
|
||||
for rec in success:
|
||||
if len(rec[1]) < 1:
|
||||
continue
|
||||
where = None
|
||||
for err in rec[1]: # for each error we find
|
||||
self.tblUnique.insertRow(count)
|
||||
fidItem = QTableWidgetItem( str(rec[0]) )
|
||||
self.tblUnique.setItem( count, 0, fidItem )
|
||||
message = err.what()
|
||||
errItem = QTableWidgetItem( message )
|
||||
if err.hasWhere(): # if there is a location associated with the error
|
||||
errItem.setData(Qt.UserRole, QVariant(err.where()))
|
||||
self.tblUnique.setItem( count, 1, errItem )
|
||||
count += 1
|
||||
self.tblUnique.setHorizontalHeaderLabels( [ self.tr("Feature"), self.tr("Error(s)") ] )
|
||||
self.tblUnique.horizontalHeader().setResizeMode( 0, QHeaderView.ResizeToContents )
|
||||
self.tblUnique.horizontalHeader().show()
|
||||
self.tblUnique.horizontalHeader().setResizeMode( 1, QHeaderView.Stretch )
|
||||
self.tblUnique.resizeRowsToContents()
|
||||
self.lstCount.insert(str(count))
|
||||
self.cancel_close.setText( "Close" )
|
||||
QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
|
||||
return True
|
||||
|
||||
|
||||
def runStatusFromThread( self, status ):
|
||||
self.progressBar.setValue( status )
|
||||
|
||||
|
||||
def runRangeFromThread( self, range_vals ):
|
||||
self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )
|
||||
|
||||
class validateThread( QThread ):
|
||||
def __init__( self, parentThread, parentObject, vlayer, mySelection ):
|
||||
def __init__( self, parentThread, parentObject, vlayer, mySelection, myName, myEncoding, myNewShape ):
|
||||
QThread.__init__( self, parentThread )
|
||||
self.parent = parentObject
|
||||
self.running = False
|
||||
self.vlayer = vlayer
|
||||
self.mySelection = mySelection
|
||||
self.myName = myName
|
||||
self.myEncoding = myEncoding
|
||||
self.writeShape = myNewShape
|
||||
|
||||
def run( self ):
|
||||
self.running = True
|
||||
output = self.check_geometry( self.vlayer )
|
||||
self.emit( SIGNAL( "runFinished(PyQt_PyObject)" ), output )
|
||||
success = self.check_geometry( self.vlayer )
|
||||
self.emit( SIGNAL( "runFinished(PyQt_PyObject)" ), success )
|
||||
|
||||
def stop(self):
|
||||
self.running = False
|
||||
@ -265,4 +315,30 @@ class validateThread( QThread ):
|
||||
if not geom.isGeosEmpty():
|
||||
lstErrors.append((feat.id(), list(geom.validateGeometry())))
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat )
|
||||
return lstErrors
|
||||
|
||||
if self.writeShape:
|
||||
fields = { 0 : QgsField( "FEAT_ID", QVariant.Int ),
|
||||
1 : QgsField( "ERROR", QVariant.String ) }
|
||||
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
|
||||
QGis.WKBPoint, vlayer.crs() )
|
||||
for rec in lstErrors:
|
||||
if len(rec[1]) < 1:
|
||||
continue
|
||||
for err in rec[1]:
|
||||
fidItem = str(rec[0])
|
||||
message = err.what()
|
||||
if err.hasWhere():
|
||||
locErr = err.where()
|
||||
xP = locErr.x()
|
||||
yP = locErr.y()
|
||||
myPoint = QgsPoint( xP, yP )
|
||||
geometry = QgsGeometry().fromPoint( myPoint )
|
||||
ft = QgsFeature()
|
||||
ft.setGeometry( geometry )
|
||||
ft.setAttributeMap( { 0 : QVariant( fidItem ),
|
||||
1 : QVariant( message ) } )
|
||||
writer.addFeature( ft )
|
||||
del writer
|
||||
return "writeShape"
|
||||
else:
|
||||
return lstErrors
|
||||
|
@ -41,6 +41,15 @@ class VisualDialog( QDialog, Ui_Dialog ):
|
||||
self.iface = iface
|
||||
self.setupUi( self )
|
||||
self.myFunction = function
|
||||
|
||||
## Set object visibility to False if tool is not Check geometry
|
||||
self.ckBoxShpError.hide()
|
||||
self.browseShpError.hide()
|
||||
self.lineEditShpError.hide()
|
||||
self.label_6.hide()
|
||||
self.line.hide()
|
||||
self.buttonBox_2.setOrientation(Qt.Horizontal)
|
||||
|
||||
if self.myFunction == 2 or self.myFunction == 3:
|
||||
QObject.connect( self.inShape, SIGNAL( "currentIndexChanged(QString)" ), self.update )
|
||||
self.manageGui()
|
||||
@ -289,7 +298,7 @@ class visualThread( QThread ):
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
|
||||
else: # there is no selection, process the whole layer
|
||||
nFeat = vprovider.featureCount()
|
||||
if nFeat > 0:
|
||||
if nFeat > 0:
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
|
||||
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
|
||||
vprovider.select( allAttrs )
|
||||
@ -355,7 +364,7 @@ class visualThread( QThread ):
|
||||
else: # there is no selection, process the whole layer
|
||||
nFeat = vprovider.featureCount()
|
||||
uniqueVal = ftools_utils.getUniqueValuesCount( vlayer, index, False )
|
||||
if nFeat > 0:
|
||||
if nFeat > 0:
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
|
||||
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
|
||||
vprovider.select( allAttrs )
|
||||
|
@ -9,8 +9,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>404</width>
|
||||
<height>481</height>
|
||||
<width>370</width>
|
||||
<height>484</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -20,7 +20,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
@ -34,18 +34,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useSelected">
|
||||
<property name="text">
|
||||
<string>Use only selected features</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="2" column="0">
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
@ -59,7 +48,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="3" column="0">
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
@ -107,7 +96,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
@ -125,40 +114,98 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1" rowspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QProgressBar" name="partProgressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="ckBoxShpError">
|
||||
<property name="text">
|
||||
<string>Save errors location</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Press Ctrl+C to copy results to the clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditShpError">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="browseShpError">
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Output point shapefile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useSelected">
|
||||
<property name="text">
|
||||
<string>Use only selected features</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QProgressBar" name="partProgressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user