Buffering a layer manually in QGIS means navigating through the Processing Toolbox, setting parameters, and then loading the output. This script does all of that in one run from the Python Console.
What it does
The buffer_active_layer.py script takes whatever layer is currently selected (active) in the Layers panel and expands every feature outward by a fixed radius in metres. The result is saved as a GeoJSON alongside the input file and automatically loaded into your QGIS project.
This is useful for:
- Defining a zone of influence around trees (e.g. canopy spread radius)
- Adding a setback distance around polygon boundaries
- Creating proximity rings around survey points
What you need
- QGIS 3.28 or newer
- A point or polygon layer loaded into QGIS and set as the active layer
- The
buffer_active_layer.pyscript from the GIS Utilities Pack
Steps
- Load your vector layer into QGIS and click it in the Layers panel to make it active.
- Open Plugins → Python Console → Show Editor.
- Paste the script contents into the editor.
- Find the line at the bottom that calls the buffer function and set
buffer_radius(in metres) to what you need — for example,buffer_radius=1.5for a 1.5 m buffer around each tree. - Click Run.
The output file {input_name}_buffered.geojson is saved in the same directory as the input and added to the project immediately.
Configurable parameters
| Parameter | Default | What it changes |
|---|---|---|
buffer_radius | set at call site | Buffer distance in metres |
LOG_PATH | ~/Documents/QGIS_Projects/buffer_log.txt | Where the run log is written |
Output
A new GeoJSON file with all features buffered outward. The geometry type changes to polygon (even for point inputs — each point becomes a circle). The original attributes are preserved.
Get the script
buffer_active_layer.py is part of the GIS Utilities Pack — four everyday QGIS automation scripts for $25 USD.