Bug #46372 buffer of linestring returns multipolygon in certain cases
Submitted: 24 Jul 17:31 Modified: 25 Nov 18:06
Reporter: John Powell
Status: Patch pending
Category:Server: GIS Severity:S3 (Non-critical)
Version:mysql-5.1-wl1326 OS:Any
Assigned to: Alexey Botchkov Target Version:
Tags: gis, buffer, linestring, multipolygon
Triage: Triaged: D2 (Serious)

[24 Jul 17: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 17:32] John Powell
linestring to create geometry for buffering

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

[24 Jul 19:48] Miguel Solorzano
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 18: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