简体   繁体   English

如何在 mssql 中将 SQL 几何类型转换为纬度(-90,90)和经度(-180,180)?

[英]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 .我有一个带有几何列的数据列表,格式为0x6A7F0000010D340AF

I wand to retrieve the latitude and longitude in the range of (-90,90) and (-180,180) .我想检索(-90,90)(-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.但是,它返回5058449.313范围内的纬度和经度值。

Any idea what I should do?知道我应该做什么吗? Can I also use Python to do the conversion?我也可以使用 Python 进行转换吗? How can I get the CRS from the geom?如何从 geom 获取CRS

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假设我知道CRS ,我可以使用此代码(Y,X)检索到的latitudelongitude

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. STX 和 STY 返回 Point 实例的 X 坐标和 Y 坐标属性。 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 ".其他人发布了一个建议的答案,随后的对话归结为“使用geography而不是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.在不知道这一点的情况下,您(和我们)所能做的就是推测/猜测。

如何在坐标(纬度,经度)中计算截然相反的坐标,其中-90 <lat<90 and -180<lon<180< div><div id="text_translate"><p> 给定坐标点 X=(lat, lon) 和圆心 C=(lat_center, lon_center) 我想计算点 X 截然相反的坐标(假设 X 在圆心为 C 的圆内) .</p><p> 例如,如果 C=(45.9, 180),则与 X=(45.9, -179) 截然相反的值应该是 (45.9, 179)。</p><p> 以下 function 是一个近似值,但不能解决纬度在 (-90, 90) 和经度 (-180, 180) 之间的问题。</p><pre> def f(lat, lon, center): lat_center = center[0] lon_center = center[1] dist_lon = np.abs(lon - lon_center) if np.abs(lon - lon_center)&lt;180 else 360 - np.abs(lon - lon_center) dist_lat = np.abs(lat - lat_center) if np.abs(lat - lat_center)&lt;180 else 360 - np.abs(lat - lat_center) lon_op = lon_center + dist_lon if lon_center + dist_lon.= lon else lon_center - dist_lon lat_op = lat_center + dist_lat if lat_center + dist_lat,= lat else lat_center - dist_lat return np,round(lat_op. 2), np.round(lon_op, 2)</pre> </div></lat<90> - How to calculate diametrically opposite in coordinates(lat, lon) where -90<lat<90 and -180<lon<180

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在坐标(纬度,经度)中计算截然相反的坐标,其中-90 <lat<90 and -180<lon<180< div><div id="text_translate"><p> 给定坐标点 X=(lat, lon) 和圆心 C=(lat_center, lon_center) 我想计算点 X 截然相反的坐标(假设 X 在圆心为 C 的圆内) .</p><p> 例如,如果 C=(45.9, 180),则与 X=(45.9, -179) 截然相反的值应该是 (45.9, 179)。</p><p> 以下 function 是一个近似值,但不能解决纬度在 (-90, 90) 和经度 (-180, 180) 之间的问题。</p><pre> def f(lat, lon, center): lat_center = center[0] lon_center = center[1] dist_lon = np.abs(lon - lon_center) if np.abs(lon - lon_center)&lt;180 else 360 - np.abs(lon - lon_center) dist_lat = np.abs(lat - lat_center) if np.abs(lat - lat_center)&lt;180 else 360 - np.abs(lat - lat_center) lon_op = lon_center + dist_lon if lon_center + dist_lon.= lon else lon_center - dist_lon lat_op = lat_center + dist_lat if lat_center + dist_lat,= lat else lat_center - dist_lat return np,round(lat_op. 2), np.round(lon_op, 2)</pre> </div></lat<90> - How to calculate diametrically opposite in coordinates(lat, lon) where -90<lat<90 and -180<lon<180 GeoDjango是否要在[-180 -90,180 90]范围内进行协调? - GeoDjango wanting coordinated in range [-180 -90, 180 90]? 如何在python中将字符或字符串旋转90或180度? - How to rotate a character or string by 90 or 180 degree in python? 使用 python 和 tensorflow 旋转 90、180 和 270 - Rotation of 90, 180 and 270 using python and tensorflow Django会员资格(选择30,90,180天)和它的逻辑 - Django membership (choices 30, 90, 180 days) and it`s logic 如何将纬度标准化为-90到90? - how to normalise latitude into the range of -90 to 90? 将经度从 -180 更改为 180 到 0 到 360 - Change longitude from -180 to 180 to 0 to 360 ValueError:操作数不能与形状(224,224)(180,180)一起广播 - ValueError: operands could not be broadcast together with shapes (224,224) (180,180) 如何按纬度在 90 到 -90 范围内拆分 dataframe - How to split dataframe by latitude in ranges from 90 to -90 python-shapefile将几何转换为纬度/经度 - python-shapefile convert geometry to latitude/longitude
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM