简体   繁体   中英

How to convert the SQL geometry type to latitude (-90,90) and longitude (-180,180) in mssql?

I have a list of data with geometry column in the format of 0x6A7F0000010D340AF .

I wand to retrieve the latitude and longitude in the range of (-90,90) and (-180,180) . I have tried the following code:

select geom.STY as lat, geom.STX as lon 
from Table;

However, it returns values in the range of 5058449.313 for latitude and longitude.

Any idea what I should do? Can I also use Python to do the conversion? How can I get the CRS from the geom?

Update-Solution

Assuming that I know the CRS , I can use this code to get the latitude and longitude from the (Y,X) retrieved from

select geom.STY as lat, geom.STX as lon 
from Table;

STX and STY return X-coordinate and Y-coordinate property of a Point instance. here is what you need:

SELECT  
    geom.Long AS [Longitude]
    ,geom.Lat AS [Latitude]
FROM [Table]

Someone else has posted a proposed answer and the ensuing conversation has boiled down to "use geography instead of geometry ". I agree!

But you also rightfully observe that you have what you have. And so my suggestion would be to get with whomever was responsible for writing the data and figure out how they stored latitude and longitude. That will get you a long way towards figuring out how to extract it from the extant data. Without knowing that, all you (and we) can do is speculate/guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM