@@ -45,7 +45,7 @@ def accept(self):
4545 else :
4646 self .outShape .clear ()
4747 self .geometry ( self .inShape .currentText (), self .lineEdit .value (), self .cmbField .currentText () )
48-
48+
4949 def outFile (self ):
5050 self .outShape .clear ()
5151 (self .shapefileName , self .encoding ) = ftools_utils .saveDialog (self )
@@ -90,11 +90,6 @@ def manageGui(self):
9090 self .lineEdit .setVisible (False )
9191 self .cmbField .setVisible (False )
9292 self .field_label .setVisible (False )
93- elif self .myFunction == 6 : # Simplify geometries
94- self .setWindowTitle ( self .tr ( "Simplify geometries" ) )
95- self .label_2 .setText ( self .tr ( "Output shapefile" ) )
96- self .cmbField .setVisible (False )
97- self .field_label .setVisible (False )
9893 elif self .myFunction == 7 : # Polygon centroids
9994 self .setWindowTitle ( self .tr ( "Polygon centroids" ) )
10095 self .label_2 .setText ( self .tr ( "Output point shapefile" ) )
@@ -119,7 +114,7 @@ def manageGui(self):
119114 myList = []
120115 self .inShape .clear ()
121116 if self .myFunction == 3 or self .myFunction == 6 :
122- myList = ftools_utils .getLayerNames ( [ QGis .Polygon , QGis .Line ] )
117+ myList = ftools_utils .getLayerNames ( [ QGis .Polygon , QGis .Line ] )
123118 elif self .myFunction == 4 or self .myFunction == 7 :
124119 myList = ftools_utils .getLayerNames ( [ QGis .Polygon ] )
125120 elif self .myFunction == 8 :
@@ -136,7 +131,7 @@ def manageGui(self):
136131#3: Extract nodes
137132#4: Polygons to lines
138133#5: Export/Add geometry columns
139- #6: Simplify geometries
134+ #6: Simplify geometries (disabled)
140135#7: Polygon centroids
141136#8: Delaunay triangulation
142137#9: Polygon from layer extent
@@ -153,7 +148,7 @@ def geometry( self, myLayer, myParam, myField ):
153148 QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Unable to delete existing shapefile." ) )
154149 return
155150 self .buttonOk .setEnabled ( False )
156- self .testThread = geometryThread ( self .iface .mainWindow (), self , self .myFunction , vlayer , myParam ,
151+ self .testThread = geometryThread ( self .iface .mainWindow (), self , self .myFunction , vlayer , myParam ,
157152 myField , self .shapefileName , self .encoding )
158153 QObject .connect ( self .testThread , SIGNAL ( "runFinished(PyQt_PyObject)" ), self .runFinishedFromThread )
159154 QObject .connect ( self .testThread , SIGNAL ( "runStatus(PyQt_PyObject)" ), self .runStatusFromThread )
@@ -165,7 +160,7 @@ def geometry( self, myLayer, myParam, myField ):
165160 def cancelThread ( self ):
166161 self .testThread .stop ()
167162 self .buttonOk .setEnabled ( True )
168-
163+
169164 def runFinishedFromThread ( self , success ):
170165 self .testThread .stop ()
171166 self .buttonOk .setEnabled ( True )
@@ -177,7 +172,7 @@ def runFinishedFromThread( self, success ):
177172 QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ("At least two features must have same attribute value!\n Please choose another field..." ) )
178173 if not QgsVectorFileWriter .deleteShapeFile ( self .shapefileName ):
179174 QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ( "Unable to delete incomplete shapefile." ) )
180- else :
175+ else :
181176 self .cancel_close .setText ( "Close" )
182177 QObject .disconnect ( self .cancel_close , SIGNAL ( "clicked()" ), self .cancelThread )
183178 if success :
@@ -187,13 +182,13 @@ def runFinishedFromThread( self, success ):
187182 QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Error loading output shapefile:\n %1" ).arg ( unicode ( self .shapefileName ) ))
188183 else :
189184 QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ( "Error writing output shapefile." ) )
190-
185+
191186 def runStatusFromThread ( self , status ):
192187 self .progressBar .setValue ( status )
193-
188+
194189 def runRangeFromThread ( self , range_vals ):
195190 self .progressBar .setRange ( range_vals [ 0 ], range_vals [ 1 ] )
196-
191+
197192class geometryThread ( QThread ):
198193 def __init__ ( self , parentThread , parentObject , function , vlayer , myParam , myField , myName , myEncoding ):
199194 QThread .__init__ ( self , parentThread )
@@ -218,8 +213,7 @@ def run( self ):
218213 success = self .polygons_to_lines ()
219214 elif self .myFunction == 5 : # Export/Add geometry columns
220215 success = self .export_geometry_info ()
221- elif self .myFunction == 6 : # Simplify geometries
222- success = self .simplify_geometry ()
216+ # note that 6 used to be associated with simplify_geometry
223217 elif self .myFunction == 7 : # Polygon centroids
224218 success = self .polygon_centroids ()
225219 elif self .myFunction == 8 : # Delaunay triangulation
@@ -231,7 +225,7 @@ def run( self ):
231225
232226 def stop (self ):
233227 self .running = False
234-
228+
235229 def single_to_multi ( self ):
236230 vprovider = self .vlayer .dataProvider ()
237231 allAttrs = vprovider .attributeIndexes ()
@@ -291,7 +285,7 @@ def multi_to_single( self ):
291285 allAttrs = vprovider .attributeIndexes ()
292286 vprovider .select ( allAttrs )
293287 fields = vprovider .fields ()
294- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
288+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
295289 fields , vprovider .geometryType (), vprovider .crs () )
296290 inFeat = QgsFeature ()
297291 outFeat = QgsFeature ()
@@ -302,7 +296,7 @@ def multi_to_single( self ):
302296 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
303297 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
304298 while vprovider .nextFeature ( inFeat ):
305- nElement += 1
299+ nElement += 1
306300 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
307301 inGeom = inFeat .geometry ()
308302 atMap = inFeat .attributeMap ()
@@ -319,7 +313,7 @@ def extract_nodes( self ):
319313 allAttrs = vprovider .attributeIndexes ()
320314 vprovider .select ( allAttrs )
321315 fields = vprovider .fields ()
322- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
316+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
323317 fields , QGis .WKBPoint , vprovider .crs () )
324318 inFeat = QgsFeature ()
325319 outFeat = QgsFeature ()
@@ -330,7 +324,7 @@ def extract_nodes( self ):
330324 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
331325 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
332326 while vprovider .nextFeature ( inFeat ):
333- nElement += 1
327+ nElement += 1
334328 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
335329 inGeom = inFeat .geometry ()
336330 atMap = inFeat .attributeMap ()
@@ -347,7 +341,7 @@ def polygons_to_lines( self ):
347341 allAttrs = vprovider .attributeIndexes ()
348342 vprovider .select ( allAttrs )
349343 fields = vprovider .fields ()
350- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
344+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
351345 fields , QGis .WKBLineString , vprovider .crs () )
352346 inFeat = QgsFeature ()
353347 outFeat = QgsFeature ()
@@ -359,7 +353,7 @@ def polygons_to_lines( self ):
359353 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
360354 while vprovider .nextFeature (inFeat ):
361355 multi = False
362- nElement += 1
356+ nElement += 1
363357 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
364358 inGeom = inFeat .geometry ()
365359 if inGeom .isMultipart ():
@@ -378,7 +372,7 @@ def export_geometry_info( self ):
378372 allAttrs = vprovider .attributeIndexes ()
379373 vprovider .select ( allAttrs )
380374 ( fields , index1 , index2 ) = self .checkGeometryFields ( self .vlayer )
381- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
375+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
382376 fields , vprovider .geometryType (), vprovider .crs () )
383377 inFeat = QgsFeature ()
384378 outFeat = QgsFeature ()
@@ -389,7 +383,7 @@ def export_geometry_info( self ):
389383 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
390384 while vprovider .nextFeature (inFeat ):
391385 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
392- nElement += 1
386+ nElement += 1
393387 inGeom = inFeat .geometry ()
394388 ( attr1 , attr2 ) = self .simpleMeasure ( inGeom )
395389 outFeat .setGeometry ( inGeom )
@@ -401,41 +395,12 @@ def export_geometry_info( self ):
401395 del writer
402396 return True
403397
404- def simplify_geometry ( self ):
405- vprovider = self .vlayer .dataProvider ()
406- tolerance = self .myParam
407- allAttrs = vprovider .attributeIndexes ()
408- vprovider .select ( allAttrs )
409- fields = vprovider .fields ()
410- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
411- fields , vprovider .geometryType (), vprovider .crs () )
412- inFeat = QgsFeature ()
413- outFeat = QgsFeature ()
414- nFeat = vprovider .featureCount ()
415- nElement = 0
416- self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
417- self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
418- self .measure = QgsDistanceArea ()
419- while vprovider .nextFeature ( inFeat ):
420- nElement += 1
421- self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
422- inGeom = inFeat .geometry ()
423- atMap = inFeat .attributeMap ()
424- outGeom = QgsGeometry (inGeom .simplify (tolerance ))
425- if outGeom is None :
426- return "math_error"
427- outFeat .setAttributeMap ( atMap )
428- outFeat .setGeometry ( outGeom )
429- writer .addFeature ( outFeat )
430- del writer
431- return True
432-
433398 def polygon_centroids ( self ):
434399 vprovider = self .vlayer .dataProvider ()
435400 allAttrs = vprovider .attributeIndexes ()
436401 vprovider .select ( allAttrs )
437402 fields = vprovider .fields ()
438- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
403+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
439404 fields , QGis .WKBPoint , vprovider .crs () )
440405 inFeat = QgsFeature ()
441406 outFeat = QgsFeature ()
@@ -456,7 +421,7 @@ def polygon_centroids( self ):
456421 writer .addFeature ( outFeat )
457422 del writer
458423 return True
459-
424+
460425 def delaunay_triangulation ( self ):
461426 import voronoi
462427 vprovider = self .vlayer .dataProvider ()
@@ -495,13 +460,13 @@ def delaunay_triangulation( self ):
495460 if step <= 3 : feat .addAttribute ( step , QVariant ( index ) )
496461 step += 1
497462 geometry = QgsGeometry ().fromPolygon ( [ polygon ] )
498- feat .setGeometry ( geometry )
463+ feat .setGeometry ( geometry )
499464 writer .addFeature ( feat )
500465 nElement += 1
501466 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
502467 del writer
503468 return True
504-
469+
505470 def layer_extent ( self ):
506471 self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
507472 self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , 0 ) )
@@ -517,7 +482,7 @@ def layer_extent( self ):
517482 8 : QgsField ( "HEIGHT" , QVariant .Double ),
518483 9 : QgsField ( "WIDTH" , QVariant .Double ) }
519484
520- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
485+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
521486 fields , QGis .WKBPolygon , self .vlayer .srs () )
522487 rect = self .vlayer .extent ()
523488 minx = rect .xMinimum ()
@@ -587,7 +552,7 @@ def perimMeasure( self, inGeom, measure ):
587552
588553 def checkForField ( self , L , e ):
589554 e = QString ( e ).toLower ()
590- fieldRange = range ( 0 ,len ( L ) )
555+ fieldRange = range ( 0 ,len ( L ) )
591556 for item in fieldRange :
592557 if L [ item ].toLower () == e :
593558 return True , item
@@ -602,17 +567,17 @@ def checkGeometryFields( self, vlayer ):
602567 nameList .append ( fieldList [ i ].name ().toLower () )
603568 if geomType == QGis .Polygon :
604569 plp = "Poly"
605- ( found , index1 ) = self .checkForField ( nameList , "AREA" )
570+ ( found , index1 ) = self .checkForField ( nameList , "AREA" )
606571 if not found :
607572 field = QgsField ( "AREA" , QVariant .Double , "double" , 10 , 6 , self .tr ("Polygon area" ) )
608573 index1 = len ( fieldList .keys () )
609- fieldList [ index1 ] = field
574+ fieldList [ index1 ] = field
610575 ( found , index2 ) = self .checkForField ( nameList , "PERIMETER" )
611-
576+
612577 if not found :
613578 field = QgsField ( "PERIMETER" , QVariant .Double , "double" , 10 , 6 , self .tr ("Polygon perimeter" ) )
614579 index2 = len ( fieldList .keys () )
615- fieldList [ index2 ] = field
580+ fieldList [ index2 ] = field
616581 elif geomType == QGis .Line :
617582 plp = "Line"
618583 (found , index1 ) = self .checkForField (nameList , "LENGTH" )
@@ -675,7 +640,7 @@ def extractAsSingle( self, geom ):
675640 else :
676641 temp_geom .append ( geom )
677642 return temp_geom
678-
643+
679644 def extractAsMulti ( self , geom ):
680645 temp_geom = []
681646 if geom .type () == 0 :
0 commit comments