Skip to content

Commit a2b82bf

Browse files
authoredJul 13, 2017
Merge pull request #4851 from alexbruy/processing-exception
[processing] use QgsProcessingException instead of old exception class
2 parents 50df255 + 5620854 commit a2b82bf

25 files changed

+72
-122
lines changed
 

‎python/plugins/processing/algs/qgis/Boundary.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from qgis.PyQt.QtGui import QIcon
3838

3939
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
40-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4140

4241
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
4342

‎python/plugins/processing/algs/qgis/BoundingBox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
QgsWkbTypes,
3232
QgsFeatureSink,
3333
QgsProcessing,
34+
QgsProcessingException,
3435
QgsProcessingParameterFeatureSource,
3536
QgsProcessingParameterFeatureSink)
3637

3738

3839
from qgis.PyQt.QtGui import QIcon
3940

4041
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
41-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4242

4343
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
4444

@@ -84,7 +84,7 @@ def processAlgorithm(self, parameters, context, feedback):
8484
if input_geometry:
8585
output_geometry = QgsGeometry.fromRect(input_geometry.boundingBox())
8686
if not output_geometry:
87-
raise GeoAlgorithmExecutionException(
87+
raise QgsProcessingException(
8888
self.tr('Error calculating bounding box'))
8989

9090
output_feature.setGeometry(output_geometry)

‎python/plugins/processing/algs/qgis/ConcaveHull.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626

2727
__revision__ = '$Format:%H$'
2828

29+
from math import sqrt
30+
2931
from qgis.core import (QgsFeature,
3032
QgsFeatureSink,
3133
QgsWkbTypes,
3234
QgsProcessing,
35+
QgsProcessingException,
3336
QgsProcessingParameterFeatureSource,
3437
QgsProcessingParameterNumber,
3538
QgsProcessingParameterBoolean,
3639
QgsProcessingParameterFeatureSink)
37-
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
38-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3940
import processing
40-
from math import sqrt
41+
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
4142

4243

4344
class ConcaveHull(QgisAlgorithm):
@@ -89,7 +90,7 @@ def processAlgorithm(self, parameters, context, feedback):
8990
features = delaunay_layer.getFeatures()
9091
count = delaunay_layer.featureCount()
9192
if count == 0:
92-
raise GeoAlgorithmExecutionException(self.tr('No Delaunay triangles created.'))
93+
raise QgsProcessingException(self.tr('No Delaunay triangles created.'))
9394

9495
counter = 50. / count
9596
lengths = []

‎python/plugins/processing/algs/qgis/Delaunay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
QgsWkbTypes,
4141
QgsProcessing,
4242
QgsFields,
43+
QgsProcessingException,
4344
QgsProcessingParameterFeatureSource,
4445
QgsProcessingParameterFeatureSink)
4546

4647
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
47-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4848

4949
from . import voronoi
5050

@@ -112,7 +112,7 @@ def processAlgorithm(self, parameters, context, feedback):
112112
feedback.setProgress(int(current * total))
113113

114114
if len(pts) < 3:
115-
raise GeoAlgorithmExecutionException(
115+
raise QgsProcessingException(
116116
self.tr('Input file should contain at least 3 points. Choose '
117117
'another file and try again.'))
118118

‎python/plugins/processing/algs/qgis/GridPolygon.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
QgsPointXY,
3838
QgsWkbTypes,
3939
QgsProcessing,
40+
QgsProcessingException,
4041
QgsProcessingParameterEnum,
4142
QgsProcessingParameterExtent,
4243
QgsProcessingParameterNumber,
@@ -45,7 +46,6 @@
4546
QgsFields)
4647

4748
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
48-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4949

5050
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
5151

@@ -122,19 +122,19 @@ def processAlgorithm(self, parameters, context, feedback):
122122
originY = bbox.yMaximum()
123123

