5

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 <ParameterVector>
length <ParameterNumber>
GRASS_REGION_PARAMETER <ParameterExtent>
GRASS_SNAP_TOLERANCE_PARAMETER <ParameterNumber>
GRASS_MIN_AREA_PARAMETER <ParameterNumber>
GRASS_OUTPUT_TYPE_PARAMETER <ParameterSelection>
output <OutputVector>

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.

1 Answer 1

5

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'}
7
  • 1
    In addition to this answer, I guess the extent should always been set when using grass algorithms from processing module (it's kind of specified in the QGIS doc, but more related on GRASS itself : "GRASS algorithms use a region for calculations. This region can be defined manually using values similar to the ones found in the SAGA configuration, or automatically, taking the minimum extent that covers all the input layers used to execute the algorithm each time".
    – mgc
    Commented Jan 8, 2016 at 18:41
  • Thank you for your answer. Unfortunately I still have the same problem. The output folder is created but is still empty. I tried running your code from the Python Console as well (in case the problem would come from anything in my plugin), but the problem happens as well.
    – Ril8772
    Commented Jan 11, 2016 at 11:02
  • @Ril8772 - Strange, is there anything mentioned in the Log Messages Panel for the Processing tab? Might tell you more of what's happening.
    – Joseph
    Commented Jan 11, 2016 at 11:36
  • 1
    Yes ! There was a problem with the rights to launch GRASS from QGIS. By running QGIS as an administrator it worked. Thank you very much, the problem is solved now :)
    – Ril8772
    Commented Jan 11, 2016 at 14:58
  • @Ril8772 - Awesome! Glad you got it working =)
    – Joseph
    Commented Jan 11, 2016 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.