Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] fix fTools Clip algorithm (fix #7281)
  • Loading branch information
alexbruy committed Sep 15, 2013
1 parent f7aab64 commit 6910a2e
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions python/plugins/processing/algs/ftools/Clip.py
Expand Up @@ -26,14 +26,15 @@
from PyQt4.QtCore import *
from qgis.core import *
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.tools import dataobjects, vector
from processing.core.ProcessingLog import ProcessingLog
from processing.parameters.ParameterVector import ParameterVector
from processing.outputs.OutputVector import OutputVector
from processing.tools import dataobjects, vector
from processing.tools import vector as utils

class Clip(GeoAlgorithm):


INPUT = "INPUT"
OVERLAY = "OVERLAY"
OUTPUT = "OUTPUT"
Expand Down Expand Up @@ -66,33 +67,44 @@ def processAlgorithm(self, progress):
for inFeatA in selectionA:
geom = QgsGeometry(inFeatA.geometry())
attrs = inFeatA.attributes()
intersections = index.intersects(geom.boundingBox())
intersects = index.intersects(geom.boundingBox())
first = True
found = False
if len(intersections) > 0:
for i in intersections:
request = QgsFeatureRequest().setFilterFid(i)
inFeatB = layerB.getFeatures(request).next()
if len(intersects) > 0:
for i in intersects:
layerB.getFeatures(QgsFeatureRequest().setFilterFid(i)).nextFeature(inFeatB)
tmpGeom = QgsGeometry(inFeatB.geometry())
if tmpGeom.intersects(geom):
found = True
if first:
outFeat.setGeometry(QgsGeometry(tmpGeom))
first = False
else:
cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(cur_geom.combine(tmpGeom))
outFeat.setGeometry(QgsGeometry(new_geom))
if found:
cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == QGis.WKBNoGeometry :
int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))
outFeat.setGeometry(new_geom)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
try:
cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(cur_geom.combine(tmpGeom))
outFeat.setGeometry(QgsGeometry(new_geom))
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "GEOS geoprocessing error: One or more input features have invalid geometry.")
break
if found:
try:
cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0:
int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))
try:
outFeat.setGeometry(new_geom)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Feature geometry error: One or more output features ignored due to invalid geometry.")
continue
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "GEOS geoprocessing error: One or more input features have invalid geometry.")
continue

current += 1
progress.setPercentage(int(current * total))
Expand Down

0 comments on commit 6910a2e

Please sign in to comment.