5

I am using QGIS version 3.2.2-Bonn on Windows 10 and this is my first attempt using Python on QGIS from the console. I am following this article: Getting Started With Python Programming

When typing iface in the console a receive the following reply:

qgis._gui.QgisInterface object at 0x0000019EF2194D38

Then when I try to use the dir(layer) command I receive the following error message:

*dir(layer)*
Traceback (most recent call last):
 File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\code.py", line 91, in runcode
 exec(code, self.locals)
 File "<input>", line 1, in <module>
NameError: name 'layer' is not defined

Do I need to configure something before starting using the console?

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Oct 17, 2018 at 0:48

2 Answers 2

5
  • iface is predefined variable in QGIS. qgis._gui.QgisInterface object at .... means that variable iface is an instance of QgisInterface.

  • You probably didn't define variable layer. Thus, you get an error. In the article there is a line layer = iface.activeLayer() above the dir(layer). Firstly, run that code (please be sure to select a layer before), then you can use dir(layer).

answered Oct 17, 2018 at 1:34
0
1

You need to first define the layer first click on Layer=>Vector-Layer=>Upload the .shp file and then select the identity tool and you will see the features and value corresponding to the layer points.

After this write

layer = iface.activeLayer() dir(layer)

After this start using features and then you can do attribute-based clustering and statistical analysis.

answered Oct 25, 2019 at 19:00

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.