4

I often deal with polygons that delineate an area of interest. When visualizing them, I have the problem that:

  1. using a fill "masks" the content of the area of interest, e.g. a background raster layer
  2. using an outline isn't clear/unambigous in showing what's inside and outside, especially with complex geometries

I presume this is a common dilemma, so I was wondering:

Is there a convenient function to do an "inverse fill" in QGIS?

Materializing the symmetrical difference and using that for visualization is a solution (that is what I did for below screenshots), but isn't really convenient, given that now I have to use different files for calculations and visualization (and calculating the symmetrical difference takes surprisingly long).

To show what I mean, this is what I have:

Polygons, visualized with outline. This is ambigous: Do i mean the forested (dark) or unforested (brighter) area? polygons with outline

With a fill, it is clear which area is meant, but now my area of interest is "covered" (to some extent, could be less with transparency and such, but then the highlight isn't as powerful): polygons with fill

With an "inverse fill", I have the desired effect: The area of interest is fully clear, everything else is masked. polygons with inverse fill

Honeybear
  • 2,454
  • 1
  • 15
  • 25

3 Answers3

7

In the style tab, instead of selecting unique symbol

enter image description here

select inverted polygons

enter image description here

You can also apply a partial opacity to it (or a pattern fill, if desired), so the features underneath are also visible.

enter image description here

jpinilla
  • 3,230
  • 1
  • 12
  • 24
4

I consider this circumstantial and not convenient, but it is a way to achieve it (used for the last screenshot), so for completeness I'll post it here as an answer:

  1. Create a new polygon "vis_area" that encompasses the whole area to visualize (a single filled rectangle)
  2. Calculate the symmetrical difference between vis_area and area_of_interest.
  3. Use the result.shp for visualization with a fill.
Honeybear
  • 2,454
  • 1
  • 15
  • 25
3

The answer by @JesúsPinilla is the way to go. However, just to show another way how to do it - including the possibility to create this either just for visualization without creating a new layer (using Geometry generator), or creating it as actual geometries on a new layer with Geometry by expression (see here for details about both options).

Create an expression that:

  1. Collects all the polygons
  2. Creates a bounding box around the extent of the layer
  3. Buffers this bounding box
  4. Creates the difference: extraxts the polygons (no. 1) from the buffered bounding box (no. 3)

Use this expression (change the buffer size - here: 4000 - at the end of line 2 as you like):

difference (
    buffer (layer_property(@layer,'extent'), 4000),
    collect($geometry)
)

The solution, used with Geometry generator to create the area with blue line fill pattern from the initial red polygons: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208