4

I'm trying to indicate a specific point to fixate 2 lines of a feature's labels. This points should by linked to the END of a guideline's position, who is rendered by the "Geometry Generator" in my shapefile.

I already have an example of what is expected as final result in QGIS. It's a dynamic block that I've elaborated several years ago to AutoCAD.

Dynamic block made into AutoCAD.

Currently what I´ve reached in QGIS, using a Multi-line label and a guideline:

Currently in QGIS

So, the difference between the 2 examples above is on the 1st and the 4th line of QGIS's labels. As I've said, I want to put it always in the guideline's end point with the 4th line on the closest point and the 1st line after the 4th. The problem is: this place is exactly between the 2nd and 3rd line and if I use one more '\ n' (breakline) the final result is not that good.

I don't know if is that a way to "print" the labels in a specific coordinate using Geometry Generator's expression.

Anyone has another idea to do it with the final result similar to the AutoCAD's block ?

Here's the link with the shapefile and the ".qml" style that I'm using on the GIF's example: https://drive.google.com/open?id=12zYPu4aGMMCpXGpE3-mLIiT-q8WM4oae

Label's code:

  "Nodo_tipo"    ||   '\n'  || 
  'CT = '  || "CT_(N)"   ||  '\n'   ||  
   'CF = '  ||"CF_nodo"   ||   '\n'  || 
   'h = '  ||"h_nodo_NT"   || 'm'

And guideline's generator code:

CASE
WHEN @map_scale < 6000
THEN

If ($x < "LABEL_X",

make_line (
make_point( "LABEL_X" + (0.015 * @map_scale), "LABEL_Y" + (0.0065 * 
@map_scale)),
make_point( "LABEL_X" - (0.0020 * @map_scale), "LABEL_Y" + (0.0065 * 
@map_scale)),
make_point( x(centroid( $geometry )), y(centroid( $geometry )))
 ),

make_line (
make_point( "LABEL_X" - (0.0020 * @map_scale), "LABEL_Y" + (0.0065 * 
@map_scale)),
make_point( "LABEL_X" + (0.015 * @map_scale), "LABEL_Y" + (0.0065 * 
@map_scale)),
make_point( x(centroid( $geometry )), y(centroid( $geometry )))

) 

) 
END
6

The solution I found was working with a rule-based label. In this way you can assign different X, Y positions for each set of labels.

I also made some changes to the guideline generation code.


UPDATE: Here's the link with the shapefile and the "line_double_label.qml" style that I'm using on the GIF's example:

https://drive.google.com/file/d/1DsWDSiLuIw9Kf-9gJQv0lUo3dWRvQnA2/view?usp=sharing


See the result, very similar to the CAD result.

QGIS LABEL

enter image description here

The first label shows the "Nodo_Tipo" and "h_nodo_NT". The second shows "CT" and "CF".

First label code:

If ($x < "LABEL_X", "h_nodo_NT"   || 'm'||'  '||Nodo_tipo
,Nodo_tipo||'  '||"h_nodo_NT"   || 'm')

Code for the X and Y coordinates of the label:

X

If ($x < "LABEL_X",

"LABEL_X" + (0.02 * @map_scale),
 "LABEL_X" - (0.03 * @map_scale) )

Y

"LABEL_Y" + (0.0062 *@map_scale)

Second label code:

'CT = ' || "CT_(N)" || '\n' ||
'CF = ' ||"CF_nodo" || '\n'

Code for the X and Y coordinates of the label:

X

"LABEL_X"

Y

"LABEL_Y"
  • 1
    Narcélio, thanks for the answer it's working exactly like I was seeking – LeoNazareth Apr 11 '18 at 17:56

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.