Skip to content

[Feature]: Add an area of a cloud-optimised GeoTIFF by its address as a raster layer: layer.addUrl {"bbox"} reads only that window #1204

Closed

Description

@elpidioassinaturas

Before you start

  • I searched the existing issues and the roadmap and did not find a duplicate request.

What problem does this solve?

A large GeoTIFF by its address comes in one of two ways today (docs/user-guide/data-formats.md):

  • Read in place: a tile layer (map.addTiles kind cog). It is drawn, but it isn't a raster. raster.process, raster.project, raster.mosaic, zonal statistics and symbology don't take it ("no raster layer").
  • Whole ("whole": true): a raster layer, but the file is downloaded whole, up to MAX_DOWNLOAD (512 MiB on the desktop, 256 MiB in the web app).

There is nothing in between: a raster of just the area one works on. Two cases:

  • MapBiomas land cover. Collection 10, 2019–2024, 30 m, one COG per year for Brazil, about 1.2 GB each. It is mirrored on Source Cooperative (https://data.source.coop/tristangruppwri/mapbiomas/mapbiomas-brazil/mapbiomas_brazil_2024/mapbiomas_brazil_2024.tif), with range requests, CORS, MODE overviews and class names in the metadata (CLASS_3=Forest Formation…). One municipality (Teresina, 1,392 km²) is about 1,400 × 3,000 pixels, some 4 million values. Today it can only be drawn (as grey, since a tile layer takes no class colours), or not had at all: the file is over the 512 MiB limit.
  • Copernicus GLO-30 elevation. These are 1° tiles. A plugin that puts a municipality's elevation on a UTM grid has to download each tile whole ("whole": true, about 47 MB each) before it can raster.mosaic, clip and raster.project it.

The reading itself exists. The data-cube commands read just an area of STAC COGs at a chosen overview, with cog::info_blocking and cog::read_values_blocking(info, url, level, band, cols, rows) (crates/tiles/src/cog.rs; used in crates/engine/src/cmd/stac.rs). It isn't offered for a single file by its address.

Proposed solution

layer.addUrl takes a "bbox" for a cloud-optimised GeoTIFF:

{"url": "https://…/mapbiomas_brazil_2024.tif", "bbox": [-42.971, -5.587, -42.599, -4.786], "name": "MapBiomas 2024"}
  • The header is read as for a tile layer (cog::info). Then only the tiles that cross the box, at full resolution, come in as a raster layer of that window, in the file's coordinate system, with its no-data. The box is in longitude and latitude, and is turned into the file's system when that is another.
  • "cellSize" (optional, in the file's units, or metres for a geographic file) picks the coarsest overview that is still finer than it. Without it, a window over MAX_VALUES_READ (256 MB) is refused with the overview that would fit, never read at a resolution nobody asked for.
  • Band names, and the class names a file declares (GDAL's CLASS_<code> metadata, as in the MapBiomas files, and a band's category names when present), go to the layer. A categorical file is then ready for a Colormap or Unique Values legend (see [Feature]: Raster legend labels from class names (colour table / RAT), and editable raster class labels #889).
  • Without bbox, nothing changes: a tile layer, or a whole download with "whole": true.

Choices in this proposal

  • A parameter of layer.addUrl, not a new command. It is the command that already tells a COG from other files and reads its header, and plugins and scripts already call it. bbox is the name service.add and stac.search use for the same thing.
  • Full resolution by default. An analysis on a 30 m product expects its pixels. The overview is only taken when the caller asks for a coarser cell, so a result never silently comes from MODE or nearest overviews (the Brazil Data Cube's overviews pick one pixel per cell).
  • The same reader as the data cubes (read_values_blocking), on the desktop and the command line. In the web app the window goes through the front end's download path, as other layer.addUrl downloads do (fix(plugins): a plugin's layer.addUrl downloads off the frame on the desktop #1170), reading the tiles with range requests (the server must allow CORS with Range, as for a COG read in place).
  • Bounded: at most MAX_VALUES_READ values, at most a set number of tiles, and the usual time limit. The limits go in the docs, with the overview to take for a larger area.

Estimated scope

Medium. The header, tile reads and decoding exist. What is new is turning a box into a level's columns and rows, building the raster layer from the values with its transform, carrying the class names, and the web path.

Alternatives considered

  • raster.project reading the address directly, onto a grid: this is useful too, and it could follow, but it is narrower. A window as a plain raster layer serves clipping, statistics, symbology and export alike.
  • A STAC catalogue for each such file: cube.reduce reads by area, but needs a STAC API's search, and a static catalogue (the MapBiomas mirror has one) can't be searched ("a data cube needs a STAC API's search").
  • GDAL (gdal_translate -projwin /vsicurl/…) on the desktop works, but not in the web app, and it needs GDAL installed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions