# fungobungaloid/georefio architecture

> Architecture diagram of the GitHub repository fungobungaloid/georefio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fungobungaloid/georefio
- Repository: https://github.com/fungobungaloid/georefio

## Overview

#### 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: [`magic_georeferencer/core/georeferencer.py`](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/georeferencer.py) (Pipeline coordinator), [`magic_georeferencer/ui/main_dialog.py`](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/main_dialog.py) (Main workflow), [`magic_georeferencer/core/model_manager.py`](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/model_manager.py) (Model manager), [`magic_georeferencer/magic_georeferencer.py`](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/magic_georeferencer.py) (Plugin controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_qgis["QGIS Plugin"]
  node_qgis_bootstrap["Plugin bootstrap<br/>QGIS entrypoint<br/>[__init__.py]"]
  node_plugin_controller["Plugin controller<br/>QGIS integration"]
  node_metadata["Plugin metadata<br/>QGIS manifest<br/>[metadata.txt]"]
  node_dependency_installer["Dependency installer<br/>environment setup"]
  node_requirements["Python dependencies<br/>dependency manifest<br/>[requirements.txt]"]
end

subgraph group_ui["Workflow UI"]
  node_main_dialog["Main workflow<br/>dialog<br/>[main_dialog.py]"]
  node_settings_dialog["Matching settings<br/>dialog<br/>[settings_dialog.py]"]
  node_confidence_viewer["Confidence review<br/>review gate"]
  node_batch_dialog["Batch workflow<br/>dialog<br/>[batch_dialog.py]"]
  node_progress_alignment["Progress and alignment<br/>interaction dialogs<br/>[progress_dialog.py]"]
end

subgraph group_pipeline["Georeferencing Pipeline"]
  node_georeferencer{{"Pipeline coordinator<br/>application service<br/>[georeferencer.py]"}}
  node_batch_processor["Batch processor<br/>batch service<br/>[batch_processor.py]"]
  node_gcp_generator["GCP generator<br/>spatial transformation<br/>[gcp_generator.py]"]
end

subgraph group_ai["AI Matching"]
  node_matcher{{"Feature matcher<br/>matching service<br/>[matcher.py]"}}
  node_model_manager["Model manager<br/>model lifecycle<br/>[model_manager.py]"]
  node_matchanything["MatchAnything adapter<br/>inference adapter<br/>[inference.py]"]
  node_model_cache[("Model weights cache<br/>local model store<br/>[.gitkeep]")]
  node_huggingface(("Hugging Face Hub<br/>external model service"))
end

subgraph group_reference["Reference Imagery"]
  node_tile_fetcher["Tile fetcher<br/>basemap assembler<br/>[tile_fetcher.py]"]
  node_tile_sources["Tile providers<br/>source definitions<br/>[tile_sources.json]"]
  node_tile_services(("Internet tile services<br/>external imagery API"))
end

node_qgis_bootstrap -->|"loads"| node_plugin_controller
node_metadata -.->|"declares plugin"| node_qgis_bootstrap
node_plugin_controller -->|"opens"| node_main_dialog
node_main_dialog -->|"configures"| node_settings_dialog
node_main_dialog -->|"submits image and canvas context"| node_georeferencer
node_georeferencer -->|"requests reference extent"| node_tile_fetcher
node_tile_fetcher -->|"uses"| node_tile_sources
node_tile_sources -->|"selects"| node_tile_services
node_georeferencer -->|"matches source to reference"| node_matcher
node_model_manager -->|"provides loaded model"| node_matcher
node_model_manager -->|"initializes"| node_matchanything
node_matcher -->|"invokes inference"| node_matchanything
node_model_manager -->|"loads or caches"| node_model_cache
node_huggingface -.->|"downloads weights"| node_model_manager
node_georeferencer -->|"converts filtered matches"| node_gcp_generator
node_gcp_generator -->|"returns GCP candidates"| node_confidence_viewer
node_confidence_viewer -->|"accepts for QGIS georeferencing"| node_plugin_controller
node_batch_dialog -->|"starts batch"| node_batch_processor
node_batch_processor -->|"reuses pipeline"| node_georeferencer
node_main_dialog -.->|"shows execution and alignment"| node_progress_alignment
node_dependency_installer -->|"installs"| node_requirements

