[GIS] How to set position of label around a point in qgis according to a field

labelingqgis

I'm working on a shape file in qgis (2.8.4 Wien for Mac). In this file I have several points with about ten fields. What I'm interest in is to use two of these fields to set position of the label and the rotation of the symbol of the point: one field is the id of the point, the other one is the rotation.

I represent the point symbol as a triangle with a little line, and I rotate it according to the rotation field (I have no problem with this).
The main problem is to place the label of the ID around the point in a specific position, according to the rotation, but without rotate it.

The rotation field contains, obviously, values from 0 to 359.

In the picture below, there is a sample of what I want to obtain:

result sample

I think is possible to use a offset function with sinus and cosinus, but the corresponding buttons are disabled on qgis interface.

There is a way to do this? Unfortunately this is a requirement of the work I'm doing.

Best Answer

In addition to the linked answer from @MaryBeth in the comment, for QGIS 2.12.1 (lyon) there's now a data defined rule for "quadrant" or the position of the label.

In the labeling dialog, select the "Placement" tab and then check the radio bullet for "Around point".

Then there is an option to set an expression for the "Quadrant".

qgis quadrant option for data defined labelling

If you check the description, it tells you what it expects as input.

In this case, it expects an int (an integer).

Data defined override
Active: no   (ctrl|right-click toggles)
Expected input:
int
[0=Above Left|1=Above|2=Above Right|
3=Left|4=Over|5=Right|
6=Below Left|7=Below|8=Below Right]
Valid input types:
string, int, double
Current definition :
undefined

You can see where each number represents a place in the quadrant.

So you just have to setup CASE ELSE type expression here that looks at the rotation values in your rotation field.

eg,

CASE
  WHEN "rotation" = 45 THEN 2
  WHEN "rotation" = 90 THEN 6
ELSE 0
END

Your WHEN statement can use ranges as well,

WHEN "rotation" >= 0 AND "rotation" <= 50 THEN ...