Filtering Basics
Learn how to filter vector data using QGIS expressions and attribute conditions in FilterMate's FILTERING tab.
Overviewβ
The FILTERING tab is your central hub for configuring all types of filters on vector layers. It provides three main filtering capabilities:
- Attribute Filtering - Filter features based on their attribute values using QGIS expressions
- Geometric Filtering - Filter based on spatial relationships (covered in Geometric Filtering)
- Buffer Operations - Add proximity zones for spatial analysis (covered in Buffer Operations)
This page focuses on attribute filtering using QGIS expressions.
All filtering operations are configured in the FILTERING tab at the top of the FilterMate panel. Don't confuse this with the EXPLORING tab, which works on the current active layer only.
FilterMate v2.3.0 automatically preserves existing filters when applying new ones. New filters are combined with the previous filter using the selected operator (AND by default). This prevents accidental filter loss when building complex queries step by step.
Example:
- Apply geometric filter β 150 features
- Apply attribute filter
"population" > 5000 - Result:
(geometric_filter) AND ("population" > 5000)β 23 features
Available Operators:
- AND (default): Intersection of filters
- OR: Union of filters
- AND NOT: Exclusion filter
FILTERING Tab Componentsβ
Layer Selectionβ
Before filtering, you must select one or more source layers:
Multi-selection of layers with geometry type indicators (point/line/polygon)
Features:
- Multi-selection: Check multiple layers to filter them simultaneously
- Geometry icons: Visual indication of layer type (π΅ Point, π’ Line, πͺ Polygon)
- Backend badges: Shows data source type (PostgreSQLβ‘, Spatialite, OGR)
- Auto Current Layer: Toggle button to automatically use QGIS's active layer
Toggle "Auto Current Layer" mode
When "Auto Current Layer" is enabled, FilterMate automatically selects whichever layer is active in QGIS, making quick filtering more convenient.
Layer Information Display:
Layer information: provider type, feature count, CRS
Shows critical layer details:
- Provider type (PostgreSQL, Spatialite, OGR)
- Total feature count
- Coordinate Reference System (CRS)
- Primary key field
Expression Builderβ
FilterMate uses QGIS expressions to filter features. These expressions are evaluated against each feature's attributes to determine which features should be included in the result.
Expression builder with free-text input
Key Features:
- Free-text expression input
- Real-time syntax validation
- Access to all QGIS expression functions
- Field name autocomplete
Field List:
The field list shows:
- All attribute fields from selected layer(s)
- Data type for each field
- Clicking a field inserts it into the expression
Expression Validationβ
FilterMate validates your expressions in real-time:
Valid Expression: Green checkmark (β) indicates valid expression
Invalid Expression: Red X (β) with detailed error message
Error messages show:
- Line and column of syntax error
- Description of the problem
- Suggestions for correction
Key Conceptsβ
- Expression: A formula that evaluates to
trueorfalsefor each feature - Attribute: A property of a feature (e.g.,
population,name,area) - Operator: Comparison symbols like
=,>,<,LIKE,IN - Function: Built-in operations like
upper(),length(),year()
Expression Syntaxβ
Basic Comparisonsβ
-- Numeric comparisons
population > 100000
area >= 50
year = 2024
-- Text comparisons (case-sensitive)
name = 'Paris'
status != 'inactive'
-- Text search (case-insensitive)
upper(name) LIKE '%CITY%'
name ILIKE 'paris'
Multiple Conditionsβ
-- AND: All conditions must be true
population > 50000 AND area < 100
-- OR: At least one condition must be true
type = 'city' OR type = 'town'
-- Complex combinations
(population > 100000 OR capital = 'yes') AND country = 'France'
Working with NULL Valuesβ
-- Check for NULL
name IS NULL
description IS NOT NULL
-- Safe NULL handling
COALESCE(population, 0) > 0
Common Filtering Patternsβ
Text Filteringβ
Exact Matchβ
-- Case-sensitive
city = 'Lyon'
-- Case-insensitive
upper(city) = 'LYON'
Pattern Matchingβ
-- Starts with
name LIKE 'Saint%'
-- Contains (case-insensitive)
name ILIKE '%sur-mer%'
-- Ends with
name LIKE '%ville'
-- Multiple patterns
name LIKE 'Paris%' OR name LIKE 'Lyon%'
Multiple Valuesβ
-- IN operator
status IN ('active', 'pending', 'review')
-- NOT IN
country NOT IN ('France', 'Germany')
Numeric Filteringβ
Range Queriesβ
-- Between
population BETWEEN 10000 AND 50000
-- Equivalent to
population >= 10000 AND population <= 50000
-- Outside range
population NOT BETWEEN 10000 AND 50000
Arithmetic Operationsβ
-- Calculated values
density > population / area
-- Percentage
(sales / target) * 100 > 80
-- Round values
round(area, 2) = 123.45
Date Filteringβ
Basic Date Comparisonsβ
-- Specific date
date = '2024-01-15'
-- Date range
date >= '2024-01-01' AND date < '2024-02-01'
-- Year
year(date) = 2024
-- Month
month(date) = 6
Relative Datesβ
-- Recent records
date >= now() - interval '7 days'
-- Last year
year(date) = year(now()) - 1
-- Current month
year(date) = year(now()) AND month(date) = month(now())
String Functionsβ
Case Conversionβ
-- Uppercase
upper(name) = 'PARIS'
-- Lowercase
lower(name) = 'paris'
String Operationsβ
-- Concatenation
name || ' ' || country = 'Paris France'
-- Length
length(name) > 10
-- Substring
substr(code, 1, 2) = 'FR'
-- Trim whitespace
trim(name) = 'Lyon'
Pattern Matchingβ
-- Regular expression
regexp_match(name, '^[A-Z]{2}[0-9]{3}$')
-- Replace
replace(name, 'Saint', 'St') = 'St-Denis'
Expression Flowβ
FilterMate processes expressions in several steps:
Key Steps:
- Expression Input: Type or build expression in FILTERING tab
- Validation: Real-time check for syntax errors (β or β)
- Apply Filter: Click FILTER button to execute
- Processing: Backend (PostgreSQL/Spatialite/OGR) evaluates expression
- Results: Filtered features displayed, feature count updated
- History: Filter saved to history for reuse
Step-by-Step Filtering Workflowβ
Complete Example: Filter Cities by Populationβ
Scenario: Find all cities with population greater than 100,000
Step 1 - Open FILTERING Tab
Switch to FILTERING tab in FilterMate panel
Step 2 - Select Source Layer
- Check the "COMMUNE" layer in the layer selector
- Verify layer information is displayed (feature count, CRS)
Step 3 - Enter Expression
Type expression: population > 100000
Step 4 - Verify Field List
Check available fields: population (Integer64), name (String), area (Double)
You can click fields to insert them into the expression.
Step 5 - Validate Expression
Green checkmark (β) confirms valid expression
The validator shows:
- β Syntax is correct
- Preview of estimated feature count (optional, if enabled)
Step 6 - Apply Filter
Click FILTER button β Progress bar shows during processing
Step 7 - View Results
Map shows filtered features, feature count updated: 247 cities displayed
Step 8 - Access History
Filter automatically saved to history for future reuse
Testing Expressionsβ
Real-Time Validationβ
FilterMate validates expressions as you type:
- Syntax Check: Identifies missing operators, unbalanced parentheses, unknown functions
- Field Verification: Checks that field names exist in the selected layer(s)
- Type Compatibility: Warns about type mismatches (e.g., comparing text to numbers)
Visual Feedback:
- β Green checkmark: Expression is valid and ready to apply
- β Red X: Syntax error detected, see error message
- β οΈ Orange warning: Expression valid but may have performance issues
Testing Against Sample Featuresβ
For complex expressions, you can test against real data:
- Enable "Expression Preview" in Configuration tab
- Expression builder shows how many features match
- Adjust expression based on preview results
For very large layers (&>;100k features), preview might be disabled for performance. In this case, apply the filter and check the result count.
Common Errorsβ
Syntax Errorsβ
-- β Wrong: Missing quotes around text
name = Paris
-- β
Correct: Text in quotes
name = 'Paris'
-- β Wrong: Unbalanced parentheses
(population > 1000 AND area < 50
-- β
Correct: Balanced parentheses
(population > 1000 AND area < 50)
FilterMate shows: "Syntax error at column 11: expected ')'"
Type Mismatchesβ
-- β Wrong: Comparing text field to number
name > 100
-- β
Correct: Convert to number if needed
to_int(name) > 100
-- β Wrong: Using numeric operator on text
city_code + 100
-- β
Correct: Concatenate as text
city_code || '100'
FilterMate shows: "Type error: cannot compare String and Integer"
NULL Handlingβ
-- β Wrong: NULL comparisons always return false
population = NULL
-- β
Correct: Use IS NULL
population IS NULL
-- β Wrong: NULL in arithmetic breaks calculation
population + income > 50000
-- β
Correct: Handle NULL explicitly
COALESCE(population, 0) + COALESCE(income, 0) > 50000
FilterMate shows: "Warning: Expression may return unexpected results with NULL values"
Field Name Errorsβ
-- β Wrong: Field doesn't exist
popilation > 1000 -- Typo!
-- β
Correct: Use field list to avoid typos
population > 1000
-- β Wrong: Field name with spaces, no quotes
Population 2024 > 1000
-- β
Correct: Quote field names with spaces
"Population 2024" > 1000
FilterMate shows: "Field 'popilation' not found in layer"
Debugging Tipsβ
-
Start Simple: Build complex expressions incrementally
-- Step 1: Test basic comparison
population > 100000
-- Step 2: Add second condition
population > 100000 AND area > 50
-- Step 3: Add third condition
population > 100000 AND area > 50 AND status = 'active' -
Use Field List: Click fields to insert them correctly
- Avoids typos
- Handles special characters automatically
- Adds proper quotes for field names with spaces
-
Check Data Types: View field list to see data types
- Integer64: Use numeric comparisons (
>,<,=) - String: Use text functions (
LIKE,upper(),||) - Date: Use date functions (
year(),month(),age())
- Integer64: Use numeric comparisons (
-
Test on Small Subset First:
- Add
LIMITclause for testing:population > 100000 LIMIT 10 - Remove LIMIT once expression is validated
- Add
Best Practicesβ
Performance Tipsβ
-
Index-Friendly Expressions
-- β Good: Uses index
population > 100000
-- β Slow: Prevents index use
population * 2 > 200000 -
Avoid Complex Functions on Large Datasets
-- β Fast: Simple comparison
year = 2024
-- β οΈ Slower: Function call per feature
year(date) = 2024 -
Filter Early
- Apply simple filters first
- Use geometric filters after attribute filters
- Combine conditions efficiently
Readabilityβ
-
Use Clear Column Names
-- β Clear
"Population 2024" > 100000
-- β Unclear
"col_23" > 100000 -
Format Complex Expressions
-- Multi-line for readability
(
status = 'active'
AND population > 50000
)
OR (
status = 'pending'
AND priority = 'high'
) -
Comment Complex Logic
-- Large cities or regional capitals
population > 100000 OR capital = 'regional'
Practical Examplesβ
Urban Planningβ
-- High-density residential areas
zone = 'residential' AND density > 100 AND year_built >= 2000
-- Mixed-use development opportunities
(zone = 'commercial' OR zone = 'mixed') AND available_area > 1000
Environmental Analysisβ
-- Protected natural areas above 50 hectares
protection_status = 'protected' AND area >= 500000 AND habitat_type IN ('forest', 'wetland')
-- Water bodies with quality issues
water_type IN ('river', 'lake') AND quality_index < 60
Transportationβ
-- Major roads needing maintenance
road_class IN ('highway', 'major') AND condition = 'poor' AND traffic_count > 10000
-- Transit stops in underserved areas
service_frequency < 4 AND population_nearby > 5000
Related Topicsβ
- Geometric Filtering - Spatial predicates and reference layers in FILTERING tab
- Buffer Operations - Add proximity zones in FILTERING tab
- Interface Overview - Complete FILTERING tab component guide
- Filter History - Manage and reuse saved filters
Next Stepsβ
Now that you understand attribute filtering in the FILTERING tab, learn about:
- Geometric Filtering - Add spatial predicates to find features based on location
- Buffer Operations - Create proximity zones for spatial analysis
- Export Features - Save your filtered results to various formats
Complete Workflow: See Quick Start Guide for a step-by-step filtering example.