简体   繁体   English

如何找到沿折线 Mysql 的最近距离

[英]How To find the nearest distance along a polyline Mysql

I am building a ride sharing application.我正在构建一个拼车应用程序。

The application has a feature for searching drivers.该应用程序具有搜索驱动程序的功能。

The drivers (employees in a work hub) can choose a route to their destination from the app.司机(工作中心的员工)可以从应用程序中选择前往目的地的路线。

The passengers, who also belong to the work hub, and are within the route, can join their ride.同样属于工作中心并且在路线内的乘客可以加入他们的行程。

This is accomplished by search functionality after user enter their destination in the app.这是在用户在应用程序中输入目的地后通过搜索功能完成的。

Here is the table structure of rides这是游乐设施的表结构

id  driver_id path
 1     1       BLOB 

Here driver id is the id of driver and path is the line string from drivers source to destination.For the sake of simplicity I won't include other fields这里driver id是 driver 的 id, path是从驱动程序源到目的地的行字符串。为了简单起见,我不会包含其他字段

My task is to find all the drivers who passes through my location with 85% or above ride match我的任务是找到所有经过我的位置且匹配率达到 85% 或以上的司机

After having a look at Mysql spatial Types https://dev.mysql.com/doc/refman/8.0/en/spatial-types.html I wrote a query of my own which looks partially ok, Please see the query below After having a look at Mysql spatial Types https://dev.mysql.com/doc/refman/8.0/en/spatial-types.html I wrote a query of my own which looks partially ok, Please see the query below

set @g1=ST_GeomFromText('LINESTRING(10.013059 76.363075,10.0168011
 76.34592529999999,10.0161831
 76.34368020000001,10.0118 76.3218,9.99848 76.311936,9.9771685 76.2773228
)');
SET @g2 = ST_GeomFromText('Point(10.0141713 76.33320359999999
)');
 
 SELECT MBRCovers(@g1,@g2)

works fine Point(10.0141713 76.33320359999999) is between Point(10.013059 76.363075) and point(9.9771685 76.2773228)工作正常Point(10.0141713 76.33320359999999)Point(10.013059 76.363075) and point(9.9771685 76.2773228)之间

but this won't work但这行不通

 set @g1=ST_GeomFromText('LINESTRING(10.013059 76.363075,10.0168011
 76.34592529999999,10.0161831
 76.34368020000001,10.0118 76.3218,9.99848 76.311936,9.9771685 76.2773228
)');
SET @g2 = ST_GeomFromText('Point(10.0185876 76.3439941
)');
 
 SELECT MBRCovers(@g1,@g2)

Point(10.0185876 76.3439941) is also between Point(10.013059 76.363075) and point(9.9771685 76.2773228) , Point(10.0185876 76.3439941)也在Point(10.013059 76.363075) and point(9.9771685 76.2773228)之间,

I think I need to add some covering distance for the above point to return true which I am not aware about.我认为我需要为上述point添加一些覆盖距离才能返回我不知道的 true。

I am expecting above 85 % of ride match.我预计骑行匹配率超过 85%。

What I mean by that is user is not necessary belongs to the line string the driver chosen, small tolerances are allowed.我的意思是用户不必属于驱动程序选择的线串,允许小公差。

I am using mysql version 8.我正在使用 mysql 版本 8。

Please help.请帮忙。

set @g1=ST_GeomFromText('LINESTRING(10.013059 76.363075, 10.0168011 76.34592529999999, 10.0161831 76.34368020000001, 10.0118 76.3218, 9.99848 76.311936, 9.9771685 76.2773228)', 4326); SET @g2 = ST_GeomFromText('Point(10.0141713 76.33320359999999)', 4326); SELECT ST_Distance(@g1, @g2, 'metre');
 | | ST_Distance(@g1, @g2, 'metre') | ST_Distance(@g1, @g2, '米') | | | -----------------------------: | -----------------------------------------: | | | 9.402168864952756 | 9.402168864952756 |
 set @g1=ST_GeomFromText('LINESTRING(10.013059 76.363075, 10.0168011 76.34592529999999, 10.0161831 76.34368020000001, 10.0118 76.3218, 9.99848 76.311936, 9.9771685 76.2773228)', 4326); SET @g2 = ST_GeomFromText('Point(10.0185876 76.3439941)', 4326); SELECT ST_Distance(@g1, @g2, 'metre');
 | | ST_Distance(@g1, @g2, 'metre') | ST_Distance(@g1, @g2, '米') | | | -----------------------------: | -----------------------------------------: | | | 247.0472114965831 | 247.0472114965831 |

db<>fiddle here db<> 在这里摆弄

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM