New method - QGIS 3.36
QGIS 3.36 introduced a new Outline: Filled Line symbology that makes this task a lot easier.
Just configure the following settings under Filled Line:
- Set Stroke width to
x
units - Set Offset to
x / 2
units (half of stroke) - Use Join style Miter - ensures sharp corners are filled
It seems to run a lot faster than the old method.
Old method - QGIS <3.36
The best way to achieve that effect is to use a line pattern fill on an "inner buffer" instead of using hatched lines.
Try this expression in Geometry generator - set geometry type to Polygon/Multipolygon, and appropriate units; replace 4
in expression with the desired distance in those units:
difference($geometry,buffer($geometry,-4))
Set the generated polygon style to line pattern fill. Add another symbol below to display a simple line showing the boundaries.
Example:
However, if you plan to use thisthe old method on many polygons, or polygons with lots of vertices, thisit can be very slow to render.
I would recommend only rendering thishatched buffer in the old metohd at lower scales, as required. The most effective way to do this is duplicate the polygon layer, have one version of the layer show only the outlines, and the other version only the hatched buffer (but- but with layer scale visibility set to 1:500 maximum or as required).
This appears to be more effective than using @map_scale < 500
or similar as a data-defined override for 'Enable symbol layer'.
Additional features (both methods)
Text mask
To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer infor the text layerlabel, and set the generated hatch or filled line hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.3434+).
Line pattern alignment
If you want the line pattern to match up perfectly at the boundaries, for either method, change the renderer type from Single SymbolLine Pattern Fill > Alignment setting to Merged Features and wrap collect()
around the above expression for the "inner buffer" geometry generatorAlign Pattern to Map Extent.
For the outline (simple line), change that also to a geometry generator and use collect($geometry)
.