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.
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.