click node_qgis_bootstrap "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/__init__.py"
click node_plugin_controller "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/magic_georeferencer.py"
click node_metadata "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/metadata.txt"
click node_dependency_installer "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/dependency_installer.py"
click node_requirements "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/requirements.txt"
click node_main_dialog "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/main_dialog.py"
click node_settings_dialog "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/settings_dialog.py"
click node_confidence_viewer "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/confidence_viewer.py"
click node_batch_dialog "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/batch_dialog.py"
click node_progress_alignment "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/progress_dialog.py"
click node_georeferencer "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/georeferencer.py"
click node_batch_processor "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/batch_processor.py"
click node_gcp_generator "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/gcp_generator.py"
click node_tile_fetcher "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/tile_fetcher.py"
click node_tile_sources "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/config/tile_sources.json"
click node_matcher "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/matcher.py"
click node_model_manager "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/model_manager.py"
click node_matchanything "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/matchanything/inference.py"
click node_model_cache "https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/weights/.gitkeep"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_qgis_bootstrap,node_plugin_controller,node_metadata,node_dependency_installer,node_requirements toneBlue
class node_main_dialog,node_settings_dialog,node_confidence_viewer,node_batch_dialog,node_progress_alignment toneAmber
class node_georeferencer,node_batch_processor,node_gcp_generator toneMint
class node_matcher,node_model_manager,node_matchanything,node_model_cache,node_huggingface toneRose
class node_tile_fetcher,node_tile_sources,node_tile_services toneIndigo
```

## Components

### QGIS Plugin

- [Plugin bootstrap](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/__init__.py): QGIS entrypoint · Registers the plugin action and QGIS integration. · `magic_georeferencer/__init__.py`
- [Plugin controller](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/magic_georeferencer.py): QGIS integration · `magic_georeferencer/magic_georeferencer.py`
- [Plugin metadata](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/metadata.txt): QGIS manifest · `magic_georeferencer/metadata.txt`
- [Dependency installer](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/dependency_installer.py): environment setup · Installs Python packages missing from QGIS Python. · `magic_georeferencer/dependency_installer.py`
- [Python dependencies](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/requirements.txt): dependency manifest · Includes PyTorch and model dependencies. · `magic_georeferencer/requirements.txt`

### Workflow UI

- [Main workflow](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/main_dialog.py): dialog · Collects raster, canvas, basemap, and matching choices. · `magic_georeferencer/ui/main_dialog.py`
- [Matching settings](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/settings_dialog.py): dialog · `magic_georeferencer/ui/settings_dialog.py`
- [Confidence review](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/confidence_viewer.py): review gate · User accepts or adjusts generated control points. · `magic_georeferencer/ui/confidence_viewer.py`
- [Batch workflow](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/batch_dialog.py): dialog · `magic_georeferencer/ui/batch_dialog.py`
- [Progress and alignment](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/ui/progress_dialog.py): interaction dialogs · `magic_georeferencer/ui/progress_dialog.py`

### Georeferencing Pipeline

- [Pipeline coordinator](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/georeferencer.py): application service · Coordinates canvas context, imagery, matching, and GCP output. · `magic_georeferencer/core/georeferencer.py`
- [Batch processor](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/batch_processor.py): batch service · Reuses the single-image pipeline for multiple rasters. · `magic_georeferencer/core/batch_processor.py`
- [GCP generator](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/gcp_generator.py): spatial transformation · Filters correspondences and converts them into spatial GCP candidates. · `magic_georeferencer/core/gcp_generator.py`

### AI Matching

- [Feature matcher](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/matcher.py): matching service · Runs image correspondence matching, potentially across progressive scales. · `magic_georeferencer/core/matcher.py`
- [Model manager](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/model_manager.py): model lifecycle · Selects CUDA or CPU and downloads or loads cached weights. · `magic_georeferencer/core/model_manager.py`
- [MatchAnything adapter](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/matchanything/inference.py): inference adapter · `magic_georeferencer/matchanything/inference.py`
- [Model weights cache](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/weights/.gitkeep): local model store · Cached MatchAnything weights. · `magic_georeferencer/weights/.gitkeep`
- **Hugging Face Hub**: external model service

### Reference Imagery

- [Tile fetcher](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/core/tile_fetcher.py): basemap assembler · Builds a reference image for the QGIS map extent. · `magic_georeferencer/core/tile_fetcher.py`
- [Tile providers](https://github.com/fungobungaloid/georefio/blob/main/magic_georeferencer/config/tile_sources.json): source definitions · Selects OSM or Esri tile sources. · `magic_georeferencer/config/tile_sources.json`
- **Internet tile services**: external imagery API · OpenStreetMap and optional Esri World Imagery.

## Connections

- 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
