3

I'm trying to build a simple multi-step selection (by attribute) with the QGIS Modeler. I created a simple sample layer to avoid data-driven errors. Now I want to query the layer and select features 1) by feature attribute "name" AND/OR 2) by feature attribute "age". The model executes the first query (name), picking up two features and then fails on the second, which should result in the selection of a single feature.

The log tells me "Error executing algorithm 1 local variable 'x' referenced before assignment See log for more details". The "History and log" (under Processing) ERROR section tells me to "See log for more details". So two logs tell me to look at a log. Is there a third log somewhere?

Another problem is that the selection comparison only allows one option (e.g. "=="). This is problematic because I want to be able to search for just "age" as well. Leaving the field for name blank selects nothing.

A few screenshots: enter image description here enter image description here enter image description here enter image description here

Using the modeler has also been a quite frustrating experience so far. Python errors out of the blue, not being able to delete algorithms before filling the input variable fields with garbage, nor being able to delete algorithms at all and QGIS just crashing. Is this "normal"?

5
  • 3
    To my experience, this is quite normal - have had very limited succes using it, and have in its current state stopped using it, since it is so unreliable... Commented Mar 1, 2015 at 11:52
  • 1
    What QGIS version are you using? be sure that you are using a recent QGIS release and then also that in your .qgis2/python/plugins folder you don't have any "processing" folder. If yes then delete it, restart qgis and try again.
    – gioman
    Commented Mar 2, 2015 at 8:05
  • 1
    because of this question I did a test and then opened an issue for QGIS. hub.qgis.org/issues/12289 But I should say that the tiket I opened is not necessarly related with this error. Commented Mar 2, 2015 at 9:42
  • @Giovanni Manghi 2.4!
    – MapEngine
    Commented Mar 5, 2015 at 17:45
  • @MapEngine please upgrade to 2.8.1 and check you don't have any processing folder in your plugins one.
    – gioman
    Commented Mar 6, 2015 at 16:09

1 Answer 1

3

I got your model running using a shape file instead of a spatialite db.

enter image description here

Can you try a shape file first, to see if it's work. Then perhaps it would be easier, to identify any Spatialite problems. I also added my model code, so you can check against your model. I got another Python error than you using Spatialite:

Algorithm testModel starting...
Prepare algorithm: QGISSELECTBYATTRIBUTE_1
Running Select by attribute [1/2]
Parameters: INPUT =dbname='D:/Dropbox/qgis/Spatialite/spatialite_join_test/myDB.sqlite' table="jackdiane" (geometry) sql=, FIELD =Name, OPERATOR =0, VALUE =Jack
String field
"Name" = 'Jack'
Converting outputs
OK. Execution took 0.046 ms (1 outputs).
Prepare algorithm: QGISSELECTBYATTRIBUTE_2
Running Select by attribute [2/2]
Parameters: INPUT =dbname='D:/Dropbox/qgis/Spatialite/spatialite_join_test/myDB.sqlite' table="jackdiane" (geometry) sql=, FIELD =Age, OPERATOR =0, VALUE =3
Failed
Error executing algorithm Select by attribute Unsupported field type "INTEGER"

Model:

