geos icon indicating copy to clipboard operation
geos copied to clipboard

Union has incorrect results for some GeometryCollection inputs

Open ergpudb opened this issue 3 years ago • 5 comments

Taking the union (using Geometry::Union) of POLYGON ((0 0, 0 1, 1 1, 0 0)) and MULTIPOINT (0 0, 99 99) produces GEOMETRYCOLLECTION (POLYGON ((0 1, 1 1, 0 0, 0 1)), POINT (99 99)), which is correct (albeit with the polygon in the result starting at a different vertex).

However, taking the union of POLYGON ((0 0, 0 1, 1 1, 0 0)) and GEOMETRYCOLLECTION (MULTIPOINT (0 0, 99 99)) produces POLYGON ((0 1, 1 1, 0 0, 0 1)), which has lost the point (99 99).

ergpudb avatar Oct 06 '22 14:10 ergpudb

Yap the GEOMETRYCOLLECTION part is tripping it up.

I see the same issue on GEOS main and my production GEOS 3.10.2

robe2 avatar Oct 10 '22 02:10 robe2

See also GEOS Trac issue 755.

dr-jts avatar Oct 11 '22 15:10 dr-jts

This behaviour is due to the fact that GEOS overlay now uses OverlayNG. OverlayNG does not support GeometryCollections as input. This case should cause an error, but a coding bug actually has the effect that no error is reported, just an incorrect result.

A: In the short term this could be fixed by ensuring an error is thrown. In GEOS this should end up delegating to the old overlay code, which handles this case correctly. (@pramsey @dbaston thoughts ?)

B: Medium term upgrade is to handle "simple" GCs. Simple GCs are ones which are equivalent to valid Multi geometries (i.e. are homogeneous and which contain no overlapping Polygons).

C: Longer term full support for GC inputs could be added to OverlayNG.

Note that this particular case was handled by the old overlay code. However, the old overlay code does not appear to handle GCs in general. It may just handle Simple GCs - more research required.

dr-jts avatar Oct 12 '22 17:10 dr-jts

JTS has added OverlayNG support for simple GeometryCollections in https://github.com/locationtech/jts/pull/915.

This handles the homogeneous collection cases in this issue.

dr-jts avatar Oct 19 '22 00:10 dr-jts

Interesting that these cases were supported by GEOS but removing that support apparently produced no test failures in GEOS or PostGIS?

dbaston avatar Oct 19 '22 13:10 dbaston

I'd have to go back and dig, but any tests we may have had (and maybe we had none) would have come out / been turned off at OverlayNG switchover. I think it's possible we just didn't have any, I have no recollection of taking them out.

pramsey avatar Oct 19 '22 15:10 pramsey

The support in old GEOS overlay may have been just accidental. As far as I can see it was not documented.

dr-jts avatar Oct 19 '22 17:10 dr-jts