Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert geometry to lat and long

Tags:

sql-server

I found in my database that shops location represented as geometry datatype.

Is it possible to convert to lat and long coordinates and use it as input for bing maps?

enter image description here

like image 422
Bill Gates Avatar asked Feb 28 '13 00:02

Bill Gates


2 Answers

Jan 2020: The previous formats shown threw the following error:

OperationalError: (1054, "Unknown column 'geometry_col.Long' in 'field list'")

However, this format worked:

SELECT ST_X(geometry_col) AS longitude,
       ST_Y(geometry_col) AS latitude
FROM yourTable;
like image 74
girlthatCANeven Avatar answered Sep 27 '22 22:09

girlthatCANeven


This works for geometry types in sql server

SELECT  [Geometry].STX AS [Longitude],
    [Geometry].STY AS [Latitude]
FROM YourTable
like image 33
mp7 Avatar answered Sep 27 '22 22:09

mp7