【问题标题】:SQL Server geography latitude longitude errorSQL Server地理纬度经度错误
【发布时间】:2019-02-13 19:41:23
【问题描述】:

我正在使用地理数据类型来计算最短距离。

CREATE TABLE Landmark (
    Id int,   
    Latitude FLOAT,
    Longitude FLOAT
)

INSERT Landmark VALUES
(1, 49.242458, -123.153465),
(2, 49.249381, -122.866683)

WITH GeographyLandmark AS
(
    SELECT Id, geography::STPointFromText('POINT(' + CAST(Latitude AS VARCHAR(20)) + ' ' + CAST(Longitude AS VARCHAR(20)) + ')', 4326) Location
    FROM Landmark
)

--this query calculates distance between point and localizations in meters
SELECT Id, geography::STPointFromText('POINT(' + CAST(49.2424566 AS VARCHAR(20)) + ' ' + CAST(-123.1534623 AS VARCHAR(20)) + ')', 4326).STDistance(Location) Distance
FROM GeographyLandmark

但我收到此错误:

在执行用户定义的例程或聚合“地理”期间发生 .NET Framework 错误: System.FormatException:24201:纬度值必须在 -90 到 90 度之间。 System.FormatException: 在 Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(双 x,双 y,Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.Validator.BeginFigure(双 x,双 y,Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(双 x,双 y,Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure(双 x,双 y,Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.WellKnownTextReader.ParsePointText(布尔 parseParentheses) 在 Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType 类型) 在 Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType 类型,Int32 srid) 在 Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType 类型,SqlChars taggedText,Int32 srid) 在 Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType 类型,SqlChars taggedText,Int32 srid) .

这里有什么问题?

【问题讨论】:

    标签: sql-server sqlgeography


    【解决方案1】:

    您的纬度和经度似乎已切换。有几点:

    1. 使用Lat 和/或Long 扩展属性进行简单的完整性检查。这是Longdoc

    2. Microsoft 的实现提供的另一个扩展是用于创建点的Point 静态方法。因此,不必为传递给STPointFromText 的点创建WKT,您只需执行geography::Point(Latitude, Longitude, SRID)。这是doc

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 2013-02-08
      • 1970-01-01
      • 2021-01-16
      • 2015-08-14
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多