How fungobungaloid/georefio works
Purpose and Runtime
Magic Georeferencer is a QGIS 3.22+ Python plugin that automatically georeferences an input raster by matching it to the current map extent/basemap. It runs inside QGIS’s bundled Python environment, using PyTorch/MatchAnything with CUDA when available and CPU fallback.
Plugin bootstrap and QGIS integration are centered on:
• magic_georeferencer/__init__.py
• magic_georeferencer/magic_georeferencer.py
• magic_georeferencer/metadata.txt
User Entry and UI Orchestration
The toolbar/plugin action opens the main workflow: choose an ungeoreferenced image, use the current QGIS canvas location, choose basemap and matching settings, execute matching, then review or accept generated control points.
Primary UI boundaries:
• magic_georeferencer/ui/main_dialog.py
• magic_georeferencer/ui/settings_dialog.py
• magic_georeferencer/ui/confidence_viewer.py
Supporting dialogs expose batch execution, progress, and alignment interaction rather than embedding inference logic:
• magic_georeferencer/ui/batch_dialog.py
• magic_georeferencer/ui/progress_dialog.py
• magic_georeferencer/ui/alignment_dialog.py
Georeferencing Pipeline Coordinator
georeferencer.py is the likely application-service boundary joining QGIS state, raster input, tile imagery, feature matches, and output GCPs. It controls the principal single-image flow:
1. Capture image and target map/canvas context.
2. Obtain reference basemap imagery for that extent.
3. Run model-backed feature matching.
4. Filter matches and convert them into spatial GCPs.
5. Return results for confidence review and QGIS georeferencing.
Core orchestration paths:
• magic_georeferencer/core/georeferencer.py
• magic_georeferencer/core/matcher.py
• magic_georeferencer/core/gcp_generator.py
Reference Imagery Acquisition Boundary
Basemap acquisition is isolated from model inference. Tile source definitions select providers such as OSM and Esri imagery; the fetcher assembles map tiles into a matching reference image, likely in Web Mercator, while QGIS supplies project/canvas CRS context.
Paths:
• magic_georeferencer/core/tile_fetcher.py
• magic_georeferencer/config/tile_sources.json
• magic_georeferencer/config/default_settings.json
External dependencies are internet-accessible tile services, including OpenStreetMap and optional Esri World Imagery. No imagery is repository-hosted.
AI Model Lifecycle and Matching
Model lifecycle is separated from inference execution. The manager downloads/caches roughly 400 MB of MatchAnything weights from Hugging Face, chooses CUDA versus CPU, and makes the model available to matching. The inference adapter encapsulates the vendored MatchAnything interface; matcher applies it to source and reference images, potentially across progressive scales.
Paths:
• magic_georeferencer/core/model_manager.py
• magic_georeferencer/core/matcher.py
• magic_georeferencer/matchanything/inference.py
Material external services/runtimes: Hugging Face Hub, PyTorch, torchvision/transformers, NVIDIA CUDA, and model weights cached beneath magic_georeferencer/weights/.
Match-to-GCP Transformation and Commit Boundary
Raw image-coordinate correspondences must become source pixel coordinates plus geographic/map coordinates. gcp_generator.py is the transformation boundary that validates/filter matches and produces GCP candidates suitable for QGIS georeferencing. The confidence UI gives the user a review gate before results are committed, preserving manual control over automated output.
Paths:
• magic_georeferencer/core/gcp_generator.py
• magic_georeferencer/core/georeferencer.py
• magic_georeferencer/ui/confidence_viewer.py
Batch and Dependency Operations
Batch processing reuses the core pipeline for multiple images, while dependency installation handles Python packages unavailable in the QGIS environment. These are operational extensions rather than alternate matching architectures.
Paths:
• magic_georeferencer/core/batch_processor.py
• magic_georeferencer/dependency_installer.py
• magic_georeferencer/requirements.txt
Main entry points: georeferencer.py Pipeline coordinator · main_dialog.py Main workflow · model_manager.py Model manager · magic_georeferencer.py Plugin controller
Components 21
QGIS Plugin
- Plugin bootstrap · Registers the plugin action and QGIS integration.
magic_georeferencer/__init__.py - Plugin controller
magic_georeferencer/magic_georeferencer.py - Plugin metadata
magic_georeferencer/metadata.txt - Dependency installer · Installs Python packages missing from QGIS Python.
magic_georeferencer/dependency_installer.py - Python dependencies · Includes PyTorch and model dependencies.
magic_georeferencer/requirements.txt
Workflow UI
- Main workflow · Collects raster, canvas, basemap, and matching choices.
magic_georeferencer/ui/main_dialog.py - Matching settings
magic_georeferencer/ui/settings_dialog.py - Confidence review · User accepts or adjusts generated control points.
magic_georeferencer/ui/confidence_viewer.py - Batch workflow
magic_georeferencer/ui/batch_dialog.py - Progress and alignment
magic_georeferencer/ui/progress_dialog.py
Georeferencing Pipeline
- Pipeline coordinator · Coordinates canvas context, imagery, matching, and GCP output.
magic_georeferencer/core/georeferencer.py - Batch processor · Reuses the single-image pipeline for multiple rasters.
magic_georeferencer/core/batch_processor.py - GCP generator · Filters correspondences and converts them into spatial GCP candidates.
magic_georeferencer/core/gcp_generator.py
AI Matching
- Feature matcher · Runs image correspondence matching, potentially across progressive scales.
magic_georeferencer/core/matcher.py - Model manager · Selects CUDA or CPU and downloads or loads cached weights.
magic_georeferencer/core/model_manager.py - MatchAnything adapter
magic_georeferencer/matchanything/inference.py - Model weights cache · Cached MatchAnything weights.
magic_georeferencer/weights/.gitkeep - Hugging Face Hub
Reference Imagery
- Tile fetcher · Builds a reference image for the QGIS map extent.
magic_georeferencer/core/tile_fetcher.py - Tile providers · Selects OSM or Esri tile sources.
magic_georeferencer/config/tile_sources.json - Internet tile services · OpenStreetMap and optional Esri World Imagery.
Connections 21
- Plugin bootstrap → Plugin controller: loads
- Plugin metadata → Plugin bootstrap: declares plugin
- Plugin controller → Main workflow: opens
- Main workflow → Matching settings: configures
- Main workflow → Pipeline coordinator: submits image and canvas context
- Pipeline coordinator → Tile fetcher: requests reference extent
- Tile fetcher → Tile providers: uses
- Tile providers → Internet tile services: selects
- Pipeline coordinator → Feature matcher: matches source to reference
- Model manager → Feature matcher: provides loaded model
- Model manager → MatchAnything adapter: initializes
- Feature matcher → MatchAnything adapter: invokes inference
- Model manager → Model weights cache: loads or caches
- Hugging Face Hub → Model manager: downloads weights
- Pipeline coordinator → GCP generator: converts filtered matches
- GCP generator → Confidence review: returns GCP candidates
- Confidence review → Plugin controller: accepts for QGIS georeferencing
- Batch workflow → Batch processor: starts batch
- Batch processor → Pipeline coordinator: reuses pipeline
- Main workflow → Progress and alignment: shows execution and alignment
- Dependency installer → Python dependencies: installs