Skip to content

Commit 48d5954

Browse files
author
jef
committed
speed up geometry validation in fTools (self-intersection detection; fixes #2262)
git-svn-id: http://svn.osgeo.org/qgis/trunk@12408 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4a47cd6 commit 48d5954

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

python/plugins/fTools/tools/doVisual.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def __init__( self, iface, function ):
1616
self.manageGui()
1717
self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
1818
self.progressBar.setValue( 0 )
19+
self.partProgressBar.setValue( 0 )
20+
self.partProgressBar.setEnabled( False )
1921

2022
def keyPressEvent( self, e ):
2123
'''
@@ -111,6 +113,8 @@ def visual( self, myLayer, myField, mySelection ):
111113
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
112114
QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
113115
QObject.connect( self.testThread, SIGNAL( "runRange(PyQt_PyObject)" ), self.runRangeFromThread )
116+
QObject.connect( self.testThread, SIGNAL( "runPartRange(PyQt_PyObject)" ), self.runPartRangeFromThread )
117+
QObject.connect( self.testThread, SIGNAL( "runPartStatus(PyQt_PyObject)" ), self.runPartStatusFromThread )
114118
self.cancel_close.setText( "Cancel" )
115119
QObject.connect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
116120
self.testThread.start()
@@ -154,6 +158,16 @@ def runStatusFromThread( self, status ):
154158

155159
def runRangeFromThread( self, range_vals ):
156160
self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )
161+
162+
def runPartStatusFromThread( self, status ):
163+
self.partProgressBar.setValue( status )
164+
if status >= self.part_max:
165+
self.partProgressBar.setEnabled( False )
166+
167+
def runPartRangeFromThread( self, range_vals ):
168+
self.part_max = range_vals[ 1 ]
169+
self.partProgressBar.setEnabled( True )
170+
self.partProgressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )
157171

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

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

461476
def isSelfIntersecting( self, polygon ):
477+
cPart = 0
478+
for h in polygon:
479+
cPart += len(h)
480+
481+
self.emit( SIGNAL( "runPartRange(PyQt_PyObject)" ), ( 0, cPart ) )
482+
483+
nPart = 0
462484
for h in polygon:
463-
count = 0
464-
size = range( 0, len (h )- 1 )
465-
for i in size:
485+
for i in range( 0, len(h)-1 ):
486+
self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), nPart )
487+
466488
count = 0
467-
for j in size:
489+
for j in range( i+1, len(h)-1 ):
468490
if QgsGeometry().fromPolyline( [ h[ i ], h[ i + 1 ] ] ).intersects( QgsGeometry().fromPolyline( [ h[ j ], h[ j + 1 ] ] ) ):
469491
count += 1
470-
if count > 3:
492+
if count > 2:
493+
self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), cPart )
471494
return True
495+
496+
nPart += 1
497+
498+
self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), cPart )
499+
472500
return False
473501

474502
def isCorrectOrientation( self, polygon ):

python/plugins/fTools/tools/frmVisual.ui

+31-18
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,28 @@
114114
</item>
115115
</layout>
116116
</item>
117-
<item row="7" column="0">
117+
<item row="3" column="0">
118+
<layout class="QVBoxLayout" name="verticalLayout">
119+
<item>
120+
<widget class="QCheckBox" name="useSelected">
121+
<property name="text">
122+
<string>Use only selected features</string>
123+
</property>
124+
</widget>
125+
</item>
126+
</layout>
127+
</item>
128+
<item row="8" column="1" rowspan="2">
129+
<widget class="QDialogButtonBox" name="buttonBox_2">
130+
<property name="orientation">
131+
<enum>Qt::Vertical</enum>
132+
</property>
133+
<property name="standardButtons">
134+
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
135+
</property>
136+
</widget>
137+
</item>
138+
<item row="9" column="0">
118139
<widget class="QProgressBar" name="progressBar">
119140
<property name="value">
120141
<number>24</number>
@@ -124,27 +145,19 @@
124145
</property>
125146
</widget>
126147
</item>
127-
<item row="7" column="1">
128-
<widget class="QDialogButtonBox" name="buttonBox_2">
129-
<property name="orientation">
130-
<enum>Qt::Horizontal</enum>
148+
<item row="8" column="0">
149+
<widget class="QProgressBar" name="partProgressBar">
150+
<property name="enabled">
151+
<bool>false</bool>
131152
</property>
132-
<property name="standardButtons">
133-
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
153+
<property name="value">
154+
<number>24</number>
155+
</property>
156+
<property name="alignment">
157+
<set>Qt::AlignCenter</set>
134158
</property>
135159
</widget>
136160
</item>
137-
<item row="3" column="0">
138-
<layout class="QVBoxLayout" name="verticalLayout">
139-
<item>
140-
<widget class="QCheckBox" name="useSelected">
141-
<property name="text">
142-
<string>Use only selected features</string>
143-
</property>
144-
</widget>
145-
</item>
146-
</layout>
147-
</item>
148161
</layout>
149162
</widget>
150163
<resources/>

0 commit comments

Comments
 (0)