Skip to content

Add 'mvt rezoom' subcommand for overzooming and underzooming tiles - #47

Merged
trasch merged 1 commit into
mainfrom
feat/rezoom-command
Jul 16, 2026
Merged

trasch merged 1 commit into
mainfrom
feat/rezoom-command

Conversation

@trasch

@trasch trasch commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new mvt rezoom CLI subcommand and library API for rezooming (overzooming or underzooming) source tiles into a single output tile at a target zoom level.

Closes #46.

Usage

mvt rezoom [--target-z <z>] [--target-x <x>] [--target-y <y>] \
           [--output <file>] [--output-format <fmt>] \
           [--buffer-extents <n>] [--buffer-pixels <n>] \
           [--simplify-extents <n>] [--simplify-meters <n>] \
           [--layer <name>...] [--drop-layer <name>...] \
           [--force-overwrite] [--strict] [--verbose] \
           <source-tiles...>

Examples

# Overzoom z=14 tile to z=15 child, infer target from output filename
mvt rezoom --output ./tiles/15_17432_16030.mvt source_14_8716_8015.mvt

# Underzoom with explicit target coordinates
mvt rezoom --target-z 13 --target-x 4358 --target-y 4007 \
    --output out.mvt source_14_8716_8015.mvt

# Strict mode: abort if any source is not an ancestor/descendant
mvt rezoom --target-z 15 --target-x 2 --target-y 2 --strict \
    --output out.mvt source.mvt

How it works

Each source tile must be an ancestor or descendant of the target tile (validated via MapTile.isRelated(to:) from gis-tools 2.0.7). Features are copied in geographic coordinates; clipping to the target tile's bounding box (+ optional buffer) happens at encode time via the existing MVTEncoder/MLTEncoder projection and clipping pipeline — no manual coordinate scaling needed.

  • Overzoom (source z < target z): features outside the target child tile are clipped away.
  • Underzoom (source z > target z): all child features are retained within the larger parent tile.
  • Same zoom (identity): features pass through unchanged.

Library API

// Rezoom a single tile
let result = source.rezoom(toTargetX: 2, targetY: 2, targetZ: 3)

// Rezoom multiple sources into one target
let result = VectorTile.rezoom([sourceA, sourceB], toTargetX: 2, targetY: 2, targetZ: 3)

CLI behavior

  • Target coordinates: specified with --target-x/y/z or inferred from the --output file path (e.g. 15_17432_16030.mvt or 15/17432/16030.mvt).
  • --strict: aborts with an error if any source is not an ancestor/descendant of the target. Without --strict, invalid sources are silently skipped.
  • Supports all input/output formats (MVT, MLT, GeoJSON, GPX, Shapefile, GeoPackage) via the existing TileFormat loader and shared CLI.writeTile helper.

Refactoring

Extracted the duplicated writeTile method from MergeOptions into a shared CLI.writeTile in Sources/MVTCLI/WriteTile.swift, used by both Merge/Import/Export and Rezoom.

Files changed

  • Sources/MVTTools/Overzoom.swift (new) — VectorTile.rezoom() instance + static methods
  • Sources/MVTCLI/Rezoom.swift (new) — CLI.Rezoom subcommand
  • Sources/MVTCLI/WriteTile.swift (new) — shared CLI.writeTile helper
  • Sources/MVTCLI/CLI.swift — register Rezoom.self
  • Sources/MVTCLI/MergeOptions.swift — use shared CLI.writeTile
  • Package.swift — update gis-tools to 2.0.7
  • Tests/MVTToolsTests/OverzoomTests.swift (new) — 19 library tests
  • Tests/MVTCLITests/RezoomCommandTests.swift (new) — 7 CLI tests

Test plan

  • swift build — clean, no warnings
  • swift test --filter OverzoomTests — 19/19 pass
  • swift test --filter RezoomCommandTests — 7/7 pass
  • swift test — 224/224 pass across 32 suites
  • swift run mvt rezoom --help — verified
  • Manual smoke tests: overzoom, underzoom, strict/non-strict, target inference

Add the ability to rezoom (overzoom or underzoom) source tiles into a
single output tile at a target zoom level. Each source tile must be an
ancestor or descendant of the target; features are re-projected and
clipped to the target tile's bounding box at encode time.

Library API (Sources/MVTTools/Overzoom.swift):
- VectorTile.rezoom(toTargetX:targetY:targetZ:) — rezoom a single tile
- VectorTile.rezoom(_:toTargetX:targetY:targetZ:) — rezoom multiple
  sources into one target tile
- Ancestry validation uses MapTile.isRelated(to:) from gis-tools 2.0.7

CLI subcommand (Sources/MVTCLI/Rezoom.swift):
- mvt rezoom [--target-x/y/z | inferred from --output path]
  [--output <file>] [--output-format <fmt>] [--buffer-*] [--simplify-*]
  [--layer <name>...] [--drop-layer <name>...] [--force-overwrite]
  [--strict] [--verbose] <source-tiles...>
- --strict aborts on non-ancestor sources; without it, they are skipped
- Target coordinates inferred from output path (e.g. 3_2_2.mvt)

Refactoring:
- Extract shared CLI.writeTile helper to Sources/MVTCLI/WriteTile.swift,
  removing duplication between MergeOptions and Rezoom
- Update gis-tools dependency to 2.0.7 for MapTile.isRelated(to:)

Tests:
- 19 library tests (OverzoomTests): overzoom by 1 and 2, underzoom by 1,
  underzoom with multiple children, non-ancestry, same-zoom identity, all
  4 projections, MVT round-trip with real test data, GeoJSON round-trip,
  mixed sources, skip-invalid
- 7 CLI tests (RezoomCommandTests): overzoom, underzoom, --strict fails,
  non-strict skips, target inference from output path, missing target
  error, verbose output
@trasch trasch self-assigned this Jul 16, 2026
@trasch trasch added the enhancement New feature or request label Jul 16, 2026
@trasch
trasch merged commit b0369cb into main Jul 16, 2026
1 check passed
@trasch
trasch deleted the feat/rezoom-command branch July 16, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement overzooming: composite source tiles at a higher zoom level

1 participant