簡體   English   中英

多邊形內的mysql查詢點 - 沒有結果

[英]mysql query points within polygon - no results

我很確定我在這里犯了很多錯誤,但我不確定是什么......

表格(減去幾個字段):

CREATE TABLE IF NOT EXISTS `stuff` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `lat` decimal(12,7) NOT NULL,
  `lon` decimal(12,7) NOT NULL,
  `location` point NOT NULL,  
  UNIQUE KEY `id` (`id`),
  KEY `distance` (`distance`),
  KEY `lat` (`lat`),
  KEY `lon` (`lon`),
  SPATIAL KEY `location` (`location`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5;

自動設置位置點的觸發器:

DROP TRIGGER IF EXISTS `stuff_insert_defaults`;
DELIMITER //
CREATE TRIGGER `stuff_insert_defaults` BEFORE INSERT ON `stuff`
 FOR EACH ROW SET NEW.location = PointFromText(CONCAT('POINT(',NEW.lat,' ',NEW.lon,')'))
//
DELIMITER ;

DROP TRIGGER IF EXISTS `stuff_update_location`;
DELIMITER //
CREATE TRIGGER `stuff_update_location` BEFORE UPDATE ON `stuff`
 FOR EACH ROW SET NEW.location = PointFromText(CONCAT('POINT(',NEW.lat,' ',NEW.lon,')'))
//
DELIMITER ;

一些樣本數據(科羅拉多州內4個隨機點):

/* 4 random points within the state of colorado */
INSERT INTO `stuff` (`id`, `distance`, `lat`, `lon`, `location`) VALUES
(1, 5.0000000, 40.2488450, -103.8003460, 0x000000000101000000f6622827da1f444001df6dde38f359c0),
(2, 5.0000000, 38.4849180, -107.8726700, 0x000000000101000000f19e03cb113e4340d28c45d3d9f75ac0),
(3, 5.0000000, 39.5040250, -105.3584800, 0x000000000101000000e6ae25e483c0434049111956f1565ac0),
(4, 5.0000000, 39.1904180, -106.8179680, 0x000000000101000000ed48f59d5f9843402b4b749659b45ac0);

科羅拉多州粗糙的外圍邊界:

NW corner: 41.000497 -109.050149 
NE corner: 41.002380 -102.051881 
SE corner: 36.993237 -102.041959 
SW corner: 36.999037 -109.045220 

應該返回我們插入的4條記錄的查詢:

SELECT *, AsText(location) FROM stuff 
 WHERE Contains(
 GeomFromText('POLYGON((41.000497 -109.050149, 41.002380 -102.051881, 36.993237 -102.041959, 36.999037 -109.045220, 41.000497 -109.050149))'), location );

我要回來的......

nada... 
zip... 
nil... 
nothing...

Polygon (強調添加):

Polygon斷言

  • Polygon的邊界由一組LinearRing對象(即簡單和封閉的 LineString對象)組成,構成其外部和內部邊界。

因此,您必須通過在起點處完成來關閉多邊形:

SELECT *, AsText(location) FROM stuff 
 WHERE Contains(
 GeomFromText('POLYGON((41.000497 -109.050149, 41.002380 -102.051881, 36.993237 -102.041959, 36.999037 -109.045220, 41.000497 -109.050149))'), location );

sqlfiddle上看到它。

暫無
暫無

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

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