Bug #46498 Intersection of polygon and multipolygon does not return all intersected geoms
Submitted: 31 Jul 18:27 Modified: 31 Jul 22:21
Reporter: John Powell
Status: Verified
Category:Server: GIS Severity:S2 (Serious)
Version:mysql-5.1-wl1326 OS:Linux (centos 64-bit 5.2)
Assigned to: Alexey Botchkov Target Version:
Tags: multipolygon, intersection
Triage: Triaged: D2 (Serious)

[31 Jul 18:27] John Powell
Description:
In some cases, the intersection of a polygon with a multipolygon, does not return all of
the polygons of the multipolygon that are intersected.

How to repeat:
The multipolygon for the first step will be uploaded separately below, as too large for
initial report.

mysql> set @geom=geomfromtext('MULTIPOLYGON(((........

establish that we have a multipolygon.

mysql> select numgeometries(geom) from @geom;
+---------------------+
| numgeometries(geom) |
+---------------------+
|                   8 |
+---------------------+
1 row in set (0.00 sec)

mysql> select geometrytype(geom) from @geom;
+--------------------+
| geometrytype(geom) |
+--------------------+
| MULTIPOLYGON       |
+--------------------+
1 row in set (0.00 sec)

find centroid of this multipolygon

mysql> select astext(centroid(@geom));
+------------------------------------------+
| astext(centroid(@geom))                  |
+------------------------------------------+
| POINT(499857.070505126 166856.759010446) |
+------------------------------------------+

create a rectangular polygon with centroid of geometry as top right

mysql> set @bbox=geomfromtext('POLYGON((499857 166856, 0 166856, 0 0, 499857 0, 499857
166856))');

create intersection of box and geometry

mysql> set @int=intersection(@geom,@bbox);

show that this has created a single polygon with a tiny area

mysql> select geometrytype(@int);
+--------------------+
| geometrytype(@int) |
+--------------------+
| POLYGON            |
+--------------------+

mysql> select area(@int);
+-----------------+
| area(@int)      |
+-----------------+
| 1309.3600000029 |
+-----------------+

now, explicitly create a new geom equal to the biggest polygon in the original
multipolygon

mysql> set @geom1=geometryn(@geom,1);

take the intersection again with @bbox again

mysql> set @int1=intersection(@geom,@bbox);

show area

mysql> select area(@int1);
+------------------+
| area(@int1)      |
+------------------+
| 5399156347.52692 |
+------------------+

This could be equally demonstrated by testing using intersects and geometryn

mysql> select intersects(@bbox,geometryn(@geom,1));
+--------------------------------------+
| intersects(@bbox,geometryn(@geom,1)) |
+--------------------------------------+
|                                    1 |
+--------------------------------------+

So, although the bbox intersects with all 8 of the polygons in the multipolygon
represented by @geom, only one of them is returned by the intersection function.
[31 Jul 18:30] John Powell
geometry for bug 46498

Attachment: geom.zip (application/x-zip-compressed, text), 334.56 KiB.

[31 Jul 22:21] Miguel Solorzano
Thank you for the bug report.

mysql> select intersects(@bbox,geometryn(@geom,1));
+--------------------------------------+
| intersects(@bbox,geometryn(@geom,1)) |
+--------------------------------------+
|                                    1 | 
+--------------------------------------+
1 row in set (0.17 sec)

mysql>