This question is an extension of Copying code generated when you put data into GUI via QGIS Plugins?
I have a Python file I want to run on two loaded layers in QGIS. The layers are TestPhotos (point) and TestObj (point). The tool I want the Python file to run is v.distance.
The column in TestObjects I use in v.distance is OBJ_ID
The Python file is called Test1.py. I have this code:
import processing
processing.runalg('grass7:v.distance', 'TestPhotos','point,line,area','TestObj','point,line,area',-1.0,-1.0,'to_attr','OBJ_ID','OBJ_ID',None,-1.0,0.0001,'nearestobj','distance')
I get the following output using the QGIS Python console:
execfile(u'C:/OSGeo4W64/Test1.py'.encode('mbcs'))
Error: Wrong parameter value: None
I believe it is associated with the v.distance GRASS_REGION_PARAMETER <ParameterExtent> parameter. Any idea how to deal with this to get the Python script working?
EDIT1 - responding to comment
When I typed in processing.alghelp('grass7:v.distance'), i got this:
>>>import processing
>>>processing.alghelp('grass7:v.distance')
ALGORITHM: v.distance - Finds the nearest element in vector map 'to' for elements in vector map 'from'.
from <ParameterVector>
from_type <ParameterString>
to <ParameterVector>
to_type <ParameterString>
dmax <ParameterNumber>
dmin <ParameterNumber>
upload <ParameterString>
column <ParameterString>
to_column <parameters from to>
GRASS_REGION_PARAMETER <ParameterExtent>
GRASS_SNAP_TOLERANCE_PARAMETER <ParameterNumber>
GRASS_MIN_AREA_PARAMETER <ParameterNumber>
from_output <OutputVector>
output <OutputVector>
EDIT2
When I try 'Test.py' with the following code:
import processing
TestPhotos = QgsVectorLayer('c:\OSGeo4w64\TestFiles\TestPhotos.shp', 'TestPhotos', 'ogr')
TestObj = QgsVectorLayer('c:\OSGeo4w64\TestFiles\TestObj.shp', 'TestObj', 'ogr')
extent = TestPhotos.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
processing.runalg(\
'grass7:v.distance', \
TestPhotos,\
'point,line,area',\
TestObj,\
'point,line,area',\
-1.0,-1.0,\
'to_attr',\
'OBJ_ID',\
'OBJ_ID',\
"%f,%f,%f,%f" %(xmin, xmax, ymin, ymax),\
-1.0,0.0001,\
'C:\OSGeo4W64\TestFiles\Outputfile0.shp',\
'C:\OSGeo4W64\TestFiles\Outputfile1.shp')
The output files are correctly generated with the above code. But they are not loaded in QGIS.