1

I am using QGis and making a Python script that sets the Python Init function to a custom UI file. I have a function with the following signature:

def formOpen(dialog, layer, feature):
    ...

I can access the given layer and it's contents - this works fine. But what should I do in order to access other layers?

My use case is the following: Whenever a given feature F of layer A is modified, I want to calculate the intersection of feature F with all geometry objects of layer B and show it to user. This information is later saved to the database.

I understand that in order to do that, I should be able to access the interface object. In my plugin I save the reference to the interface by:

self.iface = iface.

However, the Python init function is out of my plugin. Should I put it inside my plugin? Or use global variables?

1 Answer 1

3

QgsMapLayerRegistry is a singleton. You can therefore access it without iface.

QgsMapLayerRegistry.instance().mapLayers()

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.