Skip to content

Bound dft_stac_cube() streaming to the AOI (fetch-time read still bbox-bound after #32) #38

Description

@NewGraphEnvironment

Problem

dft_stac_cube() builds its gdalcubes cube over the AOI's bounding box (cube_view(extent = bbox_target)), so the COG streaming — the dominant cost, ~10–30 min for a multi-year monthly Sentinel-2 fetch — scales with the bbox, not the AOI. For a thin, corridor-shaped floodplain the bounding box is largely empty.

#32 restored polygon-tight output (clip = TRUE masks the assembled stack with terra::mask()), but that runs after the pixels are streamed — it does not reduce what gdalcubes reads, so fetch time is unchanged.

Measured on the packaged example AOI (Neexdzii Kwa reach): area / bbox ≈ 0.105, i.e. ~90% of the streamed bounding box is outside the polygon — a ~10× streaming overhead. Thinner / more diagonal reaches are worse (NECR io-lulc: ~10.1% inside, per #36).

Distinct from #32

#32 clips the output of dft_stac_cube() (via terra::mask(), since gdalcubes::filter_geom() segfaults on the pinned build — see inst/notes/gdalcubes-pc-gotchas.md). This issue is about reducing the read: bounding the COG streaming to near the AOI footprint.

Related to #36

#36 is the same download overhead on the categorical dft_stac_fetch() (io-lulc) path, with a tiling proposal (fetch only tiles intersecting the AOI, then mosaic). The technique transfers, but this issue tracks it for dft_stac_cube() (continuous Sentinel-2), which has its own surface: a per-tile cube_view, cloud/SCL masking, the baseline-offset item split at 2022-01-25, and the terra::cover() coalesce.

Proposed

Options, roughly in order of feasibility:

  • Tile the cube_view — split the AOI bbox into a grid, build/stream one cube per tile intersecting the AOI, skip empty tiles, and mosaic (mirrors Tile dft_stac_fetch to bound download over sparse-floodplain bounding boxes #36). Peak read approaches the union of intersecting tile bboxes — near the AOI footprint for a corridor.
  • A working filter_geom — if/when the gdalcubes segfault is fixed upstream, it pushes the AOI into the read directly (no output-side terra::mask() needed either).
  • Server-side windowing — any STAC/gdalcubes path that reads only the AOI window.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions