Using Calculator in QGIS Graphical Modeler

Since QGIS graphical modeler calculator did not lead to an answer, I'll try my luck here again. I created a simple model in QGIS 2.18.16 that shall calculate a distance based on the extent of a raster and a given number of divisions, set by the user as a parameter. Basically it shall resemble the Fishnet-tool from ArcGIS. The model looks like this: The description in the calculator tells me the following: According to this, I set up my formula like:

(e - d) / b    # this should give me the segment length
(g - f) / a    # this should give me the segment height

The Log from the model run then gives me the following error message:

Parameters:
FORMULA =(g-f)/a,
NUMBER0 =2,
NUMBER1 =3125884.941,
NUMBER2 =3135324.941,
NUMBER3 =None, NUMBER4 =None, NUMBER5 =None, NUMBER6 =None, NUMBER7 =None, NUMBER8 =None, NUMBER9 =None
Failed
Error executing algorithm Calculator Wrong formula: (None-None)/2

Unfortunately, the Documentation is empty. Can anyone tell me how to set up the variables correctly?

• Actually, the question is NOT about how to create a fishnet, but rather about using the calculator correctly Feb 18 '18 at 9:37

I think this is an issue with the code in the file (for me the path is: /QGIS 2.18/apps/qgis/python/plugins/processing/modeler/CalculatorModelerAlgorithm.py). It seems when running the algorithm, the code iterates through all available variables (which is 10) and assigns them their corresponding value.

But this only seems to work if all variables are stated in your formula, otherwise only the variables included in your formula would be given a parameter (NUMBERX). I.e. from your log:

Parameters:
FORMULA =(g-f)/a,
NUMBER0 =2,   --> a
NUMBER1 =3125884.941,   --> f
NUMBER2 =3135324.941,   --> g

A quick remedy is to write your formula and include all the variables which are not used by multiplying them by 0.

• So for your first calculator, try replacing:

(e - d) / b

with:

(e - d) / b + (a+c+f+g)*0

• And for your second calculator, try replacing:

(g - f) / a

with:

(g - f) / a + (b+c+d+e)*0

• True, that's it. Although I have no idea why it is that complicated Feb 19 '18 at 14:59
• @s6hebern - I think with a little edit to the code, this issue could be resolved but glad the workaround works :) Feb 19 '18 at 15:04
• Now I'm running into another problem indirectly related to this... the Create Grid algorithm needs a CRS, but I can't use that as a parameter. Any suggestions? Or post a new question? Feb 19 '18 at 16:12
• @s6hebern - Better post that as a new question (with similar level of detail you posted here) and hopefully others can advise as it does sound strange. Feb 19 '18 at 16:15

I think this plugin "Create Indexed Vector Grid" can helps you.

• I know that function, but as stated in the question and the comment beneath it, it is not about creating the grid in particular, but about the correct notation in the calculator. Feb 19 '18 at 6:50