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 create some custom labels for point features in a QGIS point vector layer, and I want to write a python plugin to do it. We need our labels to be presented with color tinted rectangles behind them (or else!). The labels are long strings, and are created using labeling engine expressions and conditionals.

I thought the easiest way would be to let the user set up labels for the active layer the way they want, and then let my plugin can grab the label text from the features in the layer and use the text strings to create boxes. My problem is I can't find a way to access those text strings in the QGIS API. How are label strings generated by the labeling engine stored in QGIS and how can I get to them?

share|improve this question
1  
By labels do you mean the labels for the individual point features? –  R.K. Dec 22 '12 at 8:38
    
Yes. And I want it done at the layer level, not at the print composer level. I tried automatically generating text callout boxes because I didn't realize they were print composer features, and that was really ugly. –  MonsterMushroom Dec 27 '12 at 9:44
1  
Have you thought about a strong buffer colour behind the text? I did that on one job. On another I just told the client it was not an option.... It seems a common request.... –  Willy Dec 28 '12 at 23:58
1  
The strong color buffer is my current solution. However, the client had the boxes (using a script) in their ArcGIS implementation, and they want to see the same thing in QGIS. (We're trying to change systems.) My current answer is that this is not an option, but that is never a fun answer, and I would really like to pull something out of my pocket. Plus, boxes around labels should be something we can do. It just makes sense. –  MonsterMushroom Dec 30 '12 at 12:58
    
I think the answer to this is going to be that once the labels are generated by the labeling engine and rendered to the map canvas, they are saved as svg vectors, and not as strings and are thus irretrievable. I saw this on a blog but I have not yet been able to (had the time to) confirm it, so that is not an official answer. (Also, I have learned that shield labels are being worked on as an add for the much anticipated 2.0) –  MonsterMushroom Feb 5 '13 at 20:14

1 Answer 1

up vote 0 down vote accepted

In QGIS 2.0, you can create background rectangles, ovals or custom SVG shapes without the need for a plugin. Just go to Layer Properties | Label | Background section.

enter image description here

If you want to code something. This might be a starting point: http://doc.qgis.org/api/qgspallabeling_8cpp_source.html#l04333

share|improve this answer
    
Lovely! 2.0 is going to be five kinds of cool. We await it with bated breath. –  MonsterMushroom Jun 30 '13 at 15:55

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.