2

I have a layer of lines that represent stretches of electrical conductors. These sections have a point of origin and an end point. One of its attributes is the length of each of the sections.

Some of these sections have the same point of origin and the same ending point, so when I label these lines by their length, this repeated data appears for each of the lines and the data is repeated.

I need that when labeling the layer, only the label of one of the lines appears, that is, that the distance between each of the points is represented. I have tried to do it by means of a labeling based on rules, and some function of aggregation by geometry, so that only one label is shown for each space between points.

3

Another approach:

If your have an unique numeric field, such as id = 1, 2, ..., you can call it in the expression to distinguish one of overlapping lines.

In the Label with window, give expression:

CASE WHEN "id" = minimum("id" , group_by:=geom_to_wkt($geometry)) THEN "length"
ELSE NULL
END

which would look like below.

enter image description here

This example picks up minimum id field, but you can use any numeric field.
("length" is the field which stores the length attribute).

  • Thanks Kazuhito! It's the perfect solution for me. Thanks very much! – Emilio Abad Jun 26 '18 at 21:17
  • I"m glad. Thank you @EmilioAbad :D – Kazuhito Jun 28 '18 at 4:33
1

One possibility is to create a new layer just for your labels.

  1. In the QGIS Processing Toolbox, go to QGIS geoalgorithms | Vector general tools | Delete duplicate geometries. This create a new layer "Cleaned" without duplicated lines.
  2. Set layer properties of "Cleaned" to show the labels only. (so the style has to be No symbols instead of Single symbol)
  3. Remove label from your original layer.
  • Thanks Kazuhito, thanks for your answer, but I'm looking for an option without creating a new layer regards – Emilio Abad Jun 25 '18 at 15:01
  • @EmilioAbad Got that, thanks for your response. Please see another post which does not need to create a new layer, but requires a field you can use to distinguish one of those overlapping lines. – Kazuhito Jun 25 '18 at 19:27

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.