mysql update geo point

人走茶凉 提交于 2019-12-07 07:50:51

问题


I have a MySQL table with latitude and longitude values. I want to play around with the spatial stuff in MySQL 5, just to see how it works.

However, I'm having a real problem just getting the point data created from existing values. I was trying something like this, but it fails with syntax errors in every format I've tried. Can someone point out the right way to do this?

UPDATE locationtable a SET geopoint = GeomFromText( POINT() a.latitude a.longitude ) WHERE 1

I've also tried other variations, including:

UPDATE locationtable a SET geopoint = GeomFromText( 'POINT()' a.latitude a.longitude ) WHERE 1

UPDATE locationtable a SET geopoint = GeomFromText( 'POINT() a.latitude a.longitude' ) WHERE 1

And others…


回答1:


Do you mean to do this?:

UPDATE locationtable AS a
SET a.geopoint = POINT( a.latitude, a.longitude ) 



回答2:


Try this:

UPDATE locationtable a SET geopoint = GeomFromText( 'POINT(a.latitude a.longitude)' ) WHERE 1


来源:https://stackoverflow.com/questions/8954417/mysql-update-geo-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!