
Split a Project GeoPackage into One File Per Layer
Source:R/rfp_project_split.R
rfp_project_split.RdConverts a project that keeps every layer in a single
background_layers.gpkg into one GeoPackage per layer under a
background_layers/ directory, and repoints the .qgs at the new files.
Arguments
- path
Character. Project directory.
- dir_layers
Character. Directory to write per-layer GeoPackages into.
NULL(default) resolvesgetOption("rfp.dir_layers"), normally"background_layers".- file_gpkg
Character. Name of the single GeoPackage to split.
NULL(default) resolvesgetOption("rfp.file_gpkg").- dry_run
Logical. Default
TRUE- report the plan and exit without writing anything.
Details
The single file makes any non-diffable change cost the whole project: geodiff cannot diff a changed set of tables, so adding one 28-row layer to a 135 MB project uploads 135 MB. Split, the same addition uploads ~135 KB, an unchanged layer is never uploaded at all, and the worst case becomes the largest single layer rather than the whole project.
Conversion is fail-closed. Every layer is copied with ogr2ogr -preserve_fid
(so the stable feature ids that keep refresh changesets small survive), each
copy is checked for row count and column schema against its source, and the
original is removed only after every layer has passed. A failure leaves the
project exactly as it was.
The .qgs rewrite only touches datasources rfp manages - the single
GeoPackage and anything already inside the layers directory. Form
GeoPackages, ad-hoc analysis files, rasters and web layers are left alone.
Examples
# Split a copy of the packaged fixture project
dir <- file.path(tempdir(), "split_demo")
dir.create(dir, showWarnings = FALSE)
file.copy(
system.file("testdata", "subset_fixture", "parent",
"background_layers.gpkg", package = "rfp"),
file.path(dir, "background_layers.gpkg")
)
#> [1] TRUE
# dry run reports the plan and touches nothing
rfp_project_split(dir)
#>
#> ── Split plan: /tmp/RtmpfSNDuG/split_demo ──
#>
#> ℹ background_layers.gpkg (0.2 MB) -> 4 files in background_layers/
#> lakes (1 rows)
#> roads (1 rows)
#> streams (2 rows)
#> unused_sentinel (1 rows)
#> ℹ DRY RUN - nothing written. Re-run with dry_run = FALSE to proceed.
unlink(dir, recursive = TRUE)