Skip to content

[Feature]: Mosaic Rasters (raster.mosaic) on a thread of its own, with Cancel, started from the Workflows pane #2907

Done

Description

@elpidioassinaturas

Before you start

What problem does this solve?

raster.mosaic joins tiles of one grid. Its work grows with the tiles, and it has no background path: it is in neither workflows::IN_BACKGROUND nor ON_A_COPY, and its doc comment doesn't say why. Whoever asks for it holds the window, without progress or Cancel. raster.process, raster.rasterize and imagery.mosaic (the mapping workspaces' Build) have a path.

Times of the same raster_mosaic in the 0.8.0 release, from the command line (i7-10700, Float32):

Inputs Time
2 tiles, 120 million cells, from layers 1.0–1.2 s
The same, from GeoTIFF files 1.9 s
The same, from files, also writing the GeoTIFF 2.8 s
2 tiles, 480 million cells, from files, also writing the GeoTIFF 9.9 s
20 files of 60 million cells over the same area 11.1 s

The result is at most max_samples() values (120 million to 1 billion, by memory). The total read isn't bounded when the inputs overlap, up to 10,000 of them.

It comes from the review of #2826, which takes the command off the Imagery extension, so it is reachable with the app's defaults.

Proposed solution

Registering the command isn't enough on its own. Since #2739 the app starts every IN_BACKGROUND command on a thread when it comes through the app's dispatch, but nothing there asks for raster.mosaic: it has no pane, and Command Search says it needs input. Today's callers (a script, a task, the Assistant, an attached agent, a plugin) run on the session, where every raster command still runs in place. So, two parts:

1. The path. ("raster.mosaic", "Mosaic Rasters", mosaic_rasters_work) in workflows::IN_BACKGROUND:

  • The session is read first, on the UI thread: the layers (an Arc each, no copy), the names and the output path, with the permission and the checks as now.
  • On the thread: the files are read, checked and copied into the result. Cancel is looked at between inputs and between blocks of rows, and progress counts the inputs' rows.
  • The GeoTIFF is written staged and put in place as the raster is added, as Polygons to Raster does (Polygons to Raster on a thread of its own, and raster commands from the app's dispatch too #2739).
  • Notices (what reading left out, copyrights, band names) are said as it lands, in today's order.
  • raster.mosaic goes in long_commands.
  • The answer, parameters, results and errors don't change. Command line, Python and MCP run it in place, as now.

2. A caller. A Mosaic section in the Workflows pane: the rasters to join, in order (the first wins where they overlap), a name, and a GeoTIFF to write or none. It runs through the dispatch, with its progress and Cancel in the pane. It is listed in the Workflows menu and has no ribbon button.

Part 2 lands after part 1. No dependency is needed.

Left out: raster commands a script, the Assistant, an agent or a plugin runs on the session. That holds for every one of them and needs a design of its own. Also raster.project, which has no path either, and reading the files one at a time to hold fewer in memory.

Estimated scope

Medium: two pull requests of about 300 lines each, tests included. I can open them, after #2826 lands.

Alternatives considered

Not measured: the window itself. The times are the command's, and that it runs on the UI thread is from the code.

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