Skip to content

Commit

Permalink
speed up geometry validation in fTools (self-intersection detection; f…
Browse files Browse the repository at this point in the history
…ixes #2262)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12408 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 11, 2009
1 parent e8584b2 commit c64d737
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
38 changes: 33 additions & 5 deletions python/plugins/fTools/tools/doVisual.py
Expand Up @@ -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 ):
'''
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 ):
Expand Down Expand Up @@ -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 ):
Expand Down Expand Up @@ -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 ):
Expand Down
49 changes: 31 additions & 18 deletions python/plugins/fTools/tools/frmVisual.ui
Expand Up @@ -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>
Expand All @@ -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/>
Expand Down

0 comments on commit c64d737

Please sign in to comment.