4

I'm trying to make curved labels based on map projection. As in these examples, I would like labels for point layers to follow parallels. Is that possible in QGIS 3?

enter image description here

Or a labeling style like this: enter image description here Or like this in world map spherical projection: enter image description here

5
  • The answer to your question is: yes. See here: gis.stackexchange.com/q/199702/88814
    – Babel
    Commented Aug 17, 2022 at 7:13
  • Babel i think that's not what i asked. I'm trying to adapt labels of point layer with the projection grid, from WGS 84 to RDN2008/italy zone (E-N), for example in the map i have posted name SARDINIA (angle of rotation) and the parallel name Otranto and other names in that sector (angle of rotation same as parallel).
    – Iven Pepa
    Commented Aug 17, 2022 at 11:56
  • OK, you didn't state that in your initial question. You should provide as many details about what you want to achieve, what you have tried and where exactly you're stuck - see tour. It's still not 100% clear to me what exactly is your goal.
    – Babel
    Commented Aug 17, 2022 at 12:25
  • Sorry, adding the spherical projection screenshot does not help understanding what exactly you want to achieve. We see a lot of labels there. Please add more details to your question.
    – Babel
    Commented Aug 17, 2022 at 15:30

3 Answers 3

5

It is possible. The way I know how to do it is in a roundabout way that requires using geometry generator and expressions. In the following screenshot example, you can see it in action. What I did:

  • Created a project and load a basemap just for visualization

  • Created two layers with EPSG:4326 CRS (the line layer for visualization with a few vertices all Y coordinates at the same 45° value, the point layer to contain a point with its label). This could be any geographic coordinates system if you want your labels to align with parallels

  • Set the labels up and went to the placement tab

  • Checked the geometry generator box, set it to Polyline/Multiline and changed general settings placement mode to Curved

  • In the geometry generator textbox, entered this expression:

     make_line(
     make_point(
         $x - 2,$y),
     make_point(
         $x - 1.5,$y),
     make_point(
         $x - 1,$y),
     make_point(
         $x - 0.5,$y),
     make_point(
         $x,$y),
     make_point(
         $x + 0.5,$y),
     make_point(
         $x + 1,$y),
     make_point(
         $x + 1.5,$y),
     make_point(
         $x + 2, $y)
     )
    

Now you can change your project CRS to a system that will show parallels as curves and the labels on the point layer should align with them. The label in my example looks linear but it is curved. It should be parallel to the red line. Of course only the vertices on lines are reprojected on the fly so if you want a finer curve, you need to add more vertices.

Maybe there's a better way, but this will work. Basically, I created a line just like the red one, but as the virtual geometry that the label is supposed to be based on. In the example, the final project CRS is EPSG:6622, which is a Lambert conical system.

enter image description here

7
  • Yes it works and its perfect for the point layer. How about the line and polygon layer ? What geometry expression should i use for country polygon labels to have the same result?
    – Iven Pepa
    Commented Aug 17, 2022 at 19:38
  • 1
    @IvenPepa It gets a bit more difficult because you probably want the labels to not overlap each others so much. But in the expression I quoted above, you can replace the $x and $y by x(centroid($geometry)) and y(centroid($geometry)). This would make the base point from which the line is created the centroid of your polygons.
    – Gabriel
    Commented Aug 17, 2022 at 19:45
  • Yes its awesome, it works on polygon labels too but i cant wrap the text anymore. So if you can see the label of North America in the world map i think that is wrapped. Is there a way to do that ?
    – Iven Pepa
    Commented Aug 17, 2022 at 19:57
  • 1
    The issue is that at smaller scales, the line might not be long enough (in pixel units) to actually render the label. This means you will need to tweak the distances. I made the line extend 2° east and west of the points, but for a world map, it's not going to be long enough.
    – Gabriel
    Commented Aug 17, 2022 at 20:09
  • Yes i understand, I just tried to wrap characters but it was in curved mode so i changed in parallel mode and it works with the same geometry expression. Thank You @Gabriel.
    – Iven Pepa
    Commented Aug 17, 2022 at 20:21
2

You can add a function to QGIS that will rotate your labels along parallels, as described in the answer to this question: Parameters of the coordinate system for calculating the rotation of labels along latitude lines

1

The solution to your question in fact needs two steps:

  1. Create a grid that shows parallels correctly in any projection as curved lines, not rectangular ones (depending on projection of map canvas) - see first screenshot.
  2. Apply a curved label on that parallels, following the curved shapes of the parallels.

Red - the solution you're looking for: densified grid in EPSG:4326 (parallels); black - for comparision only: rectangular grid in the project CRS, EPSG:3003: enter image description here

Proceed as follows (steps 1-2 create the grid, step 3 the curved label):

  1. Create the parallels: Menu Vector > Research Tools > Create grid, grid type = Line, Grid CRS = EPSG:4326 (this is important to get real parallels). Define the desired spacing (in degrees), e.g. 1 [degree].

  2. Densifiy the grid - use Menu Processing > Toolbox > Densify by interval and define a fraction of the spacing from above, e.g. 0.0001 (should be several powers of ten smaller then the spacing, like here: 1000 times). Alternatively, use Densify by count.

    Like this, the densified grid will show correctly in any projection of the map canvas (project CRS) - here in EPSG:3035/ETRS89-extended / LAEA Europe: enter image description here

  3. Label the desified lines (parallel grid) created in step 2. In the label settings, go to Placement tab and set the mode to Curved.

You can now freely change the projection the map canvas appears in by changing the Project CRS (not the layer CRS): the label will always follow the curved parallels.

See here how to create parallel grids:

Project CRS (map canvas) in EPSG:7794: creating a line grid in EPSG:4326 creates straight lines, but the grid is not rectangular (it would be so with project CRS/map canvas in EPSG:4326). If you created a grid in the same CRS as the project CRS (here: EPSG:7794), the grid would be rectangular: enter image description here

The densified grid from above appears (correctly) as curved lines: enter image description here

Comparision between both variants from above - quite a difference. See here for why that is so: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.