Choosing the Right Backend
Interactive guide to help you select the optimal backend for your data and workflow.
Quick Decision Treeβ
Decision Factorsβ
1. Data Source Typeβ
This is usually determined for you - FilterMate detects your layer's provider automatically.
| Your Layer Is | Backend Used | Control |
|---|---|---|
| PostgreSQL/PostGIS connection | PostgreSQL (if psycopg2 installed) | βοΈ Install psycopg2 |
| Spatialite file (.sqlite) | Spatialite | β Automatic |
| Shapefile (.shp) | OGR | π‘ Can migrate |
| GeoPackage (.gpkg) | OGR or Spatialite | π‘ Can optimize |
| GeoJSON, KML, etc. | OGR | π‘ Can migrate |
2. Dataset Sizeβ
Most important factor for performance:
< 10,000 features β Any backend works fine
10,000 - 50,000 β Spatialite recommended
50,000 - 500,000 β PostgreSQL recommended
> 500,000 β PostgreSQL required
How to Check Feature Count:
- Right-click layer β Properties
- Information tab
- Look for "Feature count"
Or in FilterMate:
- Feature count displayed in layer info panel
3. Query Complexityβ
Simple Queries (either/or):
- Attribute filtering only
- Single spatial predicate
- Small buffer distances
β Any backend adequate
Complex Queries (multiple):
- Combined attribute + spatial filtering
- Multiple spatial predicates
- Large buffer distances (>1km`)
- Multi-layer joins
β PostgreSQL strongly recommended
4. Frequency of Useβ
Occasional Use (monthly):
- Current backend likely fine
- Performance less critical
Regular Use (weekly):
- Optimize with Spatialite or PostgreSQL
- Time savings add up
Daily Use (production workflows):
- Definitely use PostgreSQL
- 10-50Γ speedup = hours saved per week
Backend Comparison Matrixβ
Performanceβ
| Backend | 10K Features | 50K Features | 100K Features | 500K Features |
|---|---|---|---|---|
| PostgreSQL | 0.1s β‘ | 0.3s β‘ | 0.8s β‘ | 2.5s β‘ |
| Spatialite | 0.4s β | 4.5s β±οΈ | 18s β±οΈ | 120s β οΈ |
| OGR (GPKG) | 2.1s | 25s β±οΈ | 95s π | 600s π΄ |
| OGR (SHP) | 3.8s | 45s β οΈ | 180s π | 1200s π΄ |
Typical query times for spatial filter with 500m buffer
Featuresβ
| Feature | PostgreSQL | Spatialite | OGR |
|---|---|---|---|
| Spatial Indexing | GIST β | R-Tree β | Limited β οΈ |
| Materialized Views | β | Temp Tables β | Memory β οΈ |
| Server-Side Processing | β | Client β οΈ | Client β οΈ |
| Concurrent Access | β | Single User β οΈ | File Locking β οΈ |
| Max Dataset Size | Unlimited β | ~1M features β | ~100K β οΈ |
| Installation | Requires Server | Built-in β | Built-in β |
| psycopg2 Required | β | No | No |
Pros & Consβ
PostgreSQL Backendβ
Pros β :
- Fastest performance (10-50Γ vs OGR)
- Handles huge datasets (millions of features)
- Server-side spatial operations
- Automatic spatial indexes
- Production-ready
- Concurrent access
Cons β οΈ:
- Requires PostgreSQL server
- Needs psycopg2 Python package
- More complex setup
- Database management knowledge helpful
Best For:
- Large datasets (>50k` features)
- Production workflows
- Multi-user environments
- Regular/daily use
- Complex spatial queries
Spatialite Backendβ
Pros β :
- Good performance for medium datasets
- File-based (portable)
- No server required
- Built into QGIS
- Spatial indexes supported
- Easy to share
Cons β οΈ:
- Slower than PostgreSQL on large datasets
- Single-user (file locking)
- Memory limitations
- Not ideal for >100k` features
Best For:
- Medium datasets (10k-50k features)
- Portable projects
- Personal workflows
- No database server available
- Occasional use
OGR Backendβ
Pros β :
- Universal compatibility
- Works with any file format
- No dependencies
- Simple setup
- Built into QGIS
Cons β οΈ:
- Slowest performance
- Limited spatial optimization
- Memory-intensive
- Not recommended for >50k` features
- File format limitations
Best For:
- Small datasets (
<10kfeatures) - Quick one-off queries
- Legacy file formats
- Compatibility requirements
- Testing/prototyping
Migration Pathsβ
Shapefile β PostgreSQLβ
Why Migrate:
- 10-50Γ faster queries
- No file size limits
- Better data types
- Concurrent access
How:
1. Install PostgreSQL + PostGIS
2. QGIS: Database β DB Manager β Import Layer
3. Source: Your Shapefile
4. Destination: PostgreSQL database
5. Enable spatial index
6. Load PostgreSQL layer in QGIS
Estimated Time: 5-15 minutes Performance Gain: 10-50Γ
Shapefile β Spatialiteβ
Why Migrate:
- 3-5Γ faster than Shapefile
- Single-file portability
- Spatial indexing
- Better attribute names (no 10-char limit)
How:
1. Processing Toolbox β Vector general β Package Layers
2. Output: Spatialite (.sqlite)
3. Check "Save layer styles"
4. Load .sqlite file in QGIS
Estimated Time: 2-5 minutes Performance Gain: 3-5Γ
Spatialite β PostgreSQLβ
Why Migrate:
- 5-10Γ faster on large datasets
- Better scalability
- Multi-user support
How:
1. DB Manager β Import Layer
2. Source: Spatialite layer
3. Destination: PostgreSQL
4. Enable spatial index
Estimated Time: 5-10 minutes Performance Gain: 5-10Γ
Real-World Scenariosβ
Scenario 1: City Parcel Analysisβ
Data:
- 150,000 parcels (polygons)
- 5,000 roads (lines)
- Regular filtering (daily)
Recommendation: PostgreSQL β‘
Why:
- Large dataset
- Complex spatial queries
- Daily use = hours saved
Alternative: Spatialite would work but 20-30Γ slower
Scenario 2: Environmental Site Assessmentβ
Data:
- 2,500 sample points
- 50 protection zones (polygons)
- Occasional use (monthly)
Recommendation: Spatialite β or current format
Why:
- Small dataset
- Occasional use
- Setup overhead not justified
Alternative: OGR (Shapefile/GPKG) perfectly adequate
Scenario 3: Regional Transportation Networkβ
Data:
- 75,000 road segments
- 12,000 intersections
- Weekly analysis
Recommendation: PostgreSQL β‘
Why:
- Medium-large dataset
- Regular use
- Complex network analysis
Alternative: Spatialite possible but slower (10-30s vs 1-2s)
Scenario 4: Small Project Boundariesβ
Data:
- 150 project sites
- 500 reference features
- One-time export
Recommendation: Current format (OGR) β
Why:
- Tiny dataset
- One-time use
- Migration not worth effort
Installation Guidesβ
Install psycopg2 for PostgreSQL Backendβ
- Windows
- Linux
- macOS
# OSGeo4W Shell (Recommended)
# Open OSGeo4W Shell as Administrator
# Run:
py3_env
pip install psycopg2-binary
# Restart QGIS
# Ubuntu/Debian
sudo apt-get install python3-psycopg2
# Or via pip
pip3 install psycopg2-binary
# Using pip
/Applications/QGIS.app/Contents/MacOS/bin/pip3 install psycopg2-binary
Verification:
# QGIS Python Console
import psycopg2
print(psycopg2.__version__)
# Should print version number
Performance Checklistβ
Before complaining about slow performance, verify:
PostgreSQL Usersβ
- psycopg2 is installed
- Spatial index exists on geometry column
- VACUUM ANALYZE run recently
- Connection is local (not remote server)
- Database has adequate RAM
Spatialite Usersβ
- Using .sqlite file (not Shapefile)
- Spatial index created (usually automatic)
- Dataset is
<100k` features - File is on local drive (not network)
OGR Usersβ
- Dataset is
<50kfeatures (if not, migrate!) - Using GeoPackage instead of Shapefile
- File is on SSD (not HDD or network)
- Consider Spatialite or PostgreSQL migration
Quick Tipsβ
When PostgreSQL Isn't Availableβ
Option 1: Use Spatialite
# Convert to Spatialite for 3-5Γ speedup
Processing β Package Layers β Spatialite
Option 2: Pre-filter with QGIS
# Reduce dataset before FilterMate
Layer Properties β Source β Query Builder
Option 3: Split large files
# Divide by region/attribute
Processing β Split Vector Layer
Optimize Existing Backendβ
PostgreSQL:
-- Create missing spatial index
CREATE INDEX idx_geom ON table_name USING GIST(geom);
-- Update statistics
VACUUM ANALYZE table_name;
-- Check index usage
EXPLAIN ANALYZE SELECT ... ;
Spatialite:
-- Create spatial index
SELECT CreateSpatialIndex('table_name', 'geom');
-- Vacuum database
VACUUM;
Summaryβ
Backend Selection Logicβ
1. Check data source type (automatic detection)
2. Count features in dataset
3. Consider usage frequency
4. Choose backend:
> 50k features + regular use β PostgreSQL
10-50k features β Spatialite
< 10k features β Current format fine
Key Takeawaysβ
- PostgreSQL: Best performance, worth setup for >50k` features
- Spatialite: Good balance for 10-50k features, no server needed
- OGR: Universal compatibility but slowest, fine for
<10kfeatures - Migration: Easy and worth it for large/frequently-used datasets
Time Investment vs Savingsβ
| Migration | Setup Time | Time Saved Per Query | Break-Even Point |
|---|---|---|---|
| SHP β Spatialite | 5 min | 5-15 seconds | ~20 queries |
| SHP β PostgreSQL | 30 min | 30-120 seconds | ~15 queries |
| Spatialite β PostgreSQL | 15 min | 10-30 seconds | ~30 queries |
Need Help?β
- π PostgreSQL Setup
- π Spatialite Guide
- π OGR Backend
- π Configuration
- π¬ Ask on GitHub