1

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?

1
  • 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).

  • That is correct, my first script works perfectly now. – MyGIS Oct 19 '18 at 0:02
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.