Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to write a python plugin to create an input file for an urban climate model out of three shape files. One of the shape files contains the buildings (polygon), one the trees (point), and the third one the center point of the new model input file (point).

I therefore need a function to select one layer out of the currently displayed ones. I tried messing around with

qgis.utils.iface.legendInterface().layers()      

but then I get some ugly output like

qgis.core.QgsVectorLayer object at 0xb4b6f5c.

Is there a possibility to get readable names out of this? Or is there an easier way to select the layers?

Any ideas or help greatly appreciated!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You're returning the layer itself. Go one step further and return the name (property) of the layer. Like this:

layers = qgis.utils.iface.legendInterface().layers()

for layer in layers:
    layerName = layer.name()
    print layerName #or do something else with the name
share|improve this answer
    
Great! That does it. Thanks a lot! –  Dominik Froehlich Sep 13 '12 at 10:09
    
@DominikFroehlich, great! Will you please mark this as the accepted answer, by clicking the checkmark next to the answer? Thanks :-) (why and how: meta.stackoverflow.com/a/5235) –  andytilia Sep 13 '12 at 15:34
    
Ah, now it worked. I had scripts blocked… My fault… Oo –  Dominik Froehlich Sep 18 '12 at 9:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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