我的 MySQL 数据库中有一个名为 house
的表。
在 house
表中,有几个名为 latitude
和 longitude
的文本列。
我添加了一个名为 coords
的新列,类型为 point
- http://dev.mysql.com/doc/refman/5.0/en/gis-class-point.html
如何将 latitude
和 longitude
值移动到新的 coords
列中?
最佳答案
假设您希望在此列上有一个 SPATIAL
索引:
ALTER TABLE mytable ADD coords Point;
UPDATE mytable
SET coords = Point(lon, lat);
ALTER TABLE mytable MODIFY coords POINT NOT NULL;
CREATE SPATIAL INDEX sx_mytable_coords ON mytable(coords);
如果你不这样做,你可以省略最后两个步骤。
更新:
在早期版本的 MySQL
中,您需要使用 WKT
填充 Point
列:
UPDATE mytable
SET coords = GeomFromText(CONCAT('POINT (', lon, ' ', lat, ')'))
关于mysql - 将经纬度文本列移动到 'point' 类型的列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5756232/