@@ -93,7 +93,7 @@ def manageGui( self ):
93
93
self .attrib .hide ()
94
94
self .mergeOutput .hide ()
95
95
if self .myFunction == 3 : # Difference
96
- self .label_2 .setText ( self .tr ( "Erase layer" ) )
96
+ self .label_2 .setText ( self .tr ( "Difference layer" ) )
97
97
self .setWindowTitle ( self .tr ( "Difference" ) )
98
98
elif self .myFunction == 5 : # Intersect
99
99
self .label_2 .setText ( self .tr ( "Intersect layer" ) )
@@ -172,7 +172,7 @@ def runFinishedFromThread( self, results ):
172
172
if addToTOC == QMessageBox .Yes :
173
173
ftools_utils .addShapeToCanvas ( unicode ( self .shapefileName ) )
174
174
else :
175
- QMessageBox .warning ( self , "Geoprocessing" , self .tr ( "Error writing output shapefile. " ) )
175
+ QMessageBox .warning ( self , "Geoprocessing" , self .tr ( "GEOS geoprocessing error, please check that all features have a valid geometry " ) )
176
176
QObject .disconnect ( self .cancel_close , SIGNAL ( "clicked()" ), self .cancelThread )
177
177
178
178
def runStatusFromThread ( self , status ):
@@ -226,6 +226,7 @@ def stop(self):
226
226
self .running = False
227
227
228
228
def buffering ( self , useField ):
229
+ GEOS_EXCEPT = True
229
230
vproviderA = self .vlayerA .dataProvider ()
230
231
allAttrs = vproviderA .attributeIndexes ()
231
232
vproviderA .select ( allAttrs )
@@ -252,12 +253,22 @@ def buffering( self, useField ):
252
253
else :
253
254
value = self .myParam
254
255
inGeom = QgsGeometry ( inFeat .geometry () )
255
- outGeom = QgsGeometry ( inGeom .buffer ( float ( value ), 5 ) )
256
+ try :
257
+ outGeom = inGeom .buffer ( float ( value ), 5 )
258
+ except :
259
+ outGeom = QgsGeometry ()
260
+ GEOS_EXCEPT = False
261
+ break
256
262
if first :
257
263
tempGeom = QgsGeometry ( outGeom )
258
264
first = False
259
265
else :
260
- tempGeom = QgsGeometry ( tempGeom .combine ( outGeom ) )
266
+ try :
267
+ tempGeom = tempGeom .combine ( outGeom )
268
+ except :
269
+ tempGeom = QgsGeometry ()
270
+ GEOS_EXCEPT = False
271
+ break
261
272
outFeat .setGeometry ( tempGeom )
262
273
writer .addFeature ( outFeat )
263
274
else :
@@ -271,14 +282,20 @@ def buffering( self, useField ):
271
282
else :
272
283
value = self .myParam
273
284
inGeom = QgsGeometry ( inFeat .geometry () )
274
- outGeom = QgsGeometry ( inGeom .buffer ( float ( value ), 5 ) )
285
+ try :
286
+ outGeom = inGeom .buffer ( float ( value ), 5 )
287
+ except :
288
+ outGeom = QgsGeometry ()
289
+ GEOS_EXCEPT = False
290
+ continue
275
291
outFeat .setGeometry ( outGeom )
276
292
outFeat .setAttributeMap ( atMap )
277
293
writer .addFeature ( outFeat )
278
294
del writer
279
- return True , True
295
+ return GEOS_EXCEPT , True
280
296
281
297
def convex_hull (self , useField ):
298
+ GEOS_EXCEPT = True
282
299
vproviderA = self .vlayerA .dataProvider ()
283
300
allAttrsA = vproviderA .attributeIndexes ()
284
301
fields = vproviderA .fields ()
@@ -314,7 +331,11 @@ def convex_hull(self, useField ):
314
331
hull .extend ( points )
315
332
if len ( hull ) >= 3 :
316
333
tmpGeom = QgsGeometry ( outGeom .fromMultiPoint ( hull ) )
317
- outGeom = QgsGeometry ( tmpGeom .convexHull () )
334
+ try :
335
+ outGeom = tmpGeom .convexHull ()
336
+ except :
337
+ outGeom = QgsGeometry ()
338
+ GEOS_EXCEPT = False
318
339
outFeat .setGeometry ( outGeom )
319
340
(area , perim ) = self .simpleMeasure ( outGeom )
320
341
outFeat .addAttribute ( 0 , QVariant ( outID ) )
@@ -335,13 +356,18 @@ def convex_hull(self, useField ):
335
356
points = ftools_utils .extractPoints ( inGeom )
336
357
hull .extend ( points )
337
358
tmpGeom = QgsGeometry ( outGeom .fromMultiPoint ( hull ) )
338
- outGeom = QgsGeometry ( tmpGeom .convexHull () )
359
+ try :
360
+ outGeom = tmpGeom .convexHull ()
361
+ except :
362
+ outGeom = QgsGeometry ()
363
+ GEOS_EXCEPT = False
339
364
outFeat .setGeometry ( outGeom )
340
365
writer .addFeature ( outFeat )
341
366
del writer
342
- return True , True
367
+ return GEOS_EXCEPT , True
343
368
344
369
def dissolve ( self , useField ):
370
+ GEOS_EXCEPT = True
345
371
vproviderA = self .vlayerA .dataProvider ()
346
372
allAttrsA = vproviderA .attributeIndexes ()
347
373
fields = vproviderA .fields ()
@@ -367,7 +393,11 @@ def dissolve( self, useField ):
367
393
else :
368
394
tmpInGeom = QgsGeometry ( inFeat .geometry () )
369
395
tmpOutGeom = QgsGeometry ( outFeat .geometry () )
370
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
396
+ try :
397
+ tmpOutGeom = tmpOutGeom .combine ( tmpInGeom )
398
+ except :
399
+ tmpOutGeom = QgsGeometry ()
400
+ GEOS_EXCEPT = False
371
401
outFeat .setGeometry ( tmpOutGeom )
372
402
outFeat .setAttributeMap ( attrs )
373
403
writer .addFeature ( outFeat )
@@ -395,14 +425,19 @@ def dissolve( self, useField ):
395
425
else :
396
426
tmpInGeom = QgsGeometry ( inFeat .geometry () )
397
427
tmpOutGeom = QgsGeometry ( outFeat .geometry () )
398
- tmpOutGeom = QgsGeometry ( tmpOutGeom .combine ( tmpInGeom ) )
428
+ try :
429
+ tmpOutGeom = tmpOutGeom .combine ( tmpInGeom )
430
+ except :
431
+ tmpOutGeom = QgsGeometry ()
432
+ GEOS_EXCEPT = False
399
433
outFeat .setGeometry ( tmpOutGeom )
400
434
outFeat .setAttributeMap ( attrs )
401
435
writer .addFeature ( outFeat )
402
436
del writer
403
- return True , True
437
+ return GEOS_EXCEPT , True
404
438
405
439
def difference ( self ):
440
+ GEOS_EXCEPT = True
406
441
vproviderA = self .vlayerA .dataProvider ()
407
442
allAttrsA = vproviderA .attributeIndexes ()
408
443
vproviderA .select ( allAttrsA )
@@ -432,15 +467,21 @@ def difference( self ):
432
467
for id in intersects :
433
468
vproviderB .featureAtId ( int ( id ), inFeatB , True , allAttrsB )
434
469
tmpGeom = QgsGeometry ( inFeatB .geometry () )
435
- if geom .intersects ( tmpGeom ):
436
- geom = geom .difference ( tmpGeom )
470
+ try :
471
+ if geom .intersects ( tmpGeom ):
472
+ geom = geom .difference ( tmpGeom )
473
+ except :
474
+ geom = QgsGeometry ()
475
+ GEOS_EXCEPT = False
476
+ break
437
477
outFeat .setGeometry ( geom )
438
478
outFeat .setAttributeMap ( atMap )
439
479
writer .addFeature ( outFeat )
440
480
del writer
441
- return True , crs_match
481
+ return GEOS_EXCEPT , crs_match
442
482
443
483
def intersect ( self ):
484
+ GEOS_EXCEPT = True
444
485
vproviderA = self .vlayerA .dataProvider ()
445
486
allAttrsA = vproviderA .attributeIndexes ()
446
487
vproviderA .select ( allAttrsA )
@@ -470,16 +511,25 @@ def intersect( self ):
470
511
for id in intersects :
471
512
vproviderB .featureAtId ( int ( id ), inFeatB , True , allAttrsB )
472
513
tmpGeom = QgsGeometry ( inFeatB .geometry () )
473
- if geom .intersects ( tmpGeom ):
474
- atMapB = inFeatB .attributeMap ()
475
- int_geom = geom .intersection ( tmpGeom )
476
- outFeat .setGeometry ( int_geom )
477
- outFeat .setAttributeMap ( ftools_utils .combineVectorAttributes ( atMapA , atMapB ) )
478
- writer .addFeature ( outFeat )
514
+ try :
515
+ if geom .intersects ( tmpGeom ):
516
+ atMapB = inFeatB .attributeMap ()
517
+ int_geom = geom .intersection ( tmpGeom )
518
+ if int_geom .wkbType () == 7 :
519
+ int_com = geom .combine ( tmpGeom )
520
+ int_sym = geom .symDifference ( tmpGeom )
521
+ int_geom = int_com .difference ( int_sym )
522
+ outFeat .setGeometry ( int_geom )
523
+ outFeat .setAttributeMap ( ftools_utils .combineVectorAttributes ( atMapA , atMapB ) )
524
+ writer .addFeature ( outFeat )
525
+ except :
526
+ GEOS_EXCEPT = False
527
+ continue
479
528
del writer
480
529
return True , crs_match
481
530
482
531
def union ( self ):
532
+ GEOS_EXCEPT = True
483
533
vproviderA = self .vlayerA .dataProvider ()
484
534
allAttrsA = vproviderA .attributeIndexes ()
485
535
vproviderA .select ( allAttrsA )
@@ -520,8 +570,18 @@ def union( self ):
520
570
tmpGeom = QgsGeometry ( inFeatB .geometry () )
521
571
if geom .intersects ( tmpGeom ):
522
572
found = True
523
- diff_geom = diff_geom .difference ( tmpGeom )
524
- int_geom = geom .intersection ( tmpGeom )
573
+ try :
574
+ diff_geom = diff_geom .difference ( tmpGeom )
575
+ int_geom = geom .intersection ( tmpGeom )
576
+ if int_geom .wkbType () == 7 :
577
+ int_com = geom .combine ( tmpGeom )
578
+ int_sym = geom .symDifference ( tmpGeom )
579
+ int_geom = int_com .difference ( int_sym )
580
+ except :
581
+ int_geom = QgsGeometry ()
582
+ GEOS_EXCEPT = False
583
+ found = False
584
+ break
525
585
outFeat .setGeometry ( int_geom )
526
586
outFeat .setAttributeMap ( ftools_utils .combineVectorAttributes ( atMapA , atMapB ) )
527
587
writer .addFeature ( outFeat )
@@ -547,15 +607,21 @@ def union( self ):
547
607
vproviderA .featureAtId ( int ( id ), inFeatB , True , allAttrsA )
548
608
atMapB = inFeatB .attributeMap ()
549
609
tmpGeom = QgsGeometry ( inFeatB .geometry () )
550
- if geom .intersects ( tmpGeom ):
551
- geom = geom .difference ( tmpGeom )
610
+ try :
611
+ if geom .intersects ( tmpGeom ):
612
+ geom = geom .difference ( tmpGeom )
613
+ except :
614
+ geom = QgsGeometry ()
615
+ GEOS_EXCEPT = False
616
+ continue
552
617
outFeat .setGeometry ( geom )
553
618
outFeat .setAttributeMap ( atMap )
554
619
writer .addFeature ( outFeat )
555
620
del writer
556
621
return True , crs_match
557
622
558
623
def symetrical_difference ( self ):
624
+ GEOS_EXCEPT = True
559
625
vproviderA = self .vlayerA .dataProvider ()
560
626
allAttrsA = vproviderA .attributeIndexes ()
561
627
vproviderA .select ( allAttrsA )
@@ -586,8 +652,13 @@ def symetrical_difference( self ):
586
652
for id in intersects :
587
653
vproviderB .featureAtId ( int ( id ), inFeatB , True , allAttrsB )
588
654
tmpGeom = QgsGeometry ( inFeatB .geometry () )
589
- if geom .intersects ( tmpGeom ):
590
- geom = geom .difference ( tmpGeom )
655
+ try :
656
+ if geom .intersects ( tmpGeom ):
657
+ geom = geom .difference ( tmpGeom )
658
+ except :
659
+ geom = QgsGeometry ()
660
+ GEOS_EXCEPT = False
661
+ continue
591
662
outFeat .setGeometry ( geom )
592
663
outFeat .setAttributeMap ( atMapA )
593
664
writer .addFeature ( outFeat )
@@ -603,15 +674,21 @@ def symetrical_difference( self ):
603
674
for id in intersects :
604
675
vproviderA .featureAtId ( int ( id ), inFeatB , True , allAttrsA )
605
676
tmpGeom = QgsGeometry ( inFeatB .geometry () )
606
- if geom .intersects ( tmpGeom ):
607
- geom = geom .difference ( tmpGeom )
677
+ try :
678
+ if geom .intersects ( tmpGeom ):
679
+ geom = geom .difference ( tmpGeom )
680
+ except :
681
+ geom = QgsGeometry ()
682
+ GEOS_EXCEPT = False
683
+ continue
608
684
outFeat .setGeometry ( geom )
609
685
outFeat .setAttributeMap ( atMap )
610
686
writer .addFeature ( outFeat )
611
687
del writer
612
- return True , crs_match
688
+ return GEOS_EXCEPT , crs_match
613
689
614
690
def clip ( self ):
691
+ GEOS_EXCEPT = True
615
692
vproviderA = self .vlayerA .dataProvider ()
616
693
allAttrsA = vproviderA .attributeIndexes ()
617
694
vproviderA .select ( allAttrsA )
@@ -641,13 +718,21 @@ def clip( self ):
641
718
for id in intersects :
642
719
vproviderB .featureAtId ( int ( id ), inFeatB , True , allAttrsB )
643
720
tmpGeom = QgsGeometry ( inFeatB .geometry () )
644
- if geom .intersects ( tmpGeom ):
645
- geom = geom .intersection ( tmpGeom )
646
- outFeat .setGeometry ( geom )
647
- outFeat .setAttributeMap ( atMap )
648
- writer .addFeature ( outFeat )
721
+ try :
722
+ if geom .intersects ( tmpGeom ):
723
+ int_geom = geom .intersection ( tmpGeom )
724
+ if int_geom .wkbType () == 7 :
725
+ int_com = geom .combine ( tmpGeom )
726
+ int_sym = geom .symDifference ( tmpGeom )
727
+ int_geom = int_com .difference ( int_sym )
728
+ outFeat .setGeometry ( int_geom )
729
+ outFeat .setAttributeMap ( atMap )
730
+ writer .addFeature ( outFeat )
731
+ except :
732
+ GEOS_EXCEPT = False
733
+ continue
649
734
del writer
650
- return True , crs_match
735
+ return GEOS_EXCEPT , crs_match
651
736
652
737
def checkParameter ( self , layer , param ):
653
738
if self .myFunction == 1 :
0 commit comments