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

Babel
  • 71,072
  • 14
  • 78
  • 208
John K
  • 213
  • 2
  • 8
  • These answers may be useful http://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 http://gis.stackexchange.com/questions/55365/overlapping-lines-representation. – user30184 Nov 23 '15 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 Nov 25 '15 at 11:45
  • Does QGIS have an equivalent to Arc's "Set Representation Control Point At Intersect"? – John K Nov 25 '15 at 11:46
  • Hi @JohnK. Did you find an answer? I am using Qgis 3.28 Firenze. Thanks for your question. – ANDRÉS Mar 26 '23 at 21:49
  • 1
    @ANDRÉS see answer added - works for newer QGIS versions: works since QGIS 3.28 – Babel Apr 02 '23 at 13:49

4 Answers4

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.
gisnside
  • 7,818
  • 2
  • 29
  • 73
5

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
    
Babel
  • 71,072
  • 14
  • 78
  • 208
  • Though this expression removes the outer boundaries it still results in overlapping dashed lines for me (QGIS 3.30) – sidapo_cartisan Apr 14 '23 at 07:22
  • Difficult to say without seeing your data. Maybe your boundaries are not exactly overlapping – Babel Apr 14 '23 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 – ANDRÉS Jul 04 '23 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 Jul 04 '23 at 16:32
1

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

BlackTesta
  • 317
  • 2
  • 7
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.

Kasper
  • 3,192
  • 1
  • 2
  • 19
Danple
  • 33
  • 5