mysql update geo point

2019-05-06 23:28发布

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…

2条回答
啃猪蹄的小仙女
2楼-- · 2019-05-07 00:18

Do you mean to do this?:

UPDATE locationtable AS a
SET a.geopoint = POINT( a.latitude, a.longitude ) 
查看更多
够拽才男人
3楼-- · 2019-05-07 00:18

Try this:

UPDATE locationtable a SET geopoint = GeomFromText( 'POINT(a.latitude a.longitude)' ) WHERE 1
查看更多
登录 后发表回答