简体   繁体   English

在多边形 mysql 中选择点 - 没有错误,没有结果 -(出了什么问题?)

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

I've got a table in my MySQL database called property我的 MySQL 数据库中有一个名为 property 的表

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

I've tried with those two queries below to view points within a polygon.我已经尝试使用下面的这两个查询来查看多边形内的点。 There is no error and no result, although two rows supposed to appear没有错误也没有结果,虽然应该出现两行

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

And

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

I can't figure out why there no result.我不明白为什么没有结果。

ps: I've checked that the polygon completely contains two points (35.489623, 6.250875) and (35.489341, 6.250135) ps:我检查过多边形完全包含两个点 (35.489623, 6.250875) 和 (35.489341, 6.250135)

Theres 3 issues有3个问题

Firsly geomfromtext is the wrong function.首先geomfromtext是错误的功能。 You should be using PolygonFromText你应该使用PolygonFromText

Secondly syntax, You need 2 brackets in the polygon function example第二种语法,多边形函数示例中需要 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))')

Thirly (This is also fixed above) You do not have a closed polygon, Your last point and first point should be equal第三(这也是上面固定的)你没有一个封闭的多边形,你的最后一点和第一点应该相等

In your example the polygon code was returning null and breaking在您的示例中,多边形代码返回null并中断

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM