Search code examples
mysqlsqlcontainsspatialcontain

Contains MySQL function - unexpected result


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.


Solution

  • After reading the reference I'ver found out that the Polygon function expects it's parameters to be of type LineString. The correct example is:

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