[英]Find the distance between two points in MYSQL. (using the Point Datatype)
[英]Distance between two POINT values in MySQL in a loop
我正在將幾何數據存儲在MySQL數據庫中
--------------------------------------------------
| ID | SPATIAL_INDEX | COORDS | DISTANCE |
| 1 | ... | POINT(0.5,0.5) | 0 |
| 2 | ... | POINT(0.7,0.7) | ? |
---------------------------------------------------
坐標來自2D笛卡爾跟蹤系統。 如何用一行的坐標到最后一行的距離填充DISTANCE列?
Row 1: Distance = 0;
Row 2: Distance = Distance between coords of row 1 and row 2
Row 3: Distance = Distance between coords of row 2 and row 3
[...]
SQL具有特殊的空間功能,可以計算兩點之間的距離。 您可以使用它加上表本身上的聯接來實現所需的功能。
UPDATE tablename AS a
LEFT JOIN tablename AS b
ON b.id = a.id-1
SET a.distance = IFNULL(DISTANCE(a.coord,b.coord),0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.