From John Armstrong:
AIUI, the process works by finding edges on a data grid. The edges are
assembled into polygons, each of which may be part of the region of
interest or a hole in that region. To test, it tries to find an interior
point of the polygon to check if it's "inside" or "outside". Usually it's
enough to use com.vividsolutions.jts.algorithm.InteriorPointArea, but if
that fails the backup plan is to walk around each vertex and check the
point one grid-cell-width to the right.
The problem comes up when the grid polygon is an L-shape, like
Here, the InteriorPointArea gives a point on the upper edge of the "right
arm" of the shape, which isn't an interior point. Then we check an offset
away from all six vertices, all of which are either on the boundary or
outside the polygon. The algorithm throws an exception and Dies Horribly.
The solution is to move right and up by half a grid cell. Every grid
polygon must have at least one lower-left corner (proof left as exercise to
reader), for which this offset will give a point within a grid cell
contained within the interior of the polygon. In terms of the code, line
427 should be changed from
c.y = ringC.y;
c.y = ringC.y + cellWidthY / 2;
and the algorithm will work as intended.