124124
if hSpacing <= 0 or vSpacing <= 0:
125-
raise GeoAlgorithmExecutionException(
125+
raise QgsProcessingException(
126126
self.tr('Invalid grid spacing: {0}/{1}').format(hSpacing, vSpacing))
127127

128128
if width < hSpacing:
129-
raise GeoAlgorithmExecutionException(
129+
raise QgsProcessingException(
130130
self.tr('Horizontal spacing is too small for the covered area'))
131131

132132
if hSpacing <= hOverlay or vSpacing <= vOverlay:
133-
raise GeoAlgorithmExecutionException(
133+
raise QgsProcessingException(
134134
self.tr('Invalid overlay: {0}/{1}').format(hOverlay, vOverlay))
135135

136136
if height < vSpacing:
137-
raise GeoAlgorithmExecutionException(
137+
raise QgsProcessingException(
138138
self.tr('Vertical spacing is too small for the covered area'))
139139

140140
fields = QgsFields()
@@ -264,7 +264,7 @@ def _hexagonGrid(self, sink, width, height, originX, originY,
264264

265265
hOverlay = hSpacing - hOverlay
266266
if hOverlay < 0:
267-
raise GeoAlgorithmExecutionException(
267+
raise QgsProcessingException(
268268
self.tr('To preserve symmetry, hspacing is fixed relative to vspacing\n \
269269
hspacing is fixed at: {0} and hoverlay is fixed at: {1}\n \
270270
hoverlay cannot be negative. Increase hoverlay.').format(hSpacing, hOverlay)

‎python/plugins/processing/algs/qgis/ImportIntoPostGIS.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
from qgis.core import (QgsVectorLayerExporter,
2929
QgsSettings,
3030
QgsFeatureSink,
31+
QgsProcessingException,
3132
QgsProcessingParameterFeatureSource,
3233
QgsProcessingParameterString,
3334
QgsProcessingParameterField,
3435
QgsProcessingParameterBoolean,
3536
QgsWkbTypes)
3637

3738
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
38-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3939
from processing.tools import postgis
4040

4141

@@ -167,7 +167,7 @@ def processAlgorithm(self, parameters, context, feedback):
167167
source.wkbType(), source.sourceCrs(), overwrite, options)
168168

169169
if exporter.errorCode() != QgsVectorLayerExporter.NoError:
170-
raise GeoAlgorithmExecutionException(
170+
raise QgsProcessingException(
171171
self.tr('Error importing to PostGIS\n{0}').format(exporter.errorMessage()))
172172

173173
features = source.getFeatures()
@@ -183,7 +183,7 @@ def processAlgorithm(self, parameters, context, feedback):
183183

184184
exporter.flushBuffer()
185185
if exporter.errorCode() != QgsVectorLayerExporter.NoError:
186-
raise GeoAlgorithmExecutionException(
186+
raise QgsProcessingException(
187187
self.tr('Error importing to PostGIS\n{0}').format(exporter.errorMessage()))
188188

189189
if geomColumn and createIndex:

‎python/plugins/processing/algs/qgis/ImportIntoSpatialite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from qgis.core import (QgsDataSourceUri,
2929
QgsFeatureSink,
3030
QgsVectorLayerExporter,
31+
QgsProcessingException,
3132
QgsProcessingParameterFeatureSource,
3233
QgsProcessingParameterVectorLayer,
3334
QgsProcessingParameterField,
@@ -36,7 +37,6 @@
3637
QgsWkbTypes)
3738

3839
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
39-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4040
from processing.tools import spatialite
4141

4242

@@ -137,7 +137,7 @@ def processAlgorithm(self, parameters, context, feedback):
137137
source.wkbType(), source.sourceCrs(), overwrite, options)
138138

139139
if exporter.errorCode() != QgsVectorLayerExporter.NoError:
140-
raise GeoAlgorithmExecutionException(
140+
raise QgsProcessingException(
141141
self.tr('Error importing to Spatialite\n{0}').format(exporter.errorMessage()))
142142

143143
features = source.getFeatures()
@@ -153,7 +153,7 @@ def processAlgorithm(self, parameters, context, feedback):
153153

154154
exporter.flushBuffer()
155155
if exporter.errorCode() != QgsVectorLayerExporter.NoError:
156-
raise GeoAlgorithmExecutionException(
156+
raise QgsProcessingException(
157157
self.tr('Error importing to Spatialite\n{0}').format(exporter.errorMessage()))
158158

159159
if geomColumn and createIndex:

‎python/plugins/processing/algs/qgis/Intersection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
QgsFeatureSink,
3535
QgsGeometry,
3636
QgsWkbTypes,
37+
QgsProcessingException,
3738
QgsProcessingParameterFeatureSource,
3839
QgsProcessingParameterFeatureSink,
3940
QgsSpatialIndex,
4041
QgsProcessingUtils)
4142

42-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4343
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
4444
from processing.tools import vector
4545

@@ -132,7 +132,7 @@ def processAlgorithm(self, parameters, context, feedback):
132132
int_sym = geom.symDifference(tmpGeom)
133133
int_geom = QgsGeometry(int_com.difference(int_sym))
134134
if int_geom.isEmpty() or not int_geom.isGeosValid():
135-
raise GeoAlgorithmExecutionException(
135+
raise QgsProcessingException(
136136
self.tr('GEOS geoprocessing error: One or '
137137
'more input features have invalid '
138138
'geometry.'))
@@ -145,7 +145,7 @@ def processAlgorithm(self, parameters, context, feedback):
145145
outFeat.setAttributes(attrs)
146146
sink.addFeature(outFeat, QgsFeatureSink.FastInsert)
147147
except:
148-
raise GeoAlgorithmExecutionException(
148+
raise QgsProcessingException(
149149
self.tr('Feature geometry error: One or more '
150150
'output features ignored due to invalid '
151151
'geometry.'))

‎python/plugins/processing/algs/qgis/Merge.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
QgsFeatureRequest,
3535
QgsFeatureSink,
3636
QgsProcessing,
37+
QgsProcessingException,
3738
QgsProcessingParameterMultipleLayers,
3839
QgsProcessingParameterFeatureSink,
3940
QgsMapLayer)
4041

4142
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
42-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4343

4444
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
4545

@@ -78,12 +78,12 @@ def processAlgorithm(self, parameters, context, feedback):
7878
totalFeatureCount = 0
7979
for layer in input_layers:
8080
if layer.type() != QgsMapLayer.VectorLayer:
81-
raise GeoAlgorithmExecutionException(
81+
raise QgsProcessingException(
8282
self.tr('All layers must be vector layers!'))
8383

8484
if (len(layers) > 0):
8585
if (layer.wkbType() != layers[0].wkbType()):
86-
raise GeoAlgorithmExecutionException(
86+
raise QgsProcessingException(
8787
self.tr('All layers must have same geometry type!'))
8888

8989
layers.append(layer)
@@ -95,7 +95,7 @@ def processAlgorithm(self, parameters, context, feedback):
9595
if (dfield.name().upper() == sfield.name().upper()):
9696
found = dfield
9797
if (dfield.type() != sfield.type()):
98-
raise GeoAlgorithmExecutionException(
98+
raise QgsProcessingException(
9999
self.tr('{} field in layer {} has different '
100100
'data type than in other layers.'.format(sfield.name(), layerSource)))
101101

@@ -142,7 +142,7 @@ def processAlgorithm(self, parameters, context, feedback):
142142
for sindex, sfield in enumerate(layer.fields()):
143143
if (sfield.name().upper() == dfield.name().upper()):
144144
if (sfield.type() != dfield.type()):
145-
raise GeoAlgorithmExecutionException(
145+
raise QgsProcessingException(
146146
self.tr('Attribute type mismatch'))
147147
dattribute = sattributes[sindex]
148148
break

‎python/plugins/processing/algs/qgis/PostGISExecuteSQL.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626

2727
__revision__ = '$Format:%H$'
2828

29-
from qgis.core import (QgsProcessingParameterString)
29+
from qgis.core import (QgsProcessingException, QgsProcessingParameterString)
3030
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
31-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3231
from processing.tools import postgis
3332

3433

@@ -67,6 +66,6 @@ def processAlgorithm(self, parameters, context, feedback):
6766
try:
6867
db._exec_sql_and_commit(str(sql))
6968
except postgis.DbError as e:
70-
raise GeoAlgorithmExecutionException(
69+
raise QgsProcessingException(
7170
self.tr('Error executing SQL:\n{0}').format(str(e)))
7271
return {}

‎python/plugins/processing/algs/qgis/RandomExtract.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import random
3030

3131
from qgis.core import (QgsFeatureSink,
32+
QgsProcessingException,
3233
QgsProcessingParameterFeatureSource,
3334
QgsProcessingParameterEnum,
3435
QgsProcessingParameterNumber,
3536
QgsProcessingParameterFeatureSink)
3637
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
37-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3838

3939

4040
class RandomExtract(QgisAlgorithm):
@@ -82,12 +82,12 @@ def processAlgorithm(self, parameters, context, feedback):
8282

8383
if method == 0:
8484
if value > featureCount:
85-
raise GeoAlgorithmExecutionException(
85+
raise QgsProcessingException(
8686
self.tr('Selected number is greater than feature count. '
8787
'Choose a lower value and try again.'))
8888
else:
8989
if value > 100:
90-
raise GeoAlgorithmExecutionException(
90+
raise QgsProcessingException(
9191
self.tr("Percentage can't be greater than 100. Set a "
9292
"different value and try again."))
9393
value = int(round(value / 100.0000, 4) * featureCount)

‎python/plugins/processing/algs/qgis/RandomExtractWithinSubsets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import random
3030

3131
from qgis.core import (QgsFeatureSink,
32+
QgsProcessingException,
3233
QgsProcessingParameterFeatureSource,
3334
QgsProcessingParameterEnum,
3435
QgsProcessingParameterField,
3536
QgsProcessingParameterNumber,
3637
QgsProcessingParameterFeatureSink)
3738
from collections import defaultdict
3839
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
39-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
4040

4141

4242
class RandomExtractWithinSubsets(QgisAlgorithm):
@@ -92,12 +92,12 @@ def processAlgorithm(self, parameters, context, feedback):
9292
value = self.parameterAsInt(parameters, self.NUMBER, context)
9393
if method == 0:
9494
if value > featureCount:
95-
raise GeoAlgorithmExecutionException(
95+
raise QgsProcessingException(
9696
self.tr('Selected number is greater that feature count. '
9797
'Choose lesser value and try again.'))
9898
else:
9999
if value > 100:
100-
raise GeoAlgorithmExecutionException(
100+
raise QgsProcessingException(
101101
self.tr("Percentage can't be greater than 100. Set "
102102
"correct value and try again."))
103103
value = value / 100.0

‎python/plugins/processing/algs/qgis/SelectByAttribute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828
from qgis.PyQt.QtCore import QVariant
2929
from qgis.core import (QgsExpression,
30+
QgsProcessingException,
3031
QgsProcessingParameterVectorLayer,
3132
QgsProcessingParameterField,
3233
QgsProcessingParameterEnum,
3334
QgsProcessingParameterString,
3435
QgsProcessingOutputVectorLayer)
3536
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
36-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3737

3838

3939
class SelectByAttribute(QgisAlgorithm):
@@ -112,7 +112,7 @@ def processAlgorithm(self, parameters, context, feedback):
112112

113113
if fieldType != QVariant.String and operator in self.STRING_OPERATORS:
114114
op = ''.join(['"%s", ' % o for o in self.STRING_OPERATORS])
115-
raise GeoAlgorithmExecutionException(
115+
raise QgsProcessingException(
116116
self.tr('Operators {0} can be used only with string fields.').format(op))
117117

118118
field_ref = QgsExpression.quotedColumnRef(fieldName)
@@ -132,7 +132,7 @@ def processAlgorithm(self, parameters, context, feedback):
132132

133133
expression = QgsExpression(expression_string)
134134
if expression.hasParserError():
135-
raise GeoAlgorithmExecutionException(expression.parserErrorString())
135+
raise QgsProcessingException(expression.parserErrorString())
136136

137137
layer.selectByExpression(expression_string)
138138
return {self.OUTPUT: parameters[self.INPUT]}

0 commit comments

Comments
 (0)
Please sign in to comment.