QGIS provides two methods for creating geometries using expressions: Geometry Generator (introduced in QGIS 2.14) and Geometry by Expression (introduced in QGIS 3.0). Both leverage QGIS's expression engine but serve fundamentally different purposes. This tutorial clarifies their differences and appropriate use cases.
Geometry Generator: Dynamic Visualization
What It Does
Creates temporary geometries for on-the-fly visualization within layer symbology. Does not modify underlying data.
How to Use
- Open Layer Styling Panel
- Add a new symbol layer (+)
- Set Symbol layer type to Geometry generator
- Select Output geometry type (point, line, or polygon)
- Enter your expression in the Geometry generator field
- Optional: Use Expression builder (ε) for assistance
Example: buffer($geometry, 100)
creates a 100m buffer around features.
Key Characteristics
- Real-time visualization: Immediate visual feedback during expression editing
- No data modification: Original geometries remain unchanged
- Limited scope: Supports layer-specific variables like
@layer
- Rendering only: Output exists only in the map canvas, not as actual features
- Geometry type must match: Select polygon type for buffers, point type for centroids, etc.
Best for: Visual experiments, dynamic styling, learning geometry functions.
Geometry by Expression: Permanent Geometry Creation
What It Does
Generates new persistent layers with actual features based on expressions.
How to Use
- Processing > Toolbox
- Search "Geometry by expression"
- Select Input layer
- Set Output geometry type
- Enter expression in Geometry expression field
- Execute to create new layer
Example: centroid($geometry)
generates centroids as a new point layer.
Key Characteristics
- Persistent output: Creates new layers usable in geoprocessing workflows
- Export capability: Results can be saved as permanent files
- No real-time preview: Requires complete reprocessing after changes
- Function limitations: Doesn't support
@layer
variables or certain aggregates - Geometry type flexibility: Automatically handles geometry conversions
Best for: Creating analysis-ready datasets, geoprocessing workflows, data export.
Feature Comparison
Functionality | Geometry Generator | Geometry by Expression |
---|---|---|
Output permanence | Temporary visualization | Permanent layer creation |
Real-time feedback | Supported | Not supported |
Variables support | Full (@layer compatible) | Limited |
Processing chain integration | Not applicable | Fully supported |
Data modification | None (original preserved) | Creates new features |
Computational efficiency | Dynamic (low resource) | Full processing required |
When to Use Which Tool
Choose Geometry Generator When:
- Testing geometry expressions interactively
- Creating temporary visual effects (e.g., buffers, halos)
- Developing styles with dynamic components
- Learning geometry function behavior
Choose Geometry by Expression When:
- Producing datasets for analysis or sharing
- Creating permanent input for geoprocessing workflows
- Generating derived data products
- Modifying geometries with complex transformations
Conclusion
Both tools enable geometry creation through QGIS expressions but address different needs:
- Geometry Generator serves as a visualization sandbox for interactive exploration
- Geometry by Expression creates permanent outputs for data production
For optimal workflow:
- Use Geometry Generator to prototype and validate expressions
- Switch to Geometry by Expression when results require persistent storage and analysis
- Remember that layer-specific expressions containing
@layer
must be modified when transitioning between tools