1

I want to get QGIS to update from a CSV file like in this How to update data from external table in real time? question, however I can't figure out what to put for "myLayer". How can I define the active QGIS layer in my code?

1 Answer 1

1

The most basic approach would be

myLayer = iface.activeLayer()
3
  • Thank you for the response! However I did try that and I got 'name "iface" is undefined' so it doesn't compile - do you know why?
    – swooders
    Feb 16, 2015 at 21:55
  • Which QGIS version are you using? The code provided by @underdark should work (I use QGIS 2.2 and 2.6 and worked for both). To be extra safe, you could first try import qgis.utils and then myLayer = qgis.utils.iface.activeLayer()
    – Joseph
    Feb 17, 2015 at 10:39
  • I'm using 2.6 and import qgis.utils worked! Thank you so much.
    – swooders
    Feb 17, 2015 at 16:35

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.