# [geos-devel] [GEOS] #755: Overlay ops accept GeometryCollections when headers indicate that they don't

GEOS geos-trac at osgeo.org
Thu May 27 19:00:13 PDT 2021

```#755: Overlay ops accept GeometryCollections when headers indicate that they
don't
------------------------+---------------------------
Reporter:  dbaston     |       Owner:  geos-devel@…
Type:  defect      |      Status:  new
Priority:  major       |   Milestone:  3.10.0
Component:  Default     |     Version:  3.5.0
Severity:  Unassigned  |  Resolution:
Keywords:              |
------------------------+---------------------------

Comment (by Mike Taves):

I don't think these operations are working as expected. Here is an odd
example with shapely with GEOS 3.9.1:

{{{#!python
from shapely.geometry import Point, GeometryCollection

poly_list = [Point(i, 0).buffer(0.7, resolution=10) for i in range(2)]
A = GeometryCollection(poly_list)
res = A.difference(Point(1, 0).buffer(0.2))
print(res)
}}}
the result is "POLYGON EMPTY". If the first geometry were replaced with a
unary-unioned polygon, the result would be a normal looking polygon with a
hole punched thru.

The odd thing is when the number of coordinates used in the
!GeometryCollection is reduced, an exception is raised:
{{{#!python
poly_list = [Point(i, 0).buffer(0.7, resolution=9) for i in range(2)]
A = GeometryCollection(poly_list)
res = A.difference(Point(1, 0).buffer(0.2))
# TopologyException: side location conflict at 0.5 -0.4861824369638621
}}}

----

A PostGIS 2.5.2 / GEOS 3.6.2 equivalent of the example is:
{{{
-- runs, but returns GEOMETRYCOLLECTION EMPTY
SELECT ST_AsText(ST_Difference(a, b))
FROM (
SELECT
as a,
as b
) f;

-- ERROR:  lwgeom_difference: GEOS Error: TopologyException: side location
conflict at 0.5 -0.4861824369638621
SELECT ST_AsText(ST_Difference(a, b))
FROM (
SELECT
as a,
as b
) f;
}}}

----

Unless there is a robust solution to get expected behaviour with
consistent results, GEOS should do what JTS does and raise an error if one
of the inputs is a !GeometryCollection.

On a related note, I see the
[https://postgis.net/docs/manual-2.2/ST_Difference.html PostGIS 2.2 manual
for ST_Difference] note "Do not call with a !GeometryCollection as an
argument", but this appears to be removed from the current release. Was
this intentional?

--
Ticket URL: <https://trac.osgeo.org/geos/ticket/755#comment:11>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).
```