6

In QGIS 3.16 I have a shapefile layer where linear features will often be digitised close to each other. These lines are all features in the same layer.

Example when zoomed in:

example of 3 lines

Problem when zooming out to export wider map:

3 lines overlap

When I zoom out, the 3 line symbols overlap each other. Making the lines thinner doesn't help as they 1) still overlap, and 2) are simply too thin for this scale map.

I want the lines to retain a decent thickness but not battle each other for space. I want them to automatically detect they are close to each other and line up side by side, or spaced out a bit for clarity.

3
  • @Babel offseting/generalizing the geometry would surely offset each line by the same amount. ie. it'd just shift the problem I'm having to a new location. In the example above I'd ideally want the orange line symbol to stay in the same place, the pink line to shift north and the blue line to shift south.
    – Theo F
    Commented Jul 14, 2021 at 16:51
  • 1
    Of course, my thoughts are not a ready-made solution, but it could be a starting-point to think about how to offset just the lines at the outside, but not the one in the middle. But there might be indeed easier options.
    – Babel
    Commented Jul 14, 2021 at 16:55
  • These are for overlapping line but could give you some ideas : gis.stackexchange.com/questions/261654/… and gis.stackexchange.com/questions/277958/…
    – J.R
    Commented Jul 14, 2021 at 17:13

1 Answer 1

7

What you want to do is a cartographic generalization operation called displace. You might have a look at GRASS v.generalize, it has an option for displacement.

Principal idea of the solution

What I propose, however, is using geometry generator with the function offset_curve( ) and for the distance use the variable @map_scale, divided by a constant.

How to implement it

  1. The line in the middle should not be offset at all and the lines at the right and left should be offset in the respective direction. For this, create a new attribute offset and add for each line a value of 0 (no offset), 1 (offset to the left) or -1 (offset to the right). You could also set other numbers to get different offset distances for different roads: the higher the number, the higher the offset.

  2. Combine these elements with geometry generator and this expression (change 500 to a value that fits your data):

    offset_curve ($geometry, "offset" * @map_scale/500)
    

When you now zoom out, the lines to the right and left move away from the line in the center:

Screenshot 1: black solid line: mid-line (no offset), black dotted line: original line that must be offset, red-lines: offsetted lines: enter image description here

Screenshot 2: result when zooming out: 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.