简体   繁体   English

C#SqlGeography纬度和经度意外行为

[英]c# SqlGeography latitude & longitude unexpected behavior

Microsoft.SqlServer.Types.SqlGeography.ToString has unexpected behavior. Microsoft.SqlServer.Types.SqlGeography.ToString具有意外的行为。

Take a look at my unit test: 看一下我的单元测试:

 latitude = 40.584474F;
 longitude = -111.633491F;
 var location = SqlGeography.Point( latitude, longitude, 4326 );
 var point = location.ToString();

At this point, the variable point has a value of: POINT (-111.63349151611328 40.58447265625) 此时,可变点的值为:POINT(-111.63349151611328 40.58447265625)

As you can see, latitude and longitude have been swapped from the norm. 如您所见,纬度和经度已从规范中互换。

This is from a nuget package downloaded today. 这是从今天下载的nuget软件包中获得的。 (v11.0.2) (v11.0.2)

Clarification: Object values are correct but ToString() is producing a format which is not appropriate to SQL Server itself, even though this is a SQLServer specific class in my opinion. 澄清:对象值正确,但是ToString()生成的格式不适用于SQL Server本身,即使我认为这是特定于SQLServer的类。

Update 2: This is not a duplicate because it is different from the question with a similar title, since this is about a .NET class (Microsoft.SqlServer.Types.SqlGeography.ToString), rather than SQL Server itself. 更新2:这不是重复项,因为它与具有类似标题的问题有所不同,因为它是关于.NET类(Microsoft.SqlServer.Types.SqlGeography.ToString),而不是SQL Server本身。

The latitude and longitude have not been swapped. 纬度和经度尚未交换。 It's just that the Point() constructor accepts the longitude after latitude, but in ToString() longitude is printed before latitude. 只是Point()构造函数在纬度之后接受经度,但是在ToString()经度在纬度之前打印。

Print the values location.Lat and location.Long to know for sure. 打印值location.Latlocation.Long肯定知道。

SQL Server 12 will accept: geography::Point(47.65100, -122.3490, 4326). SQL Server 12将接受:geography :: Point(47.65100,-122.3490,4326)。 To produce the string that would be acceptable to SQL Server: 要产生SQL Server可接受的字符串:

var point = ColValue as SqlGeography;
if (point != null)
return "geography::Point(" + point.Lat + ", " + point.Long + ", 4326)";

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

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