I am trying to use v.clean algorithm in QGIS 3 python console. Code is as follows.
lyr = iface.activeLayer()
new_layer = lyr.materialize(QgsFeatureRequest().setFilterFids(lyr.selectedFeatureIds()))
QgsProject.instance().addMapLayer(new_layer)
alg = 'grass7:v.clean'
extent = new_layer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
params = {"input": new_layer, "type": 1, "tool": 0, "-b": True, "-c": True,
"output": "E:/out.shp", "error": "E:/errLayer.shp",
"GRASS_REGION_PARAMETER": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
"GRASS_SNAP_TOLERANCE_PARAMETER": 5, "GRASS_MIN_AREA_PARAMETER": 5,
"GRASS_OUTPUT_TYPE_PARAMETER": 2}
test = processing.run(alg, params)
When I run this code I get following error:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.0\apps\qgis\python\plugins\splitroads\Split_Roads.py", line 211, in run
test = processing.run(alg, params)
File "C:\PROGRA~1\QGIS3~1.0\apps\qgis\python\plugins\processing\tools\general.py", line 84, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:\PROGRA~1\QGIS3~1.0\apps\qgis\python\plugins\processing\core\Processing.py", line 189, in runAlgorithm
feedback.reportError(msg)
TypeError: reportError() missing 1 required positional argument: 'fatal_error'
I have also checked input parameters of v.clean algorithm by using
processing.algorithmHelp("grass7:v.clean")
and got following output
Input parameters:
input: <QgsProcessingParameterVectorLayer>
Layer to clean
type: <QgsProcessingParameterEnum>
Input feature type
0 - point
1 - line
2 - boundary
3 - centroid
4 - area
5 - face
6 - kernel
tool: <QgsProcessingParameterEnum>
Cleaning tool
0 - break
1 - snap
2 - rmdangle
3 - chdangle
4 - rmbridge
5 - chbridge
6 - rmdupl
7 - rmdac
8 - bpol
9 - prune
10 - rmarea
11 - rmline
12 - rmsa
threshold: <QgsProcessingParameterString>
Threshold (comma separated for each tool)
-b: <QgsProcessingParameterBoolean>
Do not build topology for the output vector
-c: <QgsProcessingParameterBoolean>
Combine tools with recommended follow-up tools
output: <QgsProcessingParameterVectorDestination>
Cleaned
error: <QgsProcessingParameterVectorDestination>
Errors
GRASS_REGION_PARAMETER: <QgsProcessingParameterExtent>
GRASS GIS 7 region extent
GRASS_SNAP_TOLERANCE_PARAMETER: <QgsProcessingParameterNumber>
v.in.ogr snap tolerance (-1 = no snap)
GRASS_MIN_AREA_PARAMETER: <QgsProcessingParameterNumber>
v.in.ogr min area
GRASS_OUTPUT_TYPE_PARAMETER: <QgsProcessingParameterEnum>
v.out.ogr output type
0 - auto
1 - point
2 - line
3 - area
Outputs:
output: <QgsProcessingOutputVectorLayer>
Cleaned
error: <QgsProcessingOutputVectorLayer>
Errors
Everything seems fine but I am unable to run it.Can you please let me know how to run v.clean successfully in python console using QGIS 3?