3

I've digitized a curved line, and label "MONGOLIA" (SCREENSHOT 1)is on the line.

ps: I have around 50 'names' to do it like that.

what I want now is: to perfectly align the labels as 'Align justify' like in Microsoft Word (SCREENSHOT 2) (perfectly align the text to both the left and right margins),

SO if I solve "Align justify" then I don't need to fix the distance for each letter manually(by giving parameter for them all one by one),

Is it actually do it in QGIS? (in maybe Layer properties> label ??)

enter image description here

enter image description here

  • You should be able to set the character spacing based on the length of the line and the number of characters in the name. I haven't figured out the correct formula but it should be possible. – GreyHippo May 24 '18 at 20:57
  • The character spacing is based on the font size units. – GreyHippo May 24 '18 at 21:00
  • @ Hey thanks, and how could I do that? (you meant to set the character spacing in layer properties> Label? maybe use expression..) – ndr May 24 '18 at 21:06
5

First create a new field called SPACING, then calculate the field using a formula, my formula below partially worked for me.

Length of Line / (Length (Name) + 1 or 2)

Then use that field for the character spacing. I also set the label height to map units.

curve line labels

I have updated my answer with your sample data.

I first exported your original data to EPSG 3857 because I know that those units are in meters and not decimal degrees. First I calculated your length field as meters. I then created two label rules based on the lengths of the lines(greater than 500,000 and less than 500,000). I setup each label rule to use map units as text heights and added an expression for the character spacing. As you can see in the results it is not perfect but if you create a few more rules for labels you should be able to tweak your results. character spacing expr

character spacing expression

results

  • Hey, this is with fewer steps, I will try it, thanks – ndr May 28 '18 at 6:07
  • Hey, I've created one column in attribute tables, call spacing with 'real' data type. then used of field calculator(used this formula: $length / (length("name") +1 or 2) ) to get numbers or length of lines in this column, after that in layer properties I've selected the field 'spacing' and doesn't give me any result except labels are disappearing. the number in my table that I saw is too big, like 123544.102100 for example... any other suggestions? maybe I chose the data type of column wrong or maybe because of the coordinates of the data? (which is WGS84) – ndr May 29 '18 at 5:49
  • Any chance you can upload some of your data? – GreyHippo May 29 '18 at 12:55
  • @ GreyHippo Yes, here is the dropbox link, I've shared the data and style with u : dropbox.com/s/w56peapjo5twmw3/data.zip?dl=0 – ndr May 29 '18 at 13:52
  • Do you want the labels to show up at different sizes at different scales? – GreyHippo May 29 '18 at 15:28
2

I tried messing around with the letter spacing parameter, trying to find a relationship between geometrical length of the line feature and the required spacing, but I was getting nowhere fast and it seemed like the results were finnicky at best, so I after some messing around I came up with this solution. It requires a plugin and several steps, so some parts of it may benefit from automation, but I think that the final result is exactly what you are looking for.

Starting with our sample lines:

enter image description here

  1. Make sure your line features have a unique identifier attribute, we will need it later.

  2. Download the QChainage plugin and split your lines into a number of segments equal to the number of letters in their label minus one (I am using "ABCEDFG" as my sample label, so I am using 6):

enter image description here

Result:

enter image description here

  1. Buffer the resultant points using Fixed Distance Buffer, using a distance sufficiently large that it captures the curvature of the line, but sufficiently small that they do not overlap:

enter image description here

  1. Clip the original lines using the generated buffers:

enter image description here

  1. Using Multipart to singleparts to break the resultant multipart features into individual pieces.

  2. Open the Attribute Table of the singlepart line layer you just created and replace the label attribute of each feature with the individual letters of the label from the original line. You can tell the features apart via the unique identifier attribute mentioned in step 0:

enter image description here

(The order of these line features should stay intact because the points used in the buffers used to clip them should have been generated in linear order by QChainage. If some of them are backwards, consider using Reverse Line Direction on the lines that were backwards) and re-doing the steps.

End result:

enter image description here

Works at all scales (provided the final lines are large enough to be labelled):

enter image description here

  • hey @1saac First thank you ;p but is there has a short way to do this? because I have around 50 names + 5o lines..it might take time to do these all with those steps. – ndr May 24 '18 at 20:29

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.