我有一个奇怪的 MySQL 空间搜索行为。
我在 GEOM 字段(葡萄牙边界)中创建了一个多边形,然后我试图在里面找到一个点——发现它没问题。
下一个尝试是找到一个多边形之外的点,但查询仍然返回 1 个找到的行。
请帮忙,我做错了什么?为什么它会在多边形外找到一个点?
用于测试的 SQL 代码如下:
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`bounds` geometry NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `test` (`id`, `bounds`) VALUES (null, GEOMFROMTEXT('POLYGON((-8.876953125 41.8695608269946,-8.7451171875 41.9839942709356,-8.63525390625 42.0656067540572,-8.162841796875 42.1389684045809,-8.0859375 42.0248136078178,-8.23974609375 41.8859210281474,-8.15185546875 41.8204550961403,-7.899169921875 41.918628865183,-7.40478515625 41.8204550961403,-7.174072265625 41.9104534766642,-7.130126953125 42.0003251483162,-6.52587890625 41.951319946797,-6.50390625 41.6811175629065,-6.15234375 41.590796851056,-6.427001953125 41.2695495028426,-6.646728515625 41.2282490151853,-6.85546875 41.0296433871664,-6.8115234375 40.3549167507906,-7.03125 40.2334119071151,-6.866455078125 40.0213046873971,-6.9927978515625 39.687110247163,-7.53936767578125 39.6125651748163,-7.34024047851563 39.4820504550432,-7.22969055175781 39.1871628720445,-6.96533203125 39.0618491342915,-7.064208984375 38.8824811975508,-7.27294921875 38.7198047426424,-7.31689453125 38.3890334067591,-7.0751953125 38.2295504553262,-6.92550659179688 38.223077534953,-6.98799133300781 37.9994092820024,-7.20428466796875 37.9831748335134,-7.5421142578125 37.5707052423312,-7.44873046875 37.1953305828007,-7.91015625 36.985003092856,-8.32763671875 37.1252862849668,-8.63525390625 37.1340453712645,-8.98681640625 37.0025526721596,-8.7945556640625 37.6098799437471,-8.89617919921875 37.9463634508748,-8.800048828125 38.2295504553262,-8.90167236328125 38.5116391414586,-9.2230224609375 38.4320766853821,-9.23675537109375 38.6705005336435,-9.5361328125 38.7112325389523,-9.349365234375 39.364032338048,-8.8330078125 40.1956590933647,-8.822021484375 40.5096228495967,-8.61328125 41.0710691308064,-8.843994140625 41.4303718826528,-8.876953125 41.8695608269946))'));
http://i.crisp-studio.cz/i/080e83c5bd3f3a27c3ecab9086a3.png
里面:
SELECT *
FROM `test`
WHERE CONTAINS(`bounds`, geomfromtext('Point(-8.050232 39.882343)'))
外部:
SELECT *
FROM `test`
WHERE CONTAINS(`bounds`, geomfromtext('Point(-6.663208 40.05495)'))