Selective synchronization of data between GeoPackages
The GpkgToGpkg model is a QGIS Model Designer workflow developed to compare a source GeoPackage with a target GeoPackage, identify records that are missing from the target, and append them to the target database. The model does not perform a full overwrite. Instead, it processes each table individually and uses existence checks to prevent records that are already present from being copied again.
The model has a modular structure. Some core blocks are used regardless of the selected thematic options, whereas the blocks associated with Soil Sites, observed or derived Soil Profiles, Soil Bodies, and Soil Derived Objects are enabled through Boolean parameters and Conditional Branch algorithms.
Note
Key principle
Synchronization is incremental: the SOURCE is read, the TARGET is queried to determine whether the relevant keys already exist, and only missing records are passed to the GDAL append operations.
true.NOT EXISTS. For most tables, guid is used as the unique identifier; junction tables use composite keys.-update and -append, assigns the destination layer name with -nln, and uses -nlt NONE for non-spatial tables. The -unsetFid option prevents the internal feature ID from being transferred.log_folder is provided, the QGIS Processing log is written to a dated file in the selected folder.| Parameter | Type / default | Description |
|---|---|---|
| SOURCE_GPKG | File | Source GeoPackage from which records are read, checked, and copied when required. |
| TARGET_GPKG | File | Target GeoPackage to which missing records are appended. It must contain the tables expected by the model and use a schema consistent with the SOURCE. |
| LOG FOLDER | Folder | Folder in which the QGIS Processing log file will be saved. |
| Copy Soil Site | Boolean / True |
Copies soilsite records and the related datastream and observation records. |
| Copy Observed Soil Profile | Boolean / True |
Copies observed Soil Profiles, where isderived = 0, together with related profileelement records, descriptive tables, datastreams, and observations. |
| Copy Derived Soil Profile | Boolean / True |
Copies derived Soil Profiles, where isderived = 1, together with related profileelement records, descriptive tables, datastreams, and observations. The isderivedfrom table is copied only when both derived and observed Soil Profiles are enabled. |
| Copy Soil Body | Boolean / True |
Copies soilbody and soilbody_geom records. It also copies derivedprofilepresenceinsoilbody when derived Soil Profiles are enabled, and isbasedonsoilbody when Soil Derived Objects are enabled. |
| Copy Soil Derived Object | Boolean / True |
Copies soilderivedobject, isbasedonsoilderivedobject, related datastreams and observations, and conditionally copies isbasedonobservedsoilprofile and isbasedonsoilbody. |
Conditional Branch algorithms produce named branches that can be referenced as dependencies by other algorithms.
| Branch | Expression | Purpose |
|---|---|---|
| Cond Soil Profile enabled | @copy_derived_soil_profile = true OR @copy_observed_soil_profile = true |
Enables the common Soil Profile workflow when at least one profile category is requested. |
| Cond Soil Site enabled | @copy_soil_site = true |
Enables Soil Sites and their related datastreams and observations. |
| Cond Soil Body enabled | @copy_soil_body = true |
Enables Soil Bodies, geometries, and directly dependent relationships. |
| Cond Soil Der Obj enabled | @copy_soil_derived_object = true |
Enables Soil Derived Objects and their related data. |
| Cond IsDerived | @copy_derived_soil_profile = true AND @copy_observed_soil_profile = true |
Enables isderivedfrom only when both sides of the relationship are included. |
| Cond Observed | @copy_observed_soil_profile = true |
Enables workflow sections specific to observed Soil Profiles. |
| Cond Derived | @copy_derived_soil_profile = true |
Enables workflow sections specific to derived Soil Profiles. |
| LOG | @log_folder IS NOT NULL AND trim(@log_folder) <> '' |
Enables log export only when a non-null, non-empty folder has been provided. |
Note
Important semantic detail
A condition controls only the components that explicitly declare the relevant branch as a dependency. It does not automatically behave like an if block surrounding an entire area of the graphical model.
| User selection | True branches | Main result |
|---|---|---|
| Observed profiles only | Cond Soil Profile enabled; Cond Observed | Copies profiles with isderived = 0, Soil Plots, and the relevant Profile Element, Datastream, and Observation chains. isderivedfrom is not copied. |
| Derived profiles only | Cond Soil Profile enabled; Cond Derived | Copies profiles with isderived = 1 and their related chains. isderivedfrom is not copied. |
| Observed and derived profiles | Cond Soil Profile enabled; Cond Observed; Cond Derived; Cond IsDerived | Copies both profile groups and the isderivedfrom relationship. |
| Soil Sites only | Cond Soil Site enabled | Copies soilsite records and their related datastream and observation chains. |
| Soil Bodies and derived profiles | Cond Soil Body enabled; Cond Derived | Copies soilbody records, geometries, and derivedprofilepresenceinsoilbody. |
| Soil Derived Objects and observed profiles | Cond Soil Der Obj enabled; Cond Observed | Copies derived objects, isbasedonsoilderivedobject, isbasedonobservedsoilprofile, datastreams, and observations. |
| Log folder provided | LOG | Saves the log. If the field is null or empty, Save log to file is skipped. |
Internal model identifiers are intentionally omitted. The display names used in QGIS Model Designer provide a clearer operational description.
This flow completes the shared tables used by datastreams and observations.
Each check returns only records whose key does not already exist in the TARGET.
This flow is enabled when at least one group, observed or derived Soil Profiles, is requested.
isderived field.The Join SP DS / Join SP DS OBS and Join PE DS / Join PE DS OBS chains also select the datastreams and observations associated with profiles and profile elements.
This flow is enabled by Copy Observed Soil Profile and includes records where isderived = 0.
This flow is enabled by Copy Derived Soil Profile and includes records where isderived = 1.
The isderivedfrom relationship requires both profile categories.
guid_base and guid_related.Note
Why an AND condition is required
Copying isderivedfrom when only one profile group is included could create a relationship that references a profile not present in the TARGET.
This flow is enabled by Copy Soil Site.
The joins restrict datastreams and observations to the Soil Sites included in the current synchronization.
This flow is enabled by Copy Soil Body.
This flow is enabled by Copy Soil Derived Object.
This flow is independent of the thematic data domains.
log_folder has been provided.log_folder is null or empty, log export is skipped.These components perform the SOURCE/TARGET comparison:
NOT EXISTS query;These components select relevant records:
These components clean and restore the output schema:
These components modify the TARGET:
These components control execution:
guid, codelist uses id + collection, and several junction tables use pairs of foreign keys..model3 definition. This does not modify the TARGET when the corresponding GDAL component is skipped, but it may result in unnecessary preliminary processing.isderivedfrom only when both observed and derived Soil Profiles are enabled.log_folder during testing and large-scale operations to retain an execution record.GpkgToGpkg implements a three-stage pipeline: identification of missing records through SQL, selection of dependent records through joins and field retention, and writing to the TARGET through GDAL append operations. Conditional branches make the model configurable without duplicating complete workflows, but their effect must be interpreted through the dependencies declared by individual components. Parameter selection therefore determines not only which main entities are copied, but also which relationships, datastreams, and observations are retained in the target GeoPackage.