Skip to content

Commit

Permalink
gdal_footprint: fix taking into account of individual bands that have…
Browse files Browse the repository at this point in the history
… nodata
  • Loading branch information
rouault committed Nov 27, 2023
1 parent c95f6e7 commit 15e3168
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/gdal_footprint_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static bool GDALFootprintProcess(GDALDataset *poSrcDS, OGRLayer *poDstLayer,
}
else
{
if ((nMaskFlags & GMF_PER_DATASET) != 0)
if ((nMaskFlags & GMF_PER_DATASET) == 0)
{
bGlobalMask = false;
}
Expand Down
83 changes: 83 additions & 0 deletions autotest/utilities/test_gdal_footprint_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,86 @@ def test_gdaldem_footprint_rgba_overviews():
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((2 2,2 4,4 4,4 2,2 2)))")


###############################################################################
def test_gdal_footprint_lib_union():

src_ds = gdal.GetDriverByName("MEM").Create("", 3, 1, 2)
src_ds.GetRasterBand(1).SetNoDataValue(0)
src_ds.GetRasterBand(1).WriteRaster(0, 0, 1, 1, b"\xFF")
src_ds.GetRasterBand(2).SetNoDataValue(0)
src_ds.GetRasterBand(2).WriteRaster(1, 0, 1, 1, b"\xFF")
out_ds = gdal.Footprint(
"",
src_ds,
format="Memory",
targetCoordinateSystem="pixel",
)
assert out_ds is not None
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((0 0,0 1,2 1,2 0,0 0)))")


###############################################################################
def test_gdal_footprint_lib_intersection_none():

src_ds = gdal.GetDriverByName("MEM").Create("", 2, 1, 2)
src_ds.GetRasterBand(1).SetNoDataValue(0)
src_ds.GetRasterBand(1).WriteRaster(0, 0, 1, 1, b"\xFF")
src_ds.GetRasterBand(2).SetNoDataValue(0)
src_ds.GetRasterBand(2).WriteRaster(1, 0, 1, 1, b"\xFF")
out_ds = gdal.Footprint(
"",
src_ds,
format="Memory",
targetCoordinateSystem="pixel",
combineBands="intersection",
)
assert out_ds is not None
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
assert f is None


###############################################################################
def test_gdal_footprint_lib_intersection_partial():

src_ds = gdal.GetDriverByName("MEM").Create("", 3, 1, 2)
src_ds.GetRasterBand(1).SetNoDataValue(0)
src_ds.GetRasterBand(1).WriteRaster(0, 0, 2, 1, b"\xFF\xFF")
src_ds.GetRasterBand(2).SetNoDataValue(0)
src_ds.GetRasterBand(2).WriteRaster(1, 0, 1, 1, b"\xFF")
out_ds = gdal.Footprint(
"",
src_ds,
format="Memory",
targetCoordinateSystem="pixel",
combineBands="intersection",
)
assert out_ds is not None
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((1 0,1 1,2 1,2 0,1 0)))")


###############################################################################
def test_gdal_footprint_lib_intersection_full():

src_ds = gdal.GetDriverByName("MEM").Create("", 3, 1, 2)
src_ds.GetRasterBand(1).SetNoDataValue(0)
src_ds.GetRasterBand(1).WriteRaster(0, 0, 2, 1, b"\xFF\xFF")
src_ds.GetRasterBand(2).SetNoDataValue(0)
src_ds.GetRasterBand(2).WriteRaster(0, 0, 2, 1, b"\xFF\xFF")
out_ds = gdal.Footprint(
"",
src_ds,
format="Memory",
targetCoordinateSystem="pixel",
combineBands="intersection",
)
assert out_ds is not None
lyr = out_ds.GetLayer(0)
f = lyr.GetNextFeature()
ogrtest.check_feature_geometry(f, "MULTIPOLYGON (((0 0,0 1,2 1,2 0,0 0)))")

0 comments on commit 15e3168

Please sign in to comment.