Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jts-dev] Polygon empty as a result of small buffer

Are you sure that you are using the correct scale factor for the PrecisionModel?  Don't forget that scale factors are the reciprocal of the grid size.  So the specified scale factor of 0.00001 actually results in the *input* Polygon being collapsed completely to (0,0).  Also, it is the client's responsibility to ensure that coordinates for geometries are consistent with the PrecisionModel scale, which in this case they are not.

Perhaps you meant to use a scale factor of 10000?  (The input coordinates are still not consistent with that scale factor, but in this case it probably doesn't affect the result).

When I use a scale factor of 10000 to load:

POLYGON((72.0 254.374516,  72.0 394.253883,  216.0 394.253883,  216.0 254.374516,  72.0 254.374516))

and run buffer(-0.001) I get the expected result of:

POLYGON ((72.001 254.3755, 72.001 394.2529, 215.999 394.2529, 215.999 254.3755, 72.001 254.3755))





On Tue, Sep 28, 2021 at 6:46 AM Meyer Montagner Murcian <mmontagner@xxxxxxxxxxxxxx> wrote:
Dear JTSers,

since updating to version 1.18.2, I've found a behaviour that wasn't present on the previous version and I'm not sure how to handle. When applying a small negative buffer to a valid polygon, I'm sometimes receiving an empty polygon as a result.  The following test replicates the problem:

@Test
void jtsSmallBuffer() {
PrecisionModel precisionModel = new PrecisionModel(0.00001d);
GeometryFactory jtsGeometryFactory = new GeometryFactory(precisionModel);

Coordinate[] shell = new Coordinate[5];
int i = 0;
shell[i++] = new Coordinate(72.000000, 254.374516);
shell[i++] = new Coordinate(72.000000, 394.253883);
shell[i++] = new Coordinate(216.000000, 394.253883);
shell[i++] = new Coordinate(216.000000, 254.374516);
shell[i] = new Coordinate(72.000000, 254.374516);

Polygon polygon = jtsGeometryFactory.createPolygon(shell);

Geometry bufferedPolygon = BufferOp.bufferOp(polygon, -0.001);

Assertions.assertFalse(bufferedPolygon.isEmpty());

}

This tests passes on version 1.18.1  or when the scae value passed to the precision model is reduced. Digging a bit, the cause of the empty polygon is OffsetCurveSetBuilder::192, wich determines that the resulting curve "isTooClose"  (a value of 9.830507833896718E-4 in maxDist, wich is lowe than 9.9E-4).

What is the intention when returning an empty polygon in the new version? 

May this be a bug or is it caused by an incorrect use of the PrecisionModel?

Any help or insights are very appreciated. Thank you all.

Kind regars,

Meyer M

_______________________________________________
jts-dev mailing list
jts-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://dev.eclipse.org/mailman/listinfo/jts-dev

Back to the top