I am trying to write a plugin in QGIS that uses at some point a GRASS algorithm : "v.split.length", accessible by using the processing class, and here is how I am using it :
processing.runalg("grass:v.split.length",layerToSplit,30.0, None, -1,None, 0, None)
Here is a short reminder on the parameters :
input
length
GRASS_REGION_PARAMETER
GRASS_SNAP_TOLERANCE_PARAMETER
GRASS_MIN_AREA_PARAMETER
GRASS_OUTPUT_TYPE_PARAMETER
output
GRASS_OUTPUT_TYPE_PARAMETER(v.out.ogr output type)
0 - auto
1 - point
2 - line
3 - area
The problem is that when I launch this, it seems to work (there is a short delay showing that the algorithm is working) but when I open the output folder (which, in this case, is a temporary one), it is empty... (i tried saving the output in my folders, the same problem occurs)
I am not sure where my error comes from ... I tried changing the values of some of the parameters (Region, snap tolerance, min area) but nothing worked.
I found this when searching a solution, but in the end the person who faced the problem wasn't sure theirselves of what was the problem.
Answer
If I use your code, I can't get it to run (I think it's because I have to define the minimum extent of the layer manually). The following works for me:
import processing
layer = "C:\Users\Me\Desktop\Test\\line example.shp"
extent = QgsVectorLayer( layer, '', 'ogr' ).extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
res = processing.runalg("grass:v.split.length",layer,30.0, "%f , %f, %f, %f "% (xmin , xmax , ymin , ymax), -1,0, 0, None)
my_layer_path = res['output']
The directory of the temporary output should also be printed in the Python Console when it's finished:
{'output': u'C:\\Users\\Me\\AppData\\Local\\Temp\\processing972389a05d854d6693b4f7b3c2f5dbd8\\01889e0b4cf54fc084097c8af43576e1\\output.shp'}
No comments:
Post a Comment