I'm trying to run a grass
command (v.split.length
) using the processing
library in pygis
. The script is as follows:
import processing
layer = r'path\to\shp.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,1000, "%f , %f, %f, %f "% (xmin , xmax , ymin , ymax), -1,0, 0, r'path\to\out_shp\out_shp.shp')
When I execute the script I get the following message box:
GRASS folder is not configured. Please configure it before running GRASS algorithms.
I am running QGIS 2.18.22 with GRASS 7. What I have noticed in the processing options is as follows:
The Grass7 folder appears to be defined but Grass folder is not. Further more inside my QGIS installation this is what I can see
C:\Users\aboufira>cd C:\Program Files\QGIS 2.18\apps\grass
C:\Program Files\QGIS 2.18\apps\grass>dir
Volume in drive C is OS
Volume Serial Number is 944A-AABE
Directory of C:\Program Files\QGIS 2.18\apps\grass
07-Aug-18 15:49 <DIR> .
07-Aug-18 15:49 <DIR> ..
07-Aug-18 15:49 <DIR> grass-7.4.1
0 File(s) 0 bytes
3 Dir(s) 31,910,600,704 bytes free
There are two possible solutions:
- install the regular version of GRASS and add the folder to
apps
path such that when I open the providers menu I can see the path appear under regular GRASS - Find a way to call the grass 7 algorithms from the Python console. It seems that
processing.runalg
by default attempts to run the regular GRASS algorithms
Which of these options is the more straightforward one and how do I implement it? If there is an alternate option I am also open to that.