Skip to content

Commit

Permalink
gdal_footprint: fix -ovr on RGBA datasets (fixes #8792)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 23, 2023
1 parent 0fe09b6 commit b28a386
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/gdal_footprint_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
{
GDALRasterBand *poMaskBand;
const int nMaskFlags = poBand->GetMaskFlags();
if ((nMaskFlags & GMF_ALPHA) != 0)
if ((nMaskFlags & GMF_ALPHA) != 0 ||
poBand->GetColorInterpretation() == GCI_AlphaBand)
{
poMaskBand = poBand;
}
Expand Down
25 changes: 25 additions & 0 deletions autotest/utilities/test_gdal_footprint_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,28 @@ def test_gdaldem_footprint_dict_arguments():
"-lco",
"STRING_DEFAULT_WIDTH=10",
]


###############################################################################
# Test footprint, RGBA and overviews


def test_gdaldem_footprint_rgba_overviews():

src_ds = gdal.GetDriverByName("MEM").Create("", 6, 6, 4)
for i in range(4):
src_ds.GetRasterBand(i + 1).SetColorInterpretation(gdal.GCI_RedBand + i)
src_ds.BuildOverviews("NONE", [2])
for i in range(4):
src_ds.GetRasterBand(i + 1).GetOverview(0).WriteRaster(1, 1, 1, 1, b"\xFF")
out_ds = gdal.Footprint(
"",
src_ds,
format="Memory",
targetCoordinateSystem="pixel",
ovr=0,
)
assert out_ds is not None
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((2 2,2 4,4 4,4 2,2 2)))")

0 comments on commit b28a386

Please sign in to comment.