SQL geography how to get most Northern/E/S/W/highest/lowest?

时间:2017-11-11 13:35:16

标签: sql-server sqlgeography

The geography data type is new to me and I'm trying to get my head around how to use it. I have a simple question I'm unable to find an answer for.

I have a database containing coordinates (Lat, Lon; decimal(9,6)) and elevation (smallint) data. Getting highest/lowest/most Northerly/E/S/W is pretty straight forward:

SELECT MAX(Lat) FROM Tbl     etc.

Geography data is stored as an object and as far as I can tell, to get the most Northerly point, I first need to convert all data to Lat/Lon/Elev and then look for the point with the highest Lat value. That seems like a lot of trouble for something which imo is supposed to be really simple. With that in mind i'm inclined to keep the existing data and add the geography, but that doesn't feel right to me: storing the same info twice in the same table.

Is there a simple way of getting the most Northerly point from a set coordinates stored as geography data?

2 个答案:

答案 0 :(得分:1)

您将数据存储为地理对象,以便您可以执行距离交叉点等地理位置的内容

在我的情况下,我同时保留x,y和geom。所以我可以在x,y上使用索引并在geom上执行几何函数。

答案 1 :(得分:0)

胡安的答案和他对您的问题的评论相结合似乎是最正确的答案。要重申,您可以使用

对于地理:

SELECT location.Lat as Lat, location.Long as Lon from myTable;

对于几何:

SELECT location.STY as Lat, location.STX as Lon from myTable;

但是,考虑将保留“ Lat”和“ Long”作为表的列的存储成本与动态计算这些值的性能成本进行权衡,也是一个好主意。