@@ -45,7 +45,7 @@ def accept(self):
45
45
else :
46
46
self .outShape .clear ()
47
47
self .geometry ( self .inShape .currentText (), self .lineEdit .value (), self .cmbField .currentText () )
48
-
48
+
49
49
def outFile (self ):
50
50
self .outShape .clear ()
51
51
(self .shapefileName , self .encoding ) = ftools_utils .saveDialog (self )
@@ -90,11 +90,6 @@ def manageGui(self):
90
90
self .lineEdit .setVisible (False )
91
91
self .cmbField .setVisible (False )
92
92
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 )
98
93
elif self .myFunction == 7 : # Polygon centroids
99
94
self .setWindowTitle ( self .tr ( "Polygon centroids" ) )
100
95
self .label_2 .setText ( self .tr ( "Output point shapefile" ) )
@@ -119,7 +114,7 @@ def manageGui(self):
119
114
myList = []
120
115
self .inShape .clear ()
121
116
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 ] )
123
118
elif self .myFunction == 4 or self .myFunction == 7 :
124
119
myList = ftools_utils .getLayerNames ( [ QGis .Polygon ] )
125
120
elif self .myFunction == 8 :
@@ -136,7 +131,7 @@ def manageGui(self):
136
131
#3: Extract nodes
137
132
#4: Polygons to lines
138
133
#5: Export/Add geometry columns
139
- #6: Simplify geometries
134
+ #6: Simplify geometries (disabled)
140
135
#7: Polygon centroids
141
136
#8: Delaunay triangulation
142
137
#9: Polygon from layer extent
@@ -153,7 +148,7 @@ def geometry( self, myLayer, myParam, myField ):
153
148
QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Unable to delete existing shapefile." ) )
154
149
return
155
150
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 ,
157
152
myField , self .shapefileName , self .encoding )
158
153
QObject .connect ( self .testThread , SIGNAL ( "runFinished(PyQt_PyObject)" ), self .runFinishedFromThread )
159
154
QObject .connect ( self .testThread , SIGNAL ( "runStatus(PyQt_PyObject)" ), self .runStatusFromThread )
@@ -165,7 +160,7 @@ def geometry( self, myLayer, myParam, myField ):
165
160
def cancelThread ( self ):
166
161
self .testThread .stop ()
167
162
self .buttonOk .setEnabled ( True )
168
-
163
+
169
164
def runFinishedFromThread ( self , success ):
170
165
self .testThread .stop ()
171
166
self .buttonOk .setEnabled ( True )
@@ -177,7 +172,7 @@ def runFinishedFromThread( self, success ):
177
172
QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ("At least two features must have same attribute value!\n Please choose another field..." ) )
178
173
if not QgsVectorFileWriter .deleteShapeFile ( self .shapefileName ):
179
174
QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ( "Unable to delete incomplete shapefile." ) )
180
- else :
175
+ else :
181
176
self .cancel_close .setText ( "Close" )
182
177
QObject .disconnect ( self .cancel_close , SIGNAL ( "clicked()" ), self .cancelThread )
183
178
if success :
@@ -187,13 +182,13 @@ def runFinishedFromThread( self, success ):
187
182
QMessageBox .warning ( self , self .tr ("Geoprocessing" ), self .tr ( "Error loading output shapefile:\n %1" ).arg ( unicode ( self .shapefileName ) ))
188
183
else :
189
184
QMessageBox .warning ( self , self .tr ("Geometry" ), self .tr ( "Error writing output shapefile." ) )
190
-
185
+
191
186
def runStatusFromThread ( self , status ):
192
187
self .progressBar .setValue ( status )
193
-
188
+
194
189
def runRangeFromThread ( self , range_vals ):
195
190
self .progressBar .setRange ( range_vals [ 0 ], range_vals [ 1 ] )
196
-
191
+
197
192
class geometryThread ( QThread ):
198
193
def __init__ ( self , parentThread , parentObject , function , vlayer , myParam , myField , myName , myEncoding ):
199
194
QThread .__init__ ( self , parentThread )
@@ -218,8 +213,7 @@ def run( self ):
218
213
success = self .polygons_to_lines ()
219
214
elif self .myFunction == 5 : # Export/Add geometry columns
220
215
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
223
217
elif self .myFunction == 7 : # Polygon centroids
224
218
success = self .polygon_centroids ()
225
219
elif self .myFunction == 8 : # Delaunay triangulation
@@ -231,7 +225,7 @@ def run( self ):
231
225
232
226
def stop (self ):
233
227
self .running = False
234
-
228
+
235
229
def single_to_multi ( self ):
236
230
vprovider = self .vlayer .dataProvider ()
237
231
allAttrs = vprovider .attributeIndexes ()
@@ -291,7 +285,7 @@ def multi_to_single( self ):
291
285
allAttrs = vprovider .attributeIndexes ()
292
286
vprovider .select ( allAttrs )
293
287
fields = vprovider .fields ()
294
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
288
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
295
289
fields , vprovider .geometryType (), vprovider .crs () )
296
290
inFeat = QgsFeature ()
297
291
outFeat = QgsFeature ()
@@ -302,7 +296,7 @@ def multi_to_single( self ):
302
296
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
303
297
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
304
298
while vprovider .nextFeature ( inFeat ):
305
- nElement += 1
299
+ nElement += 1
306
300
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
307
301
inGeom = inFeat .geometry ()
308
302
atMap = inFeat .attributeMap ()
@@ -319,7 +313,7 @@ def extract_nodes( self ):
319
313
allAttrs = vprovider .attributeIndexes ()
320
314
vprovider .select ( allAttrs )
321
315
fields = vprovider .fields ()
322
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
316
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
323
317
fields , QGis .WKBPoint , vprovider .crs () )
324
318
inFeat = QgsFeature ()
325
319
outFeat = QgsFeature ()
@@ -330,7 +324,7 @@ def extract_nodes( self ):
330
324
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
331
325
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
332
326
while vprovider .nextFeature ( inFeat ):
333
- nElement += 1
327
+ nElement += 1
334
328
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
335
329
inGeom = inFeat .geometry ()
336
330
atMap = inFeat .attributeMap ()
@@ -347,7 +341,7 @@ def polygons_to_lines( self ):
347
341
allAttrs = vprovider .attributeIndexes ()
348
342
vprovider .select ( allAttrs )
349
343
fields = vprovider .fields ()
350
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
344
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
351
345
fields , QGis .WKBLineString , vprovider .crs () )
352
346
inFeat = QgsFeature ()
353
347
outFeat = QgsFeature ()
@@ -359,7 +353,7 @@ def polygons_to_lines( self ):
359
353
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
360
354
while vprovider .nextFeature (inFeat ):
361
355
multi = False
362
- nElement += 1
356
+ nElement += 1
363
357
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
364
358
inGeom = inFeat .geometry ()
365
359
if inGeom .isMultipart ():
@@ -378,7 +372,7 @@ def export_geometry_info( self ):
378
372
allAttrs = vprovider .attributeIndexes ()
379
373
vprovider .select ( allAttrs )
380
374
( fields , index1 , index2 ) = self .checkGeometryFields ( self .vlayer )
381
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
375
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
382
376
fields , vprovider .geometryType (), vprovider .crs () )
383
377
inFeat = QgsFeature ()
384
378
outFeat = QgsFeature ()
@@ -389,7 +383,7 @@ def export_geometry_info( self ):
389
383
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , nFeat ) )
390
384
while vprovider .nextFeature (inFeat ):
391
385
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
392
- nElement += 1
386
+ nElement += 1
393
387
inGeom = inFeat .geometry ()
394
388
( attr1 , attr2 ) = self .simpleMeasure ( inGeom )
395
389
outFeat .setGeometry ( inGeom )
@@ -401,41 +395,12 @@ def export_geometry_info( self ):
401
395
del writer
402
396
return True
403
397
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
-
433
398
def polygon_centroids ( self ):
434
399
vprovider = self .vlayer .dataProvider ()
435
400
allAttrs = vprovider .attributeIndexes ()
436
401
vprovider .select ( allAttrs )
437
402
fields = vprovider .fields ()
438
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
403
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
439
404
fields , QGis .WKBPoint , vprovider .crs () )
440
405
inFeat = QgsFeature ()
441
406
outFeat = QgsFeature ()
@@ -456,7 +421,7 @@ def polygon_centroids( self ):
456
421
writer .addFeature ( outFeat )
457
422
del writer
458
423
return True
459
-
424
+
460
425
def delaunay_triangulation ( self ):
461
426
import voronoi
462
427
vprovider = self .vlayer .dataProvider ()
@@ -495,13 +460,13 @@ def delaunay_triangulation( self ):
495
460
if step <= 3 : feat .addAttribute ( step , QVariant ( index ) )
496
461
step += 1
497
462
geometry = QgsGeometry ().fromPolygon ( [ polygon ] )
498
- feat .setGeometry ( geometry )
463
+ feat .setGeometry ( geometry )
499
464
writer .addFeature ( feat )
500
465
nElement += 1
501
466
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), nElement )
502
467
del writer
503
468
return True
504
-
469
+
505
470
def layer_extent ( self ):
506
471
self .emit ( SIGNAL ( "runStatus(PyQt_PyObject)" ), 0 )
507
472
self .emit ( SIGNAL ( "runRange(PyQt_PyObject)" ), ( 0 , 0 ) )
@@ -517,7 +482,7 @@ def layer_extent( self ):
517
482
8 : QgsField ( "HEIGHT" , QVariant .Double ),
518
483
9 : QgsField ( "WIDTH" , QVariant .Double ) }
519
484
520
- writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
485
+ writer = QgsVectorFileWriter ( self .myName , self .myEncoding ,
521
486
fields , QGis .WKBPolygon , self .vlayer .srs () )
522
487
rect = self .vlayer .extent ()
523
488
minx = rect .xMinimum ()
@@ -587,7 +552,7 @@ def perimMeasure( self, inGeom, measure ):
587
552
588
553
def checkForField ( self , L , e ):
589
554
e = QString ( e ).toLower ()
590
- fieldRange = range ( 0 ,len ( L ) )
555
+ fieldRange = range ( 0 ,len ( L ) )
591
556
for item in fieldRange :
592
557
if L [ item ].toLower () == e :
593
558
return True , item
@@ -602,17 +567,17 @@ def checkGeometryFields( self, vlayer ):
602
567
nameList .append ( fieldList [ i ].name ().toLower () )
603
568
if geomType == QGis .Polygon :
604
569
plp = "Poly"
605
- ( found , index1 ) = self .checkForField ( nameList , "AREA" )
570
+ ( found , index1 ) = self .checkForField ( nameList , "AREA" )
606
571
if not found :
607
572
field = QgsField ( "AREA" , QVariant .Double , "double" , 10 , 6 , self .tr ("Polygon area" ) )
608
573
index1 = len ( fieldList .keys () )
609
- fieldList [ index1 ] = field
574
+ fieldList [ index1 ] = field
610
575
( found , index2 ) = self .checkForField ( nameList , "PERIMETER" )
611
-
576
+
612
577
if not found :
613
578
field = QgsField ( "PERIMETER" , QVariant .Double , "double" , 10 , 6 , self .tr ("Polygon perimeter" ) )
614
579
index2 = len ( fieldList .keys () )
615
- fieldList [ index2 ] = field
580
+ fieldList [ index2 ] = field
616
581
elif geomType == QGis .Line :
617
582
plp = "Line"
618
583
(found , index1 ) = self .checkForField (nameList , "LENGTH" )
@@ -675,7 +640,7 @@ def extractAsSingle( self, geom ):
675
640
else :
676
641
temp_geom .append ( geom )
677
642
return temp_geom
678
-
643
+
679
644
def extractAsMulti ( self , geom ):
680
645
temp_geom = []
681
646
if geom .type () == 0 :
0 commit comments