# Symbolise polygon outline where it doesn't coincide with other feature using geometry generator in QGIS?

I struggled a bit with the `Geometry generator`

as @GSienko. For intersection part you can also use built-in function `aggregate`

. Also I used `segment_to_lines`

function which convert polygons to lines.

```
difference(
segments_to_lines($geometry),
aggregate(
layer:= 'line',
aggregate:='collect',
expression:= $geometry,
filter:=intersects($geometry, geometry(@parent))
)
)
```

or

```
difference(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
)
```

If you have some polygon "unrelated" to lines you can add `if`

condition for intersection. If layers are in intersection, then difference is applied for symbology, otherwise whole geometry is applied.

```
if(
intersects(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
),
difference(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
),
segments_to_lines($geometry)
)
```

*edit*: Using line generator this way has a weak point - you have to handle legend symbol, because it render line thru the polygon (not as a border). However you can still duplicate the layer, set simple fill and use it for legend.

Try using refFunction plugin within geometry generator.

Assumption. 2 layers - one lines as line, and polygons as polygon.

Style polygon like that:

```
difference(exterior_ring( $geometry ),geom_from_wkt(geomintersects('line','$geometry')))
```

geomintersect will make spatial query between polygon layer and line layer, and return geometry of intersection of two of them, in ours case, two border of polygons. Next step is to make difference with border of polygon. I don't know if you will have holes inside or not, then exterior_ring() will return only exterior border.

Final result:

The limitation - geomintersect will check intersection only for one polygon. I manage that limitation by make polygons layer to one big multipolygon, for example by virtual layer for border styling.

How about adding a white line under the blue line in the other layer, that has the same width as the red line? If you place the blue line above the polygon layer the white line will obscure the red line.

This of course assumes that you have a white background like in your example, and that you are ok with some of the crosshashes also being obscured.

This is my quick test result:

Settings for blue line: