从mysql中的点构造lineString

时间:2014-12-21 07:51:46

标签: mysql spatial-query mysql-spatial

给出下表(职位)

+--------------------+---------------------+------+-----+---------+----------------+
| Field              | Type                | Null | Key | Default | Extra          |
+--------------------+---------------------+------+-----+---------+----------------+
| position_id        | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment |
| vehicle_id         | int(11) unsigned    | YES  | MUL | NULL    |                |
| location           | point               | NO   |     | NULL    |                |
| gps_time           | datetime            | NO   |     | NULL    |                |
+--------------------+---------------------+------+-----+---------+----------------+

我想从位置列的点构造一个lineString来计算距离。

如何从位置列构造lineString? 像

这样的东西
select vehicle_id, lineString(location) from position group by vehicle_id order by gps_time;

这是数据

select position_id,vehicle_id,astext(location),gps_time from position order by gps_time;

+-------------+------------+-----------------------------+---------------------+
| position_id | vehicle_id | astext(location)            | gps_time            |
+-------------+------------+-----------------------------+---------------------+
|           3 |          1 | POINT(44.23912 15.307647)   | 2014-11-23 06:02:17 |
|           2 |          1 | POINT(44.240063 15.307788)  | 2014-11-23 08:54:11 |
|           1 |          1 | POINT(44.23884 15.307585)   | 2014-11-23 11:50:10 |
|           4 |          1 | POINT(44.232296 15.304604)  | 2014-11-24 07:24:29 |
|           5 |          1 | POINT(44.2332 15.304803)    | 2014-11-24 07:24:39 |
|           6 |          1 | POINT(44.2332 15.304803)    | 2014-11-24 07:24:49 |
|           7 |          1 | POINT(44.23428 15.3052)     | 2014-11-24 07:24:59 |
+-------------+------------+-----------------------------+---------------------+

我想计算特定gps_time期间点之间的距离。 即position_id = 3的点与position_id = 2的点之间的距离,然后将使用position_id = 2的点与position_id = 1的点之间的距离来计算结果。

预期结果如:

+------------+------------- +--------------------+---------------------+
| vehicle_id | distance(km) | start_time         | end_time            |
+------------+------------- +--------------------+---------------------+
|          1 |          1.2 |2014-11-23 06:02:17 | 2014-11-24 07:24:59 |
+------------+------------- +--------------------+---------------------+ 

距离值(1.2)只是我心中的一个随机值。它应该从以前的点计算。

0 个答案:

没有答案