This document provides essential information for AI coding agents working on the GeoPublicHealth QGIS plugin.
GeoPublicHealth is a QGIS 3.x plugin for epidemiology and public health GIS analysis. It’s written in Python and uses PyQGIS, PyQt5, and spatial analysis libraries.
Key Technologies:
Autocorrelation Coverage:
Autocorrelation UI Notes:
Run all tests:
python test_suite.py
Run a single test:
python -m unittest src.test.test_pep8.TestPep8.test_pep8
Run specific test module:
python -m unittest discover -s src/test -p "test_*.py"
Run unit tests (script):
./scripts/run_tests.sh
Run unit tests (make):
make test
Run processing tests (make):
make processing-test
None (not 0).None per feature.References:
src/core/services/.Run PEP8 style check:
make pep8
PEP8 configuration:
Update translation strings:
make update-translation-strings
Compile translation strings:
make compile-translation-strings
Test translations:
make test-translations
Translation stats:
make translation-stats
All Python files must start with UTF-8 encoding declaration and GPL license header:
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GeoPublicHealth
A QGIS plugin
-------------------
begin : YYYY-MM-DD
copyright : (C) YYYY by Author Name
email : email@example.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
Imports should be organized in this order:
__future__ or builtins)Example:
from builtins import str
from uuid import uuid4
from tempfile import NamedTemporaryFile
import numpy as np
import libpysal
from qgis.PyQt.QtCore import QSettings, QVariant
from qgis.PyQt.QtWidgets import QApplication, QDialog
from qgis.core import QgsVectorLayer, Qgis
from qgis.gui import QgsMessageBar
from GeoPublicHealth.src.core.tools import tr
from GeoPublicHealth.src.core.exceptions import GeoPublicHealthException
GeoPublicHealthPlugin, AutocorrelationDialog)create_memory_layer, open_main_window)layer_name, coordinate_reference_system)PYSAL_AVAILABLE, DEFAULT_NUMBER_LINES)_run_tests, _validate_input)Use type hints for function parameters and return types, especially in newer code:
from typing import Dict, List, Optional, Union, Any, Tuple
def create_memory_layer(
layer_name: str,
geometry: QgsWkbTypes,
coordinate_reference_system: Optional[QgsCoordinateReferenceSystem] = None,
fields: Optional[QgsFields] = None) -> QgsVectorLayer:
"""Create a vector memory layer."""
pass
Use Google-style docstrings with type information:
def copy_layer(source, target):
"""Copy a vector layer to another one.
:param source: The vector layer to copy.
:type source: QgsVectorLayer
:param target: The destination.
:type target: QgsVectorLayer
"""
pass
GeoPublicHealthExceptionsrc/core/exceptions.pyExample:
from GeoPublicHealth.src.core.exceptions import (
GeoPublicHealthException,
NoLayerProvidedException,
DifferentCrsException
)
if not layer:
raise NoLayerProvidedException()
Always wrap user-facing strings with tr() function:
from GeoPublicHealth.src.core.tools import tr
message = tr(u'No layer was provided.')
display_message_bar(tr(u'Error while processing'), Qgis.Critical)
pyuic5 -o output_ui.py input.uiDialog (e.g., AutocorrelationDialog)GeoPublicHealth/
├── src/
│ ├── core/ # Core functionality and utilities
│ │ ├── blurring/ # Blurring algorithms
│ │ ├── gis/ # GIS utilities
│ │ └── accessibility/
│ ├── gui/ # GUI dialogs and windows
│ │ ├── analysis/ # Analysis dialogs
│ │ ├── import_gui/ # Import dialogs
│ │ └── export/ # Export dialogs
│ ├── processing_geopublichealth/ # QGIS Processing algorithms
│ ├── datastore/ # Data storage implementations
│ ├── ui/ # Qt Designer .ui files
│ ├── test/ # Unit tests
│ ├── doc/ # Documentation
│ └── utilities/ # Utility functions
├── sample_data/ # Sample data for testing
├── scripts/ # Build and helper scripts
└── docs/ # Documentation files
from GeoPublicHealth.src.core.tools import create_memory_layer
from qgis.core import QgsWkbTypes
layer = create_memory_layer(
layer_name='my_layer',
geometry=QgsWkbTypes.Point,
coordinate_reference_system=source_crs,
fields=source_fields
)
import warnings
warnings.filterwarnings("ignore", category=FutureWarning,
message="Objects based on the `Geometry` class will deprecated")
warnings.filterwarnings("ignore", category=ResourceWarning,
message="unclosed file")
Always check for optional dependencies:
try:
import libpysal
PYSAL_AVAILABLE = True
except ImportError:
PYSAL_AVAILABLE = False
make pep8 with the project’s ignore rulestr())git checkout -b my-new-featurepython test_suite.pymake pep8git commit -am 'Add some feature'git push origin my-new-featuretype(scope): short summaryfeat(analysis): add inequality metrics, fix(core): handle null rates, refactor(gui): extract servicesgeopublichealth to match the plugin id.geopublichealth.zip (no version suffix) because QGIS infers the folder name from the zip.build/geopublichealth/, zip from build/, then copy the zip to installation/geopublichealth.zip.docs/plugins.xml to point at installation/geopublichealth.zip and refresh the <update_date>.