mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04: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>
|
||||
|
@ -86,6 +86,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
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,6 +97,10 @@ 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()) )
|
||||
@ -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 ):
|
||||
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 )
|
||||
@ -186,13 +223,23 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
QApplication.restoreOverrideCursor()
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
def runFinishedFromThread( self, output ):
|
||||
def runFinishedFromThread( self, success ):
|
||||
self.testThread.stop()
|
||||
QApplication.restoreOverrideCursor()
|
||||
self.buttonOk.setEnabled( True )
|
||||
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 output:
|
||||
for rec in success:
|
||||
if len(rec[1]) < 1:
|
||||
continue
|
||||
where = None
|
||||
@ -223,17 +270,20 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
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 )
|
||||
|
||||
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()
|
||||
|
@ -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,7 +114,68 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
@ -135,7 +185,9 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1" rowspan="2">
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -145,17 +197,12 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QProgressBar" name="partProgressBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Press Ctrl+C to copy results to the clipboard</string>
|
||||
<item row="6" column="0">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user