0

I love the QGIS callouts feature for labels but wanted to know if it was possible to anchor the label callout to the original feature position so that when the feature is moved the label callout is visible to the original feature position.

Currently with the label callout, the label has to be moved away from the feature for the callout to show. I was wondering if this could be achieved with the data-defined overide options for the label callouts? I know this is possible to do with the geometry generator in symbology.

1
  • Managed to create the callout line with rule based labeling =) edited my answer accordingly. – Erik Sep 8 '20 at 15:31
2

You need coordinates for the callout lines to appear. So you could use $x and $y to add the original coordinates of the feature to their attribute tables and use these coordinates for data defined override of the label position. So if you move the feature later, the label will stay in place.

In order for the callout line to go from the original position of the feature to the new one, you need to create a rule which is always true (just leave the expression empty) which labels the feature with a single blank space. An empty label wont be displayed, but the space will be. For this labeling rule, enable callout lines and set the label placement to the x/y columns in the attribute table.

Create a second labeling rule with your actual label.

Possible issues:

  1. You're adding more features later on and want to add their coordinates to the attribute table, too. In this case you'll have to use if("x-column" IS NULL,$x,"x-column") in order to not to overwrite existing values. Provided, you didn't set $x/$x as your standard values for newly created features.
  2. You're using lines or polygons. In this case you need to decide where you want the label to be displayed, e.g. at the centroid, or in the middle of the line.
3
  • Cheers - the issue is I don't want the label to stay in the same place. I want the label to move with the feature symbology but for the callout line to lead back to the feature origin – AWGIS Sep 8 '20 at 14:22
  • @AWGIS and why is the geometry generator not an option for you? – Erik Sep 8 '20 at 14:32
  • That worked a treat! A number of reasons, some of which might not make sense - one is that rendering seems slower with geometry generator – AWGIS Sep 8 '20 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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