Bug #62757 MBR Within not giving accurate results
Submitted: 16 Oct 2011 9:10 Modified: 1 Aug 2012 14:35
Reporter: newbie Shai Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: GIS Severity:S1 (Critical)
Version:5.0.77, 5.0.91, 5.1.58, 5.5.16 OS:Any
Assigned to: CPU Architecture:Any
Tags: Accuracy of MBR Within

[16 Oct 2011 9:10] newbie Shai
Description:
Dear All,
        I have been using the MBRWithin function for quite a lot of times. Suddenly I notice on google map this POINT(101.11857 4.34475) is out of the geo fence which I specify but it still give a value of 1 in mysql any reason or is this a bug in the MBRWithin itself?

SELECT MBRWithin(GeomFromText('POINT(101.11857 4.34475)'),GeomFromText('POLYGON((101.12112522125244 4.3531723687957164,101.11846446990967 4.351417913665312,101.13138198852539 4.336397898951581,101.13477230072021 4.33211863778494,101.14065170288086 4.321933898868271,101.14992141723633 4.306699328215635,101.15455627441406 4.30978050198082,101.1397933959961 4.334600612212089,101.12112522125244 4.3531723687957164,101.12112522125244 4.3531723687957164))')) As geoFenceStatus

How to repeat:
Some values only it happens other is fine.
[17 Oct 2011 10:53] Valeriy Kravchuk
Thank you for the problem report. Verified with current versions also:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -proot -P3312
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.16-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql> SELECT MBRWithin(GeomFromText('POINT(101.11857
    '> 4.34475)'),GeomFromText('POLYGON((101.12112522125244
    '> 4.3531723687957164,101.11846446990967 4.351417913665312,101.1313819885253
9
    '> 4.336397898951581,101.13477230072021 4.33211863778494,101.14065170288086
    '> 4.321933898868271,101.14992141723633 4.306699328215635,101.15455627441406

    '> 4.30978050198082,101.1397933959961 4.334600612212089,101.12112522125244
    '> 4.3531723687957164,101.12112522125244 4.3531723687957164))')) As geoFence
Status;
+----------------+
| geoFenceStatus |
+----------------+
|              1 |
+----------------+
1 row in set (0.06 sec)
[17 Oct 2011 14:57] newbie Shai
Dear Valeriy,
             I know the results is 1 but on the map the point is out of the polygong that is my problem not the query. So my concern is the accuracy of the the MBRWithin?
[1 Aug 2012 11:59] Alexander Barkov
The Polygon consists of these points:

p0=101.12112522125244  4.3531723687957164
p1=101.11846446990967  4.351417913665312
p2=101.13138198852539  4.336397898951581
p3=101.13477230072021  4.33211863778494
p4=101.14065170288086  4.321933898868271
p5=101.14992141723633  4.306699328215635
p6=101.15455627441406  4.30978050198082
p7=101.1397933959961   4.334600612212089
p8=101.12112522125244  4.3531723687957164
p9=101.12112522125244  4.3531723687957164

MBR for the above polygon is
{xmin = 101.11846446990967, ymin = 4.3066993282156352, 
 xmax = 101.15455627441406, ymax = 4.3531723687957165}

where

xmin comes from p1
ymin comes from p5
xmax comes from p6
ymax comes from p8

The point 'POINT(101.11857, 4.34475)' is inside this MBR:

101.11846446990967 < 101.11857 <  101.15455627441406
4.3066993282156352 < 4.34475   <  4.3531723687957165

So the query returns a correct result.
[1 Aug 2012 14:35] newbie Shai
Dear Alexander Barkov,
                      So basically MBR is just like drawing a rectangle around and take that as the basis is it?