Question

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.

Était-ce utile?

La solution 2

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

Autres conseils

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)'));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top