包含MySQL函数 - 意外结果

时间:2014-04-07 11:28:07

标签: mysql sql contains spatial contain

我在MySQL 5.5.35上使用Debian 7 x86_64服务器。我试图检查点是否在矩形内。我以这种方式使用Contains函数:

SELECT Contains
(
    Polygon
    (
        Point(55.538322,37.332026),
        Point(55.566347,37.875850),
        Point(55.898002,37.873103),
        Point(55.896459,37.381465),
        Point(55.538322,37.332026)
    ),
    Point(55.737177,37.623164)
)

这一点显然在矩形内,我希望获得1输出,但我得到的是(NULL)

你能指出我的错误吗?谢谢!

更新:经过一些调试后,NULL函数返回Polygon。这就是问题所在。

2 个答案:

答案 0 :(得分:1)

你可以尝试这个sintax

SELECT
MBRContains(
    GeomFromText('Polygon((55.538322 37.332026,55.566347 37.87585,55.898002 37.873103,55.896459 37.381465,55.538322 37.332026))'),
    GeomFromText('Point(55.737177 37.623164)'));

答案 1 :(得分:1)

阅读reference后,我发现Polygon函数希望它的参数类型为LineString。正确的例子是:

SELECT
Contains
(
   Polygon
   (
        LineString
        (
          Point(55.538322,37.332026),
          Point(55.566347,37.875850),
          Point(55.898002,37.873103),
          Point(55.896459,37.381465),
          Point(55.538322,37.332026)
        )
    ),
    Point(55.737177,37.623164)
)