Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#4 Probably another Bug in Geometry.buffer() function

open
nobody
None
5
2010-08-06
2010-08-06
Tim Braun
No

I've noticed an error when applying the Geometry.buffer(0) function to sets of overlapping polygons which contains corner points that lie almost exactly on a line segment of another polygon. I've reproduced the error on JTS 1.11 with these 3 polygons:

POLYGON ((9.498610949113157 49.44573068278185, 9.496805881714552 49.45008850097656, 9.52316778975428 49.51373177689611, 9.586811065673828 49.54009368493584, 9.599867820739746 49.54015472009209, 9.663511096659294 49.51379281205236, 9.689873004699022 49.45014953613281, 9.663511096659294 49.38650626021327, 9.652138534851769 49.381795590873665, 9.6505487553507 49.377957523641, 9.586905479431152 49.35159561560127, 9.523262203511605 49.377957523641, 9.496900295471876 49.44160079956055, 9.498610949113157 49.44573068278185))
POLYGON ((9.804362 49.616291, 9.806154 49.611965, 9.779792 49.548322, 9.716148 49.52196, 9.703035 49.521914, 9.639392 49.548276, 9.637896 49.551888, 9.626208 49.556729, 9.599846 49.620373, 9.626208 49.684016, 9.637686 49.68877, 9.639256 49.692561, 9.702899 49.718923, 9.716019 49.718965, 9.779662 49.692603, 9.806024 49.62896, 9.804296 49.624788, 9.806089 49.620461, 9.804362 49.616291))
POLYGON ((9.67465213101146 49.41340309644513, 9.659931768895953 49.41785440902986, 9.596288768895954 49.444216409029856, 9.576815259852522 49.4546253801569, 9.563633843100538 49.463076654098764, 9.546564989012161 49.47708430271717, 9.53255697899898 49.494152860218534, 9.522698019576143 49.51259765136085, 9.52316778975428 49.51373177689611, 9.612745197217588 49.65151417322354, 9.6215832528899 49.650674976203874, 9.64297076400082 49.644214430291164, 9.706614039920368 49.61785252225143, 9.726086871323453 49.60744407701799, 9.743154950799092 49.593436666192154, 9.757162361624928 49.57636858671651, 9.767570806858368 49.55689575531343, 9.77239183086882 49.545256773762866, 9.67465213101146 49.41340309644513))

The effect can be triggered by loading the three polygons into an Geometry array 'geoms' and then calling buffer(0) on a GeometryCollection built from it:

new GeometryFactory().createGeometryCollection(geoms).buffer(0);

The Input and output Geometries are attached as images.

Btw: I've noticed that using buffer(0.000001) instead of buffer(0) avoids the erroneous union - but I consider this only a brittle workaround.

Is there any advice on avoiding this problem in a robust fashion?

Discussion