Skip to content

GeoTIFFBase.readRasters should support COGs with multiple full-res images #470

@rgov

Description

@rgov

GeoTIFFBase.readRasters() attempts to find the best-fitting image (full resolution or overview) for given bounds and desired resolution.

The function assumes that the first image is the full resolution image, and that any other images with newSubfileType & 1 are downsampled overviews of this full resolution image:

      const firstImage = await this.getImage();
      // ...
      for (let i = 0; i < imageCount; ++i) {
        const image = await this.getImage(i);
        const { SubfileType: subfileType, NewSubfileType: newSubfileType } = image.fileDirectory;
        if (i === 0 || subfileType === 2 || newSubfileType & 1) {
          allImages.push(image);
        }
      }

However, the COG spec allows for multiple full resolution images, each with their own overview images. The function does not handle this case properly.

The function could take an optional principal_image_id (default 0) parameter, follow the sequence of overview images, and stop before the next full resolution image:

      const firstImage = await this.getImage(principal_image_id);
      // ...
      allImages.push(firstImage);
      for (let i = principal_image_id + 1; i < imageCount; ++i) {
        const image = await this.getImage(i);
        const { SubfileType: subfileType, NewSubfileType: newSubfileType } = image.fileDirectory;
        if (newSubfileType & 1 === 0) {
          // The chain ended, so this is a different full-res image
          break;
        }
        allImages.push(image);
      }

Note I've dropped the check for subfileType === 2, I'm not sure whether it should skip over other subfile types like thumbnails or terminate the loop. I don't think we expect them in a COG, and I'm not sure about the general case.

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