Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4647 closed defect (fixed)

GDALRasterPolygonEnumerator does not merge polygons correctly when nConnectedness = 8

Reported by: ctoney Owned by: warmerdam
Priority: normal Milestone: 1.9.1
Component: Algorithms Version: 1.9.0
Severity: normal Keywords: Raster Polygon Enumerator
Cc: Kyle Shannon

Description

When nConnectedness = 8 (diagonal pixels considered connected), GDALRasterPolygonEnumerator does not merge some diagonally connected pixels into the same polygon.

The attached graphic shows two examples of connected pixels that were not merged into a single polygon. In the graphic, yellow and blue pixels have the same value and should be enumerated as polygons when connected diagonally or along sides. All other pixels are masked out from polygon enumeration.

The logic in GDALRasterPolygonEnumerator::ProcessLine? is incomplete for nConnectedness = 8. Some additional checks for diagonal connectedness are needed with calls to MergePolygon?. The attached file gdalrasterpolygonenumerator_fix.cpp contains the additional checks in ProcessLine? - all changes are in lines 188-246. The fixed code has been tested on several examples and seems to work on all possible pixel configurations with diagonal connectedness.

Similar changes are probably needed in gdalrasterfpolygonenumerator.cpp (the version using float buffers).

Attachments (4)

polygon_enum_8connect_fail.png (145.9 KB) - added by ctoney 7 years ago.
gdalrasterpolygonenumerator_fix.cpp (8.8 KB) - added by ctoney 7 years ago.
4647.patch (1.8 KB) - added by Kyle Shannon 7 years ago.
patch against trunk r24372
polygonize_test.tif (2.3 KB) - added by ctoney 7 years ago.

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by ctoney

Changed 7 years ago by ctoney

comment:1 Changed 7 years ago by Kyle Shannon

Cc: Kyle Shannon added

comment:2 Changed 7 years ago by Kyle Shannon

Chris, what version are you using?

Changed 7 years ago by Kyle Shannon

Attachment: 4647.patch added

patch against trunk r24372

comment:3 Changed 7 years ago by Kyle Shannon

Added patch instead of full file.

comment:4 Changed 7 years ago by ctoney

Version: unspecified1.9.0

comment:5 Changed 7 years ago by warmerdam

Milestone: 1.9.1
Status: newassigned

It would be really nice to have a small test file that demonstrates the problem so we could extend the test suite. See samples in autotest/alg/

I also imagine this needs to be applied to the new floating point copy of the polygonization algorithm.

comment:6 Changed 7 years ago by warmerdam

Resolution: fixed
Status: assignedclosed

I have applied the change in trunk (r24379) and 1.9 (r24380) to the integer and floating point versions of the algorithm. The floating point side is untested.

Changed 7 years ago by ctoney

Attachment: polygonize_test.tif added

comment:7 Changed 7 years ago by ctoney

I've attached a small test file that demonstrates the problem of some diagonally connected polygons not merged. Pixel values are 6 or nodata.

Note: See TracTickets for help on using tickets.