是的,我知道这个问题曾经问过很多时间,但是从2012年开始,所有问题似乎已经过时了,问题/问题的基础, 我试图用列POINT执行经典搜索距离 但我有些麻烦无法解决..
是正常的,我的POINT列看起来像这样吗?
0x00000000010100000085B1852007052040C0B2D2A414684840
这是我的所有步骤,我无法看到什么是错的, 我根据最后的堆栈问题/答案做了。
我使用mariadb 10和Heideisql gui。
我有2张拉特和伦, 我创建了一个geopoints POINT列, 像这样填充地点:
UPDATE geoFRA
SET geopoints = GeomFromText(CONCAT('POINT (', lon, ' ', lat, ')'))
之后我的geopoints列如下所示:
0x00000000010100000085B1852007052040C0B2D2A414684840
然后我尝试以2个方式执行查询,首先尝试:
SET@lat = 48.88;
SET@lon = 2.34;
SELECT *
FROM geoFRA
WHERE MBRContains(LineFromText(CONCAT(
'('
, @lon + 700 / ( 111.1 / cos(RADIANS(@lon)))
, ' '
, @lat + 700 / 111.1
, ','
, @lon - 700 / ( 111.1 / cos(RADIANS(@lat)))
, ' '
, @lat - 700 / 111.1
, ')' )
,geopoints)
第二次尝试:
SET@lat = 48.88;
SET@lon = 2.34;
SET @kmRange = 172; -- = 50 Miles
SELECT *, (3956 * 2 * ASIN(SQRT(POWER(SIN((@lat - abs(`lat`)) * pi()/180 / 2),2) + COS(@lat * pi()/180 ) * COS(abs(`lat`) * pi()/180) * POWER(SIN((lon - `lon`) * pi()/180 / 2), 2)))) as distance
FROM `geoFRA`
WHERE MBRContains(LineString(Point(@lat + @kmRange / 111.1, @lon + @kmRange / (111.1 / COS(RADIANS(@lat)))), Point(@lat - @kmRange / 111.1, @lon - @kmRange / (111.1 / COS(RADIANS(@lat))))), `geopoints`)
Order By distance
我开始认为有一些mariadb不兼容?还是我错过了什么?
感谢您的帮助.., flau
答案 0 :(得分:1)
CREATE TABLE geoFRA (id int NOT NULL, geopoints point NOT NULL);
INSERT INTO geoFRA (id, geopoints) VALUES
(1, geomFromText('POINT(48 2)')),
(2, geomFromText('POINT(48 3)')),
(3, geomFromText('POINT(48.88 2.34)')),
(4, geomFromText('POINT(49 2)')),
(5, geomFromText('POINT(49 3)'));
SET @p=geomFromText('POINT(48.88 2.34)');
SELECT X(geopoints), Y(geopoints), asText(geopoints), ST_Distance(geopoints, @p) as d
FROM geoFRA
ORDER BY d;
这将返回按距离排序的地理输出。使用没有X()的地理输出,Y()和asText()以标准二进制(WKB)格式返回它们:http://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html#gis-wkb-format