mysql point 距离,查找MYSQL中两点之间的距离。 (使用点数据类型)

Suppose I have a 2 column table like this:

| user_id | int(11) | NO | UNI | NULL | |

| utm | point | NO | MUL | NULL | |

As you can see, it's very simple. utm is a Point data-type. I insert it like this:

INSERT INTO mytable(user_id, utm) VALUES(1, PointFromWKB(point(50, 50)));

Then, I create a Spatial index.

ALTER TABLE mytable ...add spatial index on(utm) or something. (forgot)

Alright, everything is good. Now , I want to select * where distance < 99999.

But it doesn't work!

//This is supposed to select all where the distance is less than 99999999.

set @mypoint = PointFromWKB(point(20,20))

select * from mytable where GLength(LineString(utm, @mypoint)) < 9999999;

Empty set (0.00 sec)

select * from mytable where GLength(LineStringFromWKB(LineString(utm, @mypoint))) < 9999;

Empty set (0.00 sec)

By the way, I have tried to INSERT INTO without the PointFromWKB...and it didn't work...that's why someone suggested that PointFromWKB to me.

解决方案

Solved. This is what I did:

where GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(@mypoint)))) < 9999999999999;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值