簡體   English   中英

在多邊形 mysql 中選擇點 - 沒有錯誤,沒有結果 -(出了什么問題?)

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

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

我已經嘗試使用下面的這兩個查詢來查看多邊形內的點。 沒有錯誤也沒有結果,雖然應該出現兩行

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並中斷

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM