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.

Kolyunya
  • 5,973
  • 7
  • 46
  • 81

2 Answers2

1

You may try this 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)'));
AlexF
  • 487
  • 1
  • 5
  • 16
  • Thank you for you response. The syntax you have suggested does work for me. Maybe you know why mine does not work? Thank you! – Kolyunya Apr 07 '14 at 12:14
  • Sincerely I think that for spatial relations you need to use precise functions (MBRContains and not just contains) just as explained on the mysql dev site http://dev.mysql.com/doc/refman/5.6/en/functions-for-testing-spatial-relations-between-geometric-objects.html For the rest I don't know why doesn't works without the 'GeomFromText' keyword, but I've always used this sintax getting it from the Mysql site. – AlexF Apr 07 '14 at 13:28
  • I've found out what my error was and posted the answer which may be useful to someone else. – Kolyunya Apr 07 '14 at 13:45
1

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)
)
Kolyunya
  • 5,973
  • 7
  • 46
  • 81