Skip to content

Commit 6221105

Browse files
committed
Set NewSubfileType tag on overview IFDs for GDAL compatibility (#1150)
GDAL and rasterio use TIFF tag 254 (NewSubfileType = 1) to identify overview sub-IFDs. Without it, overviews are written correctly but invisible to GDAL-based tools. Verified: rasterio and gdalinfo now see both overview levels, and pixel values match GDAL's own COG output to within float32 rounding (max relative error < 0.0001%).
1 parent 99586e1 commit 6221105

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

xrspatial/geotiff/_header.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616

1717
# Well-known TIFF tag IDs
18+
TAG_NEW_SUBFILE_TYPE = 254
1819
TAG_IMAGE_WIDTH = 256
1920
TAG_IMAGE_LENGTH = 257
2021
TAG_BITS_PER_SAMPLE = 258

xrspatial/geotiff/_writer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
TAG_MODEL_TIEPOINT,
4040
)
4141
from ._header import (
42+
TAG_NEW_SUBFILE_TYPE,
4243
TAG_IMAGE_WIDTH,
4344
TAG_IMAGE_LENGTH,
4445
TAG_BITS_PER_SAMPLE,
@@ -593,6 +594,11 @@ def _assemble_tiff(width: int, height: int, dtype: np.dtype,
593594
for level_idx, (arr, lw, lh, rel_offsets, byte_counts, comp_data) in enumerate(pixel_data_parts):
594595
tags = []
595596

597+
# Mark overview IFDs as reduced-resolution images (TIFF tag 254).
598+
# GDAL/rasterio use this tag to identify overview sub-IFDs.
599+
if level_idx > 0:
600+
tags.append((TAG_NEW_SUBFILE_TYPE, LONG, 1, 1))
601+
596602
tags.append((TAG_IMAGE_WIDTH, LONG, 1, lw))
597603
tags.append((TAG_IMAGE_LENGTH, LONG, 1, lh))
598604
if samples_per_pixel > 1:

0 commit comments

Comments
 (0)