我在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
。这就是问题所在。
答案 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)
)