Skip to content
Permalink
Browse files

speed up geometry validation in fTools (self-intersection detection; f…

…ixes #2262)

git-svn-id: http://svn.osgeo.org/qgis/trunk@12408 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 11, 2009
1 parent 4a47cd6 commit 48d5954f5441825fac87d46ead2efefa09480a1c
Showing with 64 additions and 23 deletions.
  1. +33 −5 python/plugins/fTools/tools/doVisual.py
  2. +31 −18 python/plugins/fTools/tools/frmVisual.ui
@@ -16,6 +16,8 @@ def __init__( self, iface, function ):
self.manageGui()
self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
self.progressBar.setValue( 0 )
self.partProgressBar.setValue( 0 )
self.partProgressBar.setEnabled( False )

def keyPressEvent( self, e ):
'''
@@ -111,6 +113,8 @@ def visual( self, myLayer, myField, mySelection ):
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 )
QObject.connect( self.testThread, SIGNAL( "runPartRange(PyQt_PyObject)" ), self.runPartRangeFromThread )
QObject.connect( self.testThread, SIGNAL( "runPartStatus(PyQt_PyObject)" ), self.runPartStatusFromThread )
self.cancel_close.setText( "Cancel" )
QObject.connect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
self.testThread.start()
@@ -154,6 +158,16 @@ def runStatusFromThread( self, status ):

def runRangeFromThread( self, range_vals ):
self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )

def runPartStatusFromThread( self, status ):
self.partProgressBar.setValue( status )
if status >= self.part_max:
self.partProgressBar.setEnabled( False )

def runPartRangeFromThread( self, range_vals ):
self.part_max = range_vals[ 1 ]
self.partProgressBar.setEnabled( True )
self.partProgressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )

class visualThread( QThread ):
def __init__( self, parentThread, parentObject, function, vlayer, myField, mySelection ):
@@ -431,6 +445,7 @@ def check_geometry( self, vlayer ):
if not self.isCorrectOrientation( geom ):
lstErrors.append( self.tr( "Feature %1 has incorrect node ordering" ).arg( unicode( feat.id() ) ) )
count += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat )
return ( lstErrors, count )

def isHoleNested( self, polygon ):
@@ -459,16 +474,29 @@ def isPolygonClosed( self, polygon ):
return True

def isSelfIntersecting( self, polygon ):
cPart = 0
for h in polygon:
cPart += len(h)

self.emit( SIGNAL( "runPartRange(PyQt_PyObject)" ), ( 0, cPart ) )

nPart = 0
for h in polygon:
count = 0
size = range( 0, len (h )- 1 )
for i in size:
for i in range( 0, len(h)-1 ):
self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), nPart )

count = 0
for j in size:
for j in range( i+1, len(h)-1 ):
if QgsGeometry().fromPolyline( [ h[ i ], h[ i + 1 ] ] ).intersects( QgsGeometry().fromPolyline( [ h[ j ], h[ j + 1 ] ] ) ):
count += 1
if count > 3:
if count > 2:
self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), cPart )
return True

nPart += 1

self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), cPart )

return False

def isCorrectOrientation( self, polygon ):
@@ -114,7 +114,28 @@
</item>
</layout>
</item>
<item row="7" column="0">
<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="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="9" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
@@ -124,27 +145,19 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDialogButtonBox" name="buttonBox_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="8" column="0">
<widget class="QProgressBar" name="partProgressBar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
<property name="value">
<number>24</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</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>
</layout>
</widget>
<resources/>

0 comments on commit 48d5954

Please sign in to comment.
You can’t perform that action at this time.