views:

156

answers:

2

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?

+2  A: 

I don't think these geometries will be the same. By default behavior buffering a feature add vertices to it's original configuration, and there is no guarantee that the same vertices will be removed.

Try doing a very small buffer, a.buffer(0.00001), for instance (1/1000th mm, if coordinates in metric systems).

In PostGIS some issues are corrected by doing this.

George
I did this, but with a very small value. We are using geographic coordinates.
Pablo Cabrera
it should "correct" itself. GEOS and other GEOS based software works. If i'm not mistaken GEOS is based on a JTS port.
George
+1  A: 

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.

Joachim Sauer