Skip to content

Tile dft_stac_fetch to bound download over sparse-floodplain bounding boxes #36

Description

@NewGraphEnvironment

Problem

dft_stac_fetch() builds a single gdalcubes cube over the AOI's bounding box and masks to the polygon afterward. For a thin, spread-out AOI — a floodplain following a river corridor — the bounding box is largely empty, so the download scales with the bbox, not the AOI. Large-floodplain fetches are download-bound (~30 min per group at 10 m × 3 yr).

Measured on an io-lulc 10 m floodplain fetch (NECR): the grid is 57.0 M cells, of which 5.73 M (10.1%) fall inside the floodplain — a ~10× download overhead. Thinner / more diagonal reaches are worse.

Distinct from #32

#32 restores polygon-tight compute in dft_stac_cube() via gdalcubes::filter_geom(), which is blocked upstream (segfault in gc_exec_worker, confirmed on gdalcubes 0.7.4 — reported upstream). This issue is the filter_geom-independent path: cut the download by tiling, on the categorical dft_stac_fetch() (io-lulc) path.

Proposed

Tile the AOI into a grid, fetch only tiles intersecting the AOI (skip empty tiles), and mosaic. Peak download approaches the union of intersecting tile bboxes — near the AOI footprint for a corridor, rather than the full bbox. Tile size trades request count against per-request waste.

Reprex

library(drift); library(sf); library(terra)
# thin AOI, large bounding box: a ~50 km diagonal reach buffered 100 m
line <- st_sfc(st_linestring(rbind(c(-122.9, 54.0), c(-122.4, 54.4))), crs = 4326)
aoi  <- st_as_sf(st_buffer(st_transform(line, 3005), 100)) |> st_transform(4326)
r <- dft_stac_fetch(aoi, source = "io-lulc", years = 2020)[["2020"]]
nn <- terra::global(!is.na(r), "sum", na.rm = TRUE)[1, 1]
c(grid_cells = terra::ncell(r), aoi_cells = nn,
  aoi_fraction = round(nn / terra::ncell(r), 3),
  download_overhead_x = round(terra::ncell(r) / nn))
#> the fetch downloads ~1/aoi_fraction more pixels than the AOI needs

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