Bug #64653 ST_Contains() reports that a polygon does not contain itself
Submitted: 15 Mar 2012 1:19 Modified: 5 Oct 2012 17:04
Reporter: Benjamin Morel Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: GIS Severity:S3 (Non-critical)
Version:5.6.4 m7, 5.6.5 m8 OS:Any
Assigned to: CPU Architecture:Any
Tags: Geometry, gis, polygon, spatial, ST_Contains

[15 Mar 2012 1:19] Benjamin Morel
Description:
This bug has probably the same roots as the following bug:
http://bugs.mysql.com/bug.php?id=64649

In the example below, we're checking whether a polygon contains itself. PostGIS reports true, MySQL reports false.

How to repeat:
SET @a = ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 4326);
SELECT ST_Contains(@a, @a);

Expected result: 1
Actual result: 0
[15 Mar 2012 7:55] Valeriy Kravchuk
Thank you for the bug report. Verified with current mysql-trunk also:

[openxs@chief trunk]$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.5-m8-debug Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET @a = ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 4326);
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT ST_Contains(@a, @a);
+---------------------+
| ST_Contains(@a, @a) |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)
[11 Sep 2012 14:18] Reinis Rozitis
Present in 5.6.6 m9 too.
[5 Oct 2012 17:04] Paul DuBois
Noted in 5.6.8, 5.7.0 changelogs.

ST_Contains() and ST_Within() incorrectly reported that a polygon did
not contain itself. ST_Equals() incorrectly returned 0 for polygons
that differed only in shifted vertices.