1

In a QGIS script, how do you set a Vector input (via your tool's GUI) as a variable which can then be used in subsequent processing in your tool's script?

I know how to set a map Layer as a variable, for example:

 pts = QgsMapLayerRegistry.instance().mapLayersByName('civic_pts')[0]

But instead of hard-wiring my file inputs like that, I want the flexibility of setting my inputs via the tool's GUI.

I've tried:

 ##Input_civic_pts=vector

...and then tried using it later in the script, for example...

 for feat in Input_civic_pts.getFeatures():

...but this generates an error.

The same script works fine when I hard-wire the civic_pts file as above.

Obviously I don't know how to convert an Input to a scripting variable.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 23, 2015 at 18:37

1 Answer 1

1

The

##Input_civic_pts=vector

doesn't mean the layer object, you have to use a function to get the layer object itself:

inputLayer = processing.getObject(Input_civic_pts)

See the documentation here: http://docs.qgis.org/2.0/ca/docs/user_manual/processing/console.html

answered Dec 23, 2015 at 19:07
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.