Skip to main content
Updated with QGIS 3.36 info, deleted old method of aligning hatch
Source Link
she_weeds
  • 13k
  • 1
  • 32
  • 64

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

enter image description here

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:

enter image description here


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+).

enter image description here


 

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).enter image description here

enter image description here enter image description hereenter image description here

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:

enter image description here


However, if you plan to use this on many polygons, or polygons with lots of vertices, this can be very slow to render.

I would recommend only rendering this buffer 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 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'.


To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer in the text layer and set the generated hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.34).

enter image description here


 

If you want the line pattern to match up perfectly at the boundaries, change the renderer type from Single Symbol to Merged Features and wrap collect() around the above expression for the "inner buffer" geometry generator.

For the outline (simple line), change that also to a geometry generator and use collect($geometry).

enter image description here enter image description here

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

enter image description here

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:

enter image description here


However, if you plan to use the old method on many polygons, or polygons with lots of vertices, it can be very slow to render.

I would recommend only rendering hatched 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 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 for the label, 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.34+).

enter image description here

Line pattern alignment

If you want the line pattern to match up perfectly at the boundaries, for either method, change the Line Pattern Fill > Alignment setting to Align Pattern to Map Extent.

enter image description here

enter image description here

added extra section about aligning hatch lines
Source Link
she_weeds
  • 13k
  • 1
  • 32
  • 64

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:

enter image description here


However, if you plan to use this on many polygons, or polygons with lots of vertices, this can be very slow to render.

I would recommend only rendering this buffer 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 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'.


To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer in the text layer and set the generated hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.34).

enter image description here


If you want the line pattern to match up perfectly at the boundaries, change the renderer type from Single Symbol to Merged Features and wrap collect() around the above expression for the "inner buffer" geometry generator.

For the outline (simple line), change that also to a geometry generator and use collect($geometry).

enter image description here enter image description here

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:

enter image description here


However, if you plan to use this on many polygons, or polygons with lots of vertices, this can be very slow to render.

I would recommend only rendering this buffer 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 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'.


To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer in the text layer and set the generated hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.34).

enter image description here

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:

enter image description here


However, if you plan to use this on many polygons, or polygons with lots of vertices, this can be very slow to render.

I would recommend only rendering this buffer 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 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'.


To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer in the text layer and set the generated hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.34).

enter image description here


If you want the line pattern to match up perfectly at the boundaries, change the renderer type from Single Symbol to Merged Features and wrap collect() around the above expression for the "inner buffer" geometry generator.

For the outline (simple line), change that also to a geometry generator and use collect($geometry).

enter image description here enter image description here

Source Link
she_weeds
  • 13k
  • 1
  • 32
  • 64

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:

enter image description here


However, if you plan to use this on many polygons, or polygons with lots of vertices, this can be very slow to render.

I would recommend only rendering this buffer 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 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'.


To also achieve the blanked-out effect behind text as in '3000 ASFC' in your image, use a mask buffer in the text layer and set the generated hatch as the symbol to mask (requires more recent version of QGIS, does not work in 3.28 but does in 3.34).

enter image description here