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?

Maxima
  • 1,701
  • 7
  • 18
fedora
  • 195
  • 4
  • Can you show us the expression? – Carlos López Quintanilla Aug 28 '18 at 22:04
  • It exhibits the same problem even with exactly the same expression from your answer (linked above). – fedora Aug 28 '18 at 22:09
  • What Coordinate System do you use? geografhic or projected? – Carlos López Quintanilla Aug 28 '18 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 Aug 28 '18 at 22:31
  • ok, I thought that you use projected coordenate system, this was a reason that you don't see the midle point, beacuse the expresion use label_x - 2, and 2 is in degrees if you use geografhic SRC. – Carlos López Quintanilla Aug 28 '18 at 22:41
  • Ohhhh. In that case it seems like it wouldn't work for point features either. It seems super strange to me that it works for point labels but not polygons... – fedora Aug 28 '18 at 22:48
  • 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 Aug 29 '18 at 03:29
  • You're both exactly right, that did it. I'm still getting the hang of GIS, clearly need to brush up on coordinate systems. Thanks! – fedora Aug 29 '18 at 19:01
  • Happy to help. I posted my comment as an answer. Please click the green check mark to accept my answer, so others with the same issue will know what the solution was. – csk Aug 31 '18 at 16:52

1 Answers1

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
csk
  • 24,827
  • 3
  • 32
  • 70