Bug #46372 buffer of linestring returns multipolygon in certain cases
Submitted: 24 Jul 2009 15:31 Modified: 7 Aug 2012 12:27
Reporter: John Powell Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: GIS Severity:S3 (Non-critical)
Version:mysql-5.1-wl1326 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: buffer, gis, linestring, multipolygon

[24 Jul 2009 15:31] John Powell
Description:
For some linestrings, the buffer function returns a multipolygon, when the output should always be a single polygon, possibly with inner rings. The 2nd geometry in the multipolygon is a single, repeated point. It is easy to work around this bug, but it could cause confusion.

How to repeat:
create geometry from linestring -- attached below, as too long for initial report

buffer by 100m and select geometry type of output

mysql>set @buff=buffer(@geom,100); select geometrytype(@buff);
+---------------------+
| geometrytype(@buff) |
+---------------------+
| MULTIPOLYGON        | 
+---------------------+

select the 2nd geometry of this multipolygon

mysql> select astext(geometryn(@buff,2));
+------------------------------------------------------------------------+
| astext(geometryn(@buff,2))                                             |
+------------------------------------------------------------------------+
| POLYGON((447495.42 1201570.5,447495.42 1201570.5,447495.42 1201570.5)) | 
+------------------------------------------------------------------------+

The output is a single, repeated point.
[24 Jul 2009 15:32] John Powell
linestring to create geometry for buffering

Attachment: ls.csv (text/csv), 40.12 KiB.

[24 Jul 2009 17:48] MySQL Verification Team
Thank you for the bug report. Verified as described:

mysql> set @buff=buffer(@geom,100); select geometrytype(@buff);
Query OK, 0 rows affected (1 min 8.05 sec)                     

+---------------------+
| geometrytype(@buff) |
+---------------------+
| MULTIPOLYGON        |
+---------------------+
1 row in set (0.00 sec)

mysql> select astext(geometryn(@buff,2));
+------------------------------------------------------------------------+
| astext(geometryn(@buff,2))                                             |
+------------------------------------------------------------------------+
| POLYGON((447495.42 1201570.5,447495.42 1201570.5,447495.42 1201570.5)) |
+------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show variables like "%version%";
+-------------------------+---------------------+
| Variable_name           | Value               |
+-------------------------+---------------------+
| protocol_version        | 10                  |
| version                 | 5.1.35-debug        |
| version_comment         | Source distribution |
| version_compile_machine | x86_64              |
| version_compile_os      | unknown-linux-gnu   |
+-------------------------+---------------------+
5 rows in set (0.01 sec)

mysql>
[25 Nov 2009 17:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/91672

2663 Alexey Botchkov	2009-11-24
      Bug#46372 buffer of linestring returns multipolygon in certain cases 
         mistake in the algorithm - dx_dy parameter should be just dx if
         dy is 0.
      
      per-file comments:
        sql/gcalc_slicescan.cc
      Bug#46372 buffer of linestring returns multipolygon in certain cases 
           GET_DX_DY fixed
        sql/gcalc_slicescan.h
      Bug#46372 buffer of linestring returns multipolygon in certain cases 
           some debugging features added
        sql/item_geofunc.cc
      Bug#46372 buffer of linestring returns multipolygon in certain cases 
           debugging code added
[5 Dec 2009 15:07] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/92967

2664 Alexey Botchkov	2009-12-04
      Bug#46372      buffer of linestring returns multipolygon in certain cases
          there was a mistake in handling of 'holes' in the polygons.
          Fixed by adding the 'first_poly_node' pointer to the res_point
          structure to point to the first point of the surrounding polygon.
          Also a set of debugging functions was added. It doesn't affect the
          working fucntions, but greatly simplifies the debugging.
          This path fixes also bug#46498 and bug#45883 also.
      
      per-file comments:
        sql/gcalc_slicescan.cc
      Bug#46372      buffer of linestring returns multipolygon in certain cases
        sql/gcalc_slicescan.h
      Bug#46372      buffer of linestring returns multipolygon in certain cases
        sql/gcalc_tools.cc
      Bug#46372      buffer of linestring returns multipolygon in certain cases
        sql/gcalc_tools.h
      Bug#46372      buffer of linestring returns multipolygon in certain cases
        sql/item_geofunc.cc
      Bug#46372      buffer of linestring returns multipolygon in certain cases
        sql/spatial.cc
      Bug#46372      buffer of linestring returns multipolygon in certain cases
[28 Apr 2010 10:21] John Powell
The bug as stated is fixed, however the problem of buffers producing mutlipolygons remains, if the points are very close together.

set @ls=geomfromtext('LINESTRING(1000 1000, 1000.01 1000.01)');

select geometrytype(buffer(@ls,2));
+-----------------------------+
| geometrytype(buffer(@ls,2)) |
+-----------------------------+
| MULTIPOLYGON                |
+-----------------------------+

mysql> select numgeometries(buffer(@ls,2));
+------------------------------+
| numgeometries(buffer(@ls,2)) |
+------------------------------+
|                            3 |
+------------------------------+
[7 Aug 2012 12:27] Alexander Barkov
This bug was earlier fixed in mysql-gis tree (before mysql-5.6 release).