doVisual.diff

geometry validation speedup - Jürgen Fischer, 2009-12-11 07:24 AM

Download (5.09 KB)

View differences:

frmVisual.ui (working copy)
114 114
     </item>
115 115
    </layout>
116 116
   </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">
118 139
    <widget class="QProgressBar" name="progressBar">
119 140
     <property name="value">
120 141
      <number>24</number>
......
124 145
     </property>
125 146
    </widget>
126 147
   </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>
131 152
     </property>
132
     <property name="standardButtons">
133
      <set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
153
     <property name="value">
154
      <number>24</number>
134 155
     </property>
156
     <property name="alignment">
157
      <set>Qt::AlignCenter</set>
158
     </property>
135 159
    </widget>
136 160
   </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>
148 161
  </layout>
149 162
 </widget>
150 163
 <resources/>
doVisual.py (working copy)
16 16
    self.manageGui()
17 17
    self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
18 18
    self.progressBar.setValue( 0 )
19
    self.partProgressBar.setValue( 0 )
20
    self.partProgressBar.setEnabled( False )
19 21
    
20 22
  def keyPressEvent( self, e ):
21 23
    '''
......
111 113
    QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
112 114
    QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
113 115
    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 )
114 118
    self.cancel_close.setText( "Cancel" )
115 119
    QObject.connect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
116 120
    self.testThread.start()
......
154 158
        
155 159
  def runRangeFromThread( self, range_vals ):
156 160
    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 ] )
157 171
    
158 172
class visualThread( QThread ):
159 173
  def __init__( self, parentThread, parentObject, function, vlayer, myField, mySelection ):
......
431 445
        if not self.isCorrectOrientation( geom ):
432 446
          lstErrors.append( self.tr( "Feature %1 has incorrect node ordering" ).arg( unicode( feat.id() ) ) )
433 447
          count += 1
448
    self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat )
434 449
    return ( lstErrors, count )
435 450

  
436 451
  def isHoleNested( self, polygon ):
......
459 474
    return True
460 475

  
461 476
  def isSelfIntersecting( self, polygon ):
477
    cPart = 0
462 478
    for h in polygon:
463
      count = 0
464
      size = range( 0, len (h )- 1 )
465
      for i in size:
479
      cPart += len(h)
480

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

  
483
    nPart = 0
484
    for h in polygon:
485
      for i in range( 0, len(h)-1 ):
486
        self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), nPart )
487

  
466 488
        count = 0
467
        for j in size:
489
        for j in range( i+1, len(h)-1 ):
468 490
          if QgsGeometry().fromPolyline( [ h[ i ], h[ i + 1 ] ] ).intersects( QgsGeometry().fromPolyline( [ h[ j ], h[ j + 1 ] ] ) ):
469 491
            count += 1
470
        if count > 3:
492
        if count > 2:
493
          self.emit( SIGNAL( "runPartStatus(PyQt_PyObject)" ), cPart )
471 494
          return True
495

  
496
        nPart += 1
497

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

  
472 500
    return False
473 501

  
474 502
  def isCorrectOrientation( self, polygon ):