0

I am using MySQL 5.5.35 server on Debian 7 x86_64. I am trying to check if the point is within the rectangle. I use the Contains function this way:

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)
)

The point is obviously within the rectangle and I was expecting to get the 1 output, but what I am getting is (NULL).

Could you please point me my mistake? Thank you!

Update: after some debug it comes out the the NULL is return by the Polygon function. So that is the problem.

4

2 回答 2

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)'));
于 2014-04-07T12:10:22.077 回答
1

阅读参考资料后,我发现该Polygon函数期望它的参数是 type 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)
)
于 2014-04-07T13:44:34.257 回答