Select 多边形内的点 mysql - 没有错误,没有结果 -(有什么问题?)

Select points within polygon mysql - No errors, no results-(What is wrong?)

我的 MySQL 数据库中有一个名为 属性

的 table
CREATE TABLE IF NOT EXISTS `property` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `latitude` double NOT NULL,
  `longitude` double NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT ;

INSERT INTO `property` (`id`, `latitude`, `longitude`) VALUES
                       ( 1,   35.489623,   6.250875),
                       ( 2,   35.489341,   6.250135),
                       ( 3,   36.749996,   5.059664),
                       ( 4,   36.749996,   5.059664);

我已经尝试使用下面的两个查询来查看多边形内的点。 没有错误也没有结果,虽然应该出现两行

SELECT id FROM `property` WHERE
ST_Contains( GeomFromText('POLYGON(35.49088 6.25108,35.48954 6.24853,35.48732 6.25164,35.48912 6.25381,35.49109 6.2525)'),
             POINT(property.latitude, property.longitude)
            )

SELECT id FROM `property` WHERE
ST_Contains( GeomFromText('POLYGON(35.49088 6.25108,35.48954 6.24853,35.48732 6.25164,35.48912 6.25381,35.49109 6.2525)'),
             GeomFromText( CONCAT( 'POINT(', property.latitude, ' ', property.longitude, ')' ) )
           )

我想不通为什么没有结果。

ps:我检查过多边形完全包含两个点 (35.489623, 6.250875) 和 (35.489341, 6.250135)

有 3 个问题

首先geomfromtext是错误的功能。你应该使用 PolygonFromText

其次语法,在多边形函数示例中需要 2 个括号

 select  PolygonFromText('POLYGON((35.49088 6.25108,35.48954 6.24853,35.48732 6.25164,35.48912 6.25381,35.49109 6.2525, 35.49088 6.25108))')

第三(这也是上面固定的)你没有封闭的多边形,你的最后一个点和第一个点应该相等

在您的示例中,多边形代码返回 null 并中断