{
    "values": {
        "inputs": {
            "STRING_NAME": {
                "values": {
                    "pos": {
                        "values": {
                            "y": 93.0, 
                            "x": 191.0
                        }, 
                        "class": "point"
                    }, 
                    "param": {
                        "values": {
                            "isAdvanced": false, 
                            "name": "STRING_NAME", 
                            "default": "", 
                            "value": null, 
                            "multiline": false, 
                            "hidden": false, 
                            "optional": false, 
                            "description": "Name"
                        }, 
                        "class": "processing.core.parameters.ParameterString"
                    }
                }, 
                "class": "processing.modeler.ModelerAlgorithm.ModelerParameter"
            }, 
            "VECTORLAYER_LAYER": {
                "values": {
                    "pos": {
                        "values": {
                            "y": 93.0, 
                            "x": 430.0
                        }, 
                        "class": "point"
                    }, 
                    "param": {
                        "values": {
                            "isAdvanced": false, 
                            "name": "VECTORLAYER_LAYER", 
                            "shapetype": [
                                -1
                            ], 
                            "value": null, 
                            "exported": null, 
                            "hidden": false, 
                            "optional": false, 
                            "description": "Layer"
                        }, 
                        "class": "processing.core.parameters.ParameterVector"
                    }
                }, 
                "class": "processing.modeler.ModelerAlgorithm.ModelerParameter"
            }, 
            "STRING_AGE": {
                "values": {
                    "pos": {
                        "values": {
                            "y": 191.0, 
                            "x": 484.0
                        }, 
                        "class": "point"
                    }, 
                    "param": {
                        "values": {
                            "isAdvanced": false, 
                            "name": "STRING_AGE", 
                            "default": "", 
                            "value": null, 
                            "multiline": false, 
                            "hidden": false, 
                            "optional": false, 
                            "description": "Age"
                        }, 
                        "class": "processing.core.parameters.ParameterString"
                    }
                }, 
                "class": "processing.modeler.ModelerAlgorithm.ModelerParameter"
            }
        }, 
        "group": "testGroup", 
        "name": "testModel", 
        "algs": {
            "QGISSELECTBYATTRIBUTE_2": {
                "values": {
                    "name": "QGISSELECTBYATTRIBUTE_2", 
                    "paramsFolded": true, 
                    "outputs": {}, 
                    "pos": {
                        "values": {
                            "y": 313.0, 
                            "x": 353.0
                        }, 
                        "class": "point"
                    }, 
                    "outputsFolded": true, 
                    "dependencies": [], 
                    "params": {
                        "OPERATOR": 0, 
                        "INPUT": {
                            "values": {
                                "alg": "QGISSELECTBYATTRIBUTE_1", 
                                "output": "OUTPUT"
                            }, 
                            "class": "processing.modeler.ModelerAlgorithm.ValueFromOutput"
                        }, 
                        "VALUE": {
                            "values": {
                                "name": "STRING_AGE"
                            }, 
                            "class": "processing.modeler.ModelerAlgorithm.ValueFromInput"
                        }, 
                        "FIELD": "Age"
                    }, 
                    "active": true, 
                    "consoleName": "qgis:selectbyattribute", 
                    "description": "Select by attribute"
                }, 
                "class": "processing.modeler.ModelerAlgorithm.Algorithm"
            }, 
            "QGISSELECTBYATTRIBUTE_1": {
                "values": {
                    "name": "QGISSELECTBYATTRIBUTE_1", 
                    "paramsFolded": true, 
                    "outputs": {}, 
                    "pos": {
                        "values": {
                            "y": 192.0, 
                            "x": 243.0
                        }, 
                        "class": "point"
                    }, 
                    "outputsFolded": true, 
                    "dependencies": [], 
                    "params": {
                        "OPERATOR": 0, 
                        "INPUT": {
                            "values": {
                                "name": "VECTORLAYER_LAYER"
                            }, 
                            "class": "processing.modeler.ModelerAlgorithm.ValueFromInput"
                        }, 
                        "VALUE": {
                            "values": {
                                "name": "STRING_NAME"
                            }, 
                            "class": "processing.modeler.ModelerAlgorithm.ValueFromInput"
                        }, 
                        "FIELD": "Name"
                    }, 
                    "active": true, 
                    "consoleName": "qgis:selectbyattribute", 
                    "description": "Select by attribute"
                }, 
                "class": "processing.modeler.ModelerAlgorithm.Algorithm"
            }
        }
    }, 
    "class": "processing.modeler.ModelerAlgorithm.ModelerAlgorithm"
}

Hope this can help you get going with the modeler.

1
  • The SL was indeed the problem. I tried my model with a shape file like suggested and it performed the right selection.
    – MapEngine
    Commented Mar 5, 2015 at 22:18

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.