Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a map of a region and I am plotting pie-charts (as diagrams) over every country in that region in QGIS (1.9.0). I also need to connect those pie-charts with lines (which I am creating in the Mapping Toolbox of MATLAB as a separate shape-file). Can you please tell me if there is a way of knowing in advance what coordinates of a country QGIS shows its pie-chart at? Also, can I capture those coordinates automatically (even before the pie-charts are drawn) just as I would normally do using the Coordinate Capture plugin? That way, I can create the lines from one point to another before even plotting the pie-charts.

Thank you.

share|improve this question
up vote 4 down vote accepted

QGIS uses the PAL library to determine the "best" diagram position, which places diagrams, based on render context information such as DPI, zoom level...

To get diagrams to render at the same place every time, you can either use the placement method "Over Point" which will always put the diagrams over the centroid of the polygon.

enter image description here

Or you can specify the place, where you want to put the diagram yourself with "Data defined position" using attributes.

enter image description here

I don't think there is a way to dynamically intercept the (PAL-calculated) diagram position before they are drawn in order to adjust your line nodes.

Hint: To manually define x and y attributes for placement, you can first "prepare" them with labels. Label your layer with whatever attribute and enable data defined placement. Then use the "move label" tool to position your labels, wherever you would like to have the diagrams placed. Now disable labeling and enable diagrams with data defined placement.

share|improve this answer
Thank you for your reply. I'm having problems with the 'Over Point' option because, for some reason, parts of some pie-charts are crossing over into other countries. The option which works best for me is 'Horizontal'. Can you please tell me what method it uses to place a pie-chart on a country? Also, there's another option, 'Free', which I don't know how to use. Can you please tell me how that works? – Usman Jul 7 '13 at 14:29
Crossing into other countries happens due to "banana shaped" polygons, where the centroid lies outside or close to the border. Source-code comments for horizontal: "Only for polygon, arranges candidates horizontaly" Source-code comments for free: "Only for polygon, arranges candidates with respect of polygon orientation" – Matthias Kuhn Jul 7 '13 at 14:49
I see. You're right. That happened with Sweden, for example. Thank you very much for your help. – Usman Jul 7 '13 at 15:04
Can you please tell me if there is a way to obtain or capture the coordinates after the pie-charts have been drawn without clicking on them (i.e. without using the Coordinate Capture plug-in)? And, if they can be obtained automatically, is there a way to populate an array (e.g. in MATLAB) with them so that the lines can be drawn between them? I am trying to automate this process as much as possible. – Usman Jul 7 '13 at 19:23
I don't think that's possible. Maybe there is actually some trick with qgspallabeling. But I can't think of a way to do so. If you really need to automate, it's probably the easiest to use data defined position and fill the attributes with sensible values yourself. – Matthias Kuhn Jul 8 '13 at 7:15

Your Answer


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.