Search code examples
javageometrybufferjts

In JTS, when I do geometry.buffer(1).buffer(-1), will the resulting geometry be equivalent to the original?


I was having problems while intersecting two geometries, getting a TopologyException probably due to a rounding error during the operation, then I read this fix and tried a buffer(0) on both input geometries, but still without success. Then I tried geo.buffer(1).buffer(-1) and it worked.

Will these geometries be equivalent to the original ones?


Solution

  • I don't know anything about JTS, but it can't be true in general.

    Assume you have two shapes:

     XXX      XXX
     X X      XXX
     XXX      XXX
    

    From my understanding a buffer(1) on both would result in roughly this:

    XXXXX    XXXXX
    XXXXX    XXXXX
    XXXXX    XXXXX
    XXXXX    XXXXX
    XXXXX    XXXXX
    

    Now buffer(-1) won't be able to produce two different results from those two shapes.

    Effectively a buffer() operation looses information, so it can't be undone without re-adding that information from somewhere else.