2

I had great luck using Carlos' answer here to make lines from features in a point-shapefile layer to their labels, but when I tried the same technique with a shapefile layer of polygons, it won't work.

When I use the same expression with a polygon layer, for unknown reasons it just draws a straight line and ignores the intermediate point. What could be the reason for this?

9
  • Can you show us the expression? Commented Aug 28, 2018 at 22:04
  • It exhibits the same problem even with exactly the same expression from your answer (linked above).
    – fedora
    Commented Aug 28, 2018 at 22:09
  • What Coordinate System do you use? geografhic or projected? Commented Aug 28, 2018 at 22:16
  • I might be misunderstanding the question, but I'm in WGS 84 (Pseudo Mercator) if that's what you're asking for.
    – fedora
    Commented Aug 28, 2018 at 22:31
  • 3
    The difference between point and polygons isn't relevant here. You just need to use a larger value than 2. In the example, label_x - 2 means 2 decimal degrees west of the label point. Since your layer is in WGS84 (pseudo mercator), the units are meters, so 2 means 2 meters. Figure out how far (in meters) you want the middle point to be from the label point, and use that value instead of 2.
    – csk
    Commented Aug 29, 2018 at 3:29

1 Answer 1

2

Your example uses a different coordinate system from Carlos's answer, so the units are different.

The layer in Carlos' example uses a geographic coordinate system so its units are decimal degrees. In his expression, label_x - 2 means 2 decimal degrees west of the label point.

Your layer is in WGS84 (pseudo mercator) so the units are meters. In this case label_x - 2 means 2 meters west of the label point. The difference is so small, the output looks like a straight line.

Figure out how far (in meters) you want the middle point to be from the label point, and use that value instead of 2. For example, this expression would place the middle point 500 meters west of the label point:

CASE 
 WHEN (label_x IS NOT NULL AND label_y IS NOT NULL) THEN
  make_line(centroid($geometry),make_point(label_x - 500,label_y), make_point(label_x ,label_y))
ELSE
  NULL
END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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