stratified_packager.processing.strata
Strata resolution: snapshot, strict naming, gpkg/zip path evaluation, bundling (SPEC §6).
Runs on the algorithm thread during Phase A. Every fatal condition raises
QgsProcessingException (the Processing framework’s sanctioned failure
path); names and paths are validated, never silently rewritten.
Module Attributes
Pseudo-stratum key of the full package (SPEC §2/§11); sanitization strips |
Functions
|
Group strata into zip bundles and enforce the §6.6 uniqueness rules. |
|
Evaluate a packaged layer's display-name expression for one stratum (SPEC §4/§13). |
|
Resolve the run's strata from the stratification layer (SPEC §6). |
Classes
|
The outcome of strata resolution. |
|
One resolved stratum (plain data; safe to hand across threads). |
- class stratified_packager.processing.strata.StrataResolution(strata, bundles, features)[source]
The outcome of strata resolution.
- Parameters:
strata (
tuple[StratumSpec,...])bundles (
Mapping[str,tuple[StratumSpec,...]])features (
tuple[QgsFeature,...])
- __init__(strata, bundles, features)
- Parameters:
strata (
tuple[StratumSpec,...])bundles (
Mapping[str,tuple[StratumSpec,...]])features (
tuple[QgsFeature,...])
- bundles: Mapping[str, tuple[StratumSpec, ...]]
Members per zip path (
zip_rel); multi-member values are bundled zips (§6.6).
- features: tuple[qgis.core.QgsFeature, ...]
The stratum features, aligned with
strata. Phase-A (algorithm thread) material only — unlike the specs, these are live QGIS objects.
- strata: tuple[StratumSpec, ...]
All strata, ordered by stratum feature id.
- class stratified_packager.processing.strata.StratumSpec(feature_id, raw_name, name, gpkg_rel, zip_rel)[source]
One resolved stratum (plain data; safe to hand across threads).
- __init__(feature_id, raw_name, name, gpkg_rel, zip_rel)
- class stratified_packager.processing.strata._PathKind(*values)[source]
Which §6 path is being evaluated (only affects error wording).
- GPKG = 'GeoPackage'
- ZIP = 'zip'
- stratified_packager.processing.strata._base_context(layer, project)[source]
Build the full project + layer expression context (SPEC §6.2).
- Parameters:
layer (
QgsMapLayer) – The layer supplying the layer scope (any map layer).project (
QgsProject) – The project.
- Return type:
- Returns:
A fresh expression context.
- stratified_packager.processing.strata._evaluate_names(layer, project, expression_text, features)[source]
Evaluate the stratum name per feature under the strict regime (SPEC §6.2).
- Parameters:
layer (
QgsVectorLayer) – The stratification layer.project (
QgsProject) – The project.expression_text (
str) – The name expression; empty means the feature id.features (
Sequence[QgsFeature]) – The snapshot.
- Return type:
- Returns:
One raw name per feature, in order.
- Raises:
QgsProcessingException – On a parse error, an evaluation error or a NULL name.
- stratified_packager.processing.strata._evaluate_path(layer, project, expression_text, feature, *, default, kind, stratum_vars)[source]
Evaluate and validate one gpkg/zip path for one stratum (SPEC §6.4/§6.5).
- Parameters:
layer (
QgsVectorLayer) – The stratification layer.project (
QgsProject) – The project.expression_text (
str) – The path expression; empty selects default.feature (
QgsFeature) – The stratum feature.default (
str) – The default path when the expression is empty.kind (
_PathKind) – Which path is being evaluated (error wording).stratum_vars (
Mapping[str,str]) – The §6.4 naming variables injected into the context.
- Return type:
- Returns:
The validated, slash-joined relative path (no extension).
- Raises:
QgsProcessingException – On parse/evaluation errors, NULL results or §6.5 path-rule violations.
- stratified_packager.processing.strata._reject_duplicate_raw_names(raw_names)[source]
Abort on duplicate raw stratum names (SPEC §6.2).
- Parameters:
- Raises:
QgsProcessingException – Listing every duplicated name.
- Return type:
- stratified_packager.processing.strata._reject_sanitization_collisions(raw_names, sanitized)[source]
Abort on case-insensitive post-sanitization collisions (SPEC §6.2, Windows rule).
- stratified_packager.processing.strata._snapshot(layer, *, strata_from_selection)[source]
Materialize the stratum features once, ordered by feature id (SPEC §6.1).
- Parameters:
layer (
QgsVectorLayer) – The stratification layer (itssubsetStringapplies implicitly).strata_from_selection (
bool) – Whether only the selected features become strata.
- Return type:
- Returns:
The ordered features.
- Raises:
QgsProcessingException – If strata_from_selection is set but nothing is selected — fail-fast, never a silent full run (SPEC §6.1/§15).
- stratified_packager.processing.strata.bundle_strata(strata)[source]
Group strata into zip bundles and enforce the §6.6 uniqueness rules.
Also called by the algorithm to re-bundle after appending the
<full>pseudo-stratum, so the full package passes the same zip- and gpkg-collision checks as any stratum.- Parameters:
strata (
Sequence[StratumSpec]) – The resolved strata.- Return type:
dict[str,tuple[StratumSpec,...]]- Returns:
Members per exact zip path, in stratum order.
- Raises:
QgsProcessingException – On case-variant zip paths or on case-insensitive gpkg path collisions inside one bundle.
- stratified_packager.processing.strata.evaluate_layer_display_name(layer, project, expression_text, *, stratum_name, stratum_name_sanitized)[source]
Evaluate a packaged layer’s display-name expression for one stratum (SPEC §4/§13).
The expression sees the full project + layer context plus
@stratum_nameand@stratum_name_sanitized. Unlike the §6 path expressions it is feature-less — it names a whole layer, not a stratum feature — and its layer scope is the packaged layer being renamed, so@layer_nameresolves to that layer’s original name.- Parameters:
layer (
QgsMapLayer) – The packaged layer being renamed.project (
QgsProject) – The project supplying the global/project/layer scopes.expression_text (
str) – The non-emptystratified_packager_layer_nameexpression.stratum_name (
str) – The raw stratum name (@stratum_name).stratum_name_sanitized (
str) – The sanitized stratum name (@stratum_name_sanitized).
- Return type:
- Returns:
The evaluated display name.
- Raises:
QgsProcessingException – On a parse error, an evaluation error or a NULL result.
- stratified_packager.processing.strata.resolve_strata(layer, *, project, name_expression='', gpkg_path_expression='', zip_path_expression='', strata_from_selection=False)[source]
Resolve the run’s strata from the stratification layer (SPEC §6).
The snapshot honors the layer’s
subsetString; when strata_from_selection is set, only the selected features become strata (an empty selection aborts — fail-fast, never a silent full run). Names follow the strict regime: NULL or evaluation errors, duplicate raw names and case-insensitive post-sanitization collisions all abort. Evaluated gpkg/zip paths are validated against the §6.5 path rules, and the §6.6 bundling rules are enforced.- Parameters:
layer (
QgsVectorLayer) – The stratification layer.project (
QgsProject) – The project supplying the expression context scopes.name_expression (
str) –STRATUM_NAME_EXPRESSION; empty means the feature id.gpkg_path_expression (
str) –GPKG_PATH_EXPRESSION; empty means the sanitized name.zip_path_expression (
str) –ZIP_PATH_EXPRESSION; empty means the gpkg basename.strata_from_selection (
bool) – Whether an existing selection restricts the strata.
- Return type:
- Returns:
The resolved strata and their zip bundles (both empty for an empty layer).
- Raises:
QgsProcessingException – On any violation of the strict §6 rules.
- stratified_packager.processing.strata.FULL_PACKAGE_KEY: Final = '<full>'
Pseudo-stratum key of the full package (SPEC §2/§11); sanitization strips
</>, so no real stratum can collide with it.