Skip to content

Commit 3c0d901

Browse files
committed
gdal raster polygonize: change --connectedness to --connect-diagonal-pixels (consistent with gdal raster sieve)
1 parent 5e750aa commit 3c0d901

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

apps/gdalalg_raster_polygonize.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ GDALRasterPolygonizeAlgorithm::GDALRasterPolygonizeAlgorithm()
7373
AddArg("attribute-name", 0, _("Name of the field with the pixel value"),
7474
&m_attributeName)
7575
.SetDefault(m_attributeName);
76-
AddArg("connectedness", 0,
77-
_("Whether to use 4-connectedness or 8-connectedness"),
78-
&m_connectedness)
79-
.SetChoices("4", "8")
80-
.SetDefault(m_connectedness);
76+
77+
AddArg("connect-diagonal-pixels", 'c',
78+
_("Consider diagonal pixels as connected"), &m_connectDiagonalPixels)
79+
.SetDefault(m_connectDiagonalPixels);
8180
}
8281

8382
/************************************************************************/
@@ -238,7 +237,7 @@ bool GDALRasterPolygonizeAlgorithm::RunImpl(GDALProgressFunc pfnProgress,
238237
}
239238

240239
CPLStringList aosPolygonizeOptions;
241-
if (m_connectedness == 8)
240+
if (m_connectDiagonalPixels)
242241
{
243242
aosPolygonizeOptions.SetNameValue("8CONNECTED", "8");
244243
}

apps/gdalalg_raster_polygonize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GDALRasterPolygonizeAlgorithm final : public GDALAlgorithm
5151
int m_band = 1;
5252
std::string m_outputLayerName = "polygonize";
5353
std::string m_attributeName = "DN";
54-
int m_connectedness = 4;
54+
bool m_connectDiagonalPixels = false;
5555
};
5656

5757
//! @endcond

autotest/utilities/test_gdalalg_raster_polygonize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ def test_gdalalg_raster_polygonize_int64():
224224
assert lyr.GetLayerDefn().GetFieldDefn(0).GetType() == ogr.OFTInteger64
225225

226226

227-
def test_gdalalg_raster_polygonize_connectedness():
227+
def test_gdalalg_raster_polygonize_connect_diagonal_pixels():
228228

229229
alg = get_alg()
230230
alg["input"] = "../gcore/data/byte.tif"
231231
alg["output"] = ""
232232
alg["output-format"] = "MEM"
233-
alg["connectedness"] = 8
233+
alg["connect-diagonal-pixels"] = True
234234
assert alg.Run()
235235
ds = alg["output"].GetDataset()
236236
lyr = ds.GetLayerByName("polygonize")

doc/source/programs/gdal_raster_polygonize.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ Standard options
7272

7373
The name of the field to create (defaults to "DN").
7474

75-
.. option:: --connectedness 4|8
75+
.. option:: -c, --connect-diagonal-pixels
7676

77-
Whether to use 4-connectedness or 8-connectedness. With 4-connectedness,
78-
pixels will be included in the same output feature if they share a side.
79-
With 8-connectedness, pixels will also be included in the same output
80-
feature if they share a corner. Default is 4.
77+
Consider diagonal pixels (pixels at the corners) as connected.
78+
The default behavior is to only consider pixels that are touching the edges
79+
as connected, which is the same as 4-connectivity. When this option is
80+
selected, the algorithm will also consider pixels at the corners as connected,
81+
which is the same as 8-connectivity.
8182

8283

8384
Advanced options

0 commit comments

Comments
 (0)