Skip to content

Commit

Permalink
Merge pull request #11343 from rouault/fix_11340
Browse files Browse the repository at this point in the history
GDALContourGenerateEx(): return CE_None even if the raster is at constant value
  • Loading branch information
rouault authored Nov 26, 2024
2 parents 7bbd872 + 9ef30ab commit b646a8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion alg/contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ CPLErr GDALContourGenerateEx(GDALRasterBandH hBand, void *hLayer,
}
}

bool ok = false;
bool ok = true;

try
{
Expand Down Expand Up @@ -880,6 +880,11 @@ CPLErr GDALContourGenerateEx(GDALRasterBandH hBand, void *hLayer,
}
}

if (ok)
{
pfnProgress(1.0, "", pProgressArg);
}

return ok ? CE_None : CE_Failure;
}

Expand Down
25 changes: 25 additions & 0 deletions autotest/alg/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,28 @@ def test_contour_min_value_is_multiple_of_interval(tmp_vsimem):
f = lyr.GetNextFeature()
assert f["ELEV"] == 3
ogrtest.check_feature_geometry(f, "LINESTRING (1.5 0.0,1.5 0.5,1.5 1.5,1.5 2.0)")


###############################################################################
# Test scenario of https://github.com/OSGeo/gdal/issues/11340


def test_contour_constant_raster_value(tmp_vsimem):

ogr_ds = ogr.GetDriverByName("Memory").CreateDataSource("")
lyr = ogr_ds.CreateLayer("contour", geom_type=ogr.wkbLineString)
lyr.CreateField(ogr.FieldDefn("ID", ogr.OFTInteger))
lyr.CreateField(ogr.FieldDefn("ELEV", ogr.OFTReal))

src_ds = gdal.GetDriverByName("MEM").Create("", 1, 1)
assert (
gdal.ContourGenerateEx(
src_ds.GetRasterBand(1),
lyr,
options=["LEVEL_INTERVAL=10", "ID_FIELD=0", "ELEV_FIELD=1"],
)
== gdal.CE_None
)

f = lyr.GetNextFeature()
assert f is None

0 comments on commit b646a8b

Please sign in to comment.