15

I have adjacent polygons that I want to be marked out with dashed or dotted lines. This sometimes works but there appears to be a problem where the pattern isn't always synchronised on the shared boundaries which leads to odd patterns or solid lines. Is there a simple way round this?

Using GQIS 2.10.1 Pisa

5
  • These answers may be useful gis.stackexchange.com/search?q=dash+polygons. Converting polygons into outlines and removing overlaps should work for sure, perhaps also the white-solid-line-under-the-dash trick gis.stackexchange.com/questions/55365/….
    – user30184
    Commented Nov 23, 2015 at 11:17
  • Using the white line underneath sort of works, but doesn't look quite right unless there's a white background.
    – John K
    Commented Nov 25, 2015 at 11:45
  • Does QGIS have an equivalent to Arc's "Set Representation Control Point At Intersect"?
    – John K
    Commented Nov 25, 2015 at 11:46
  • Hi @JohnK. Did you find an answer? I am using Qgis 3.28 Firenze. Thanks for your question. Commented Mar 26, 2023 at 21:49
  • 1
    @ANDRÉS see answer added - works for newer QGIS versions: works since QGIS 3.28
    – Babel
    Commented Apr 2, 2023 at 13:49

4 Answers 4

18

To this kind of interesting but recurring cartographic question, there is different approaches (some suggested in the comments):

  • The classic approachs is to use dashed lines with a white solid line below to hide the overlapping lines. The downside is that it's not effective if you have a colored background or multiple representations.
  • The other approach is to convert your polygons to polylines, remove overlapping line either by merging them together or using clean tools like MMQGIS / Delete Duplicate Geometries or v.clean in GRASS. Then you will have only one line to map and no more problems with dashes.
  • My favorite is to offset lines towards the inside of each polygon, therefore avoiding any overlap while keeping the line symbology of each polygon, especially in case of different dashes, symbology and colors you would like to keep visible in thematic mapping.
2
  • 3
    Adding a symbol layer -> simple line -> white solid line is a great hack and can be adapted for any monocolor background +1
    – Wassadamo
    Commented Feb 5, 2019 at 23:35
  • Thanks @gisnside. I have used your second approach to style my poligons. Commented Jul 7, 2023 at 10:48
6

Since QGIS 3.28, there is a new shared_paths() function in QGIS expressions. Using it, you can achieve what you want.

Use symbol layers with Geometry Generator. Create two symbol layers, one for the inside, shared boundaries, the other for the outside boundaries (not shared with neighboring polygons). Use the expressions from below.

Pink dotted line: shared boundaries; blue dotted lines: outside boundaries; light blue line fill pattern just for visualization purpose (showing different polygons): enter image description here

  1. Shared boundaries: Convert polygons to lines with function boundary() and for each polygon create the common boundary with all other polygons. It tests all other polygons (all polygons with a $id larger than the current polygon) if it shares any boundary and returns this boundary, using shared_paths() function. Use this expression:

     collect_geometries (
         array_foreach (
             array_filter (
                 array_agg($id), 
                 @element > $id
             ),
             shared_paths (
                 boundary (geometry (get_feature_by_id (@layer, $id))),
                 boundary (geometry (get_feature_by_id (@layer, @element)))
             )
         )
     )
    
  2. Outer boundaries: create the outer boundary just once, do not repeat it for each feature, thus use a case condition:

     case 
     when $id=minimum ($id)
     then boundary (buffer (collect ($geometry),0))
     end
    
4
  • 1
    Though this expression removes the outer boundaries it still results in overlapping dashed lines for me (QGIS 3.30) Commented Apr 14, 2023 at 7:22
  • Difficult to say without seeing your data. Maybe your boundaries are not exactly overlapping
    – Babel
    Commented Apr 14, 2023 at 14:32
  • I don't understand if the lines that refer to the outer limits you just put in the geometry generator or if something else needs to be written. Because the outer limits are still polygons, not lines. And I was able to create shared boundaries, but only the outer boundaries are shown. Thanks @Babel Commented Jul 4, 2023 at 14:47
  • Not sure what you mean and difficult to say what you have and how it looks. You should probably ask a separate question to have enough place to include all relevant informtion + screenshots. You might link to this post here for context.
    – Babel
    Commented Jul 4, 2023 at 16:32
2

I've been looking for a solution for a long time. Finally, inspired by @Babel's answer I created my own solution that works faster. But it creates only shared boundaries. Geometry generator expression:

collect_geometries(
    array_foreach(
        array_filter(
            array_foreach(
                array_filter(
                    overlay_intersects(
                        layer:=@layer,
                        expression:=@geometry,
                        return_details:=True
                    ),
                    map_get(@element,'id')>@id
                ),
                intersection(map_get(@element,'result'),@geometry)
            ),
              geometry_type(@element)='Line'
        ),
    line_merge(@element)
    )
)

The result I get: enter image description here

0

QGIS 3.10 also has the option of setting the symbol layer type as outline: simple line. There you have more options for setting the spacing and length of dash patterns, which can resolve some of these overlapping problems where the white solid line background doesn't help.

To achieve this while keeping fill colors of the polygons, you can duplicate the layer in the layer tree. This will not duplicate the layer file or database table, as the data source will not be altered. The duplicate can have its own settings, joins, visual representation, labels, etc.

In the duplicate layer, change the symbology (from e.g. 'simple fill') to one of the outline styles. This should give you fill polygons and no overlapping dashed lines between the polygons.

2
  • Could you explain your approach in more details? I am using Qgis 3.28 Firenze. Thanks. Commented Mar 26, 2023 at 21:47
  • @ANDRÉS I added what should do the trick. If it doesn't work, please report back.
    – thymaro
    Commented Apr 1, 2023 at 17:13

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.