3

Is it possible de create a custom line style in QGIS, as mentioned in the attached file?enter image description here

5

Probably the most straight forward way to achieved that is with Labels (in Layer Properties) on top of a simple line symbol:

  • activate labeling for that layer and choose the field to be used as labels
  • set font size in Text tab
  • in Background tab, check Draw Background and
    • set Shape to Rectangle
    • set Size Type to Buffer
    • set Size X to your liking
    • set Fill Color to your map canvas' background color
  • in Placement tab
    • check On line for Allowed positions
    • set Repeat to your liking

These are the minimal settings to get a similar style as in your picture. What happens here is simple: the value of the chosen field will be placed above a colored rectangle at the desired interval, overlaying the line symbol.
You should play around with the multitude of settings in the Labels tab, try to get familiar with the possibilities. The placement settings get more complicated when labels of different lines overlap etc.

One note to units: using scale sensitive units (e.g. Map Units, Meter at Scale) rather than absolute (e.g. mm) will ensure a fixed size over all scales (e.g. labels get smaller when you zoom out); might be want you want.

  • You have right. When the length feature is short, the label buffer hides the line and the componants of other layers. – ennine Jun 8 '18 at 16:26
  • 1
    @ennine yep. one easy way could be to only allow labels on lines with a certain length; you´d need to find an acceptable threshold, switch to Rule Based Labeling, set up a new rule (your settings should be copied) and type $length > your_value in the Filter field. there are other, data driven options, but at some point you will enter the realm of Cartographic Generalization, and that is a meticulous profession, done by hand... btw., QGIS 3.x comes with a very handy label moving tool – ThingumaBob Jun 8 '18 at 17:06
  • Very interesting suggestion "Rule Based Labeling" which seems a good solution for short lines. Many thanks – ennine Jun 8 '18 at 17:20
  • @ennine also, if you only want the line to disappear (because you only have lines on e.g. white background), you could assign a negative value to Size Y of the label's background, making it only slighty bigger than the line width (careful with bends, though, you need to adjust accordingly); that way you might be able to avoid the label's background covering other components (it might only be possible with Fixed as Shape, not sure right now). – ThingumaBob Jun 8 '18 at 17:36
  • In my case, the rule based on length resolves all my issues. My best thanks – ennine Jun 8 '18 at 18:24

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.