为什么 MS Geography 抱怨这个多边形?

Why is MS Geography complaining about this polygon?

我正在尝试将一些坐标转换为地理对象。下面是一个复制问题的简单测试工具。

由于 MS Geography 需要逆时针坐标,而我不知道我所处的地理区域是什么,所以我得到了坐标,然后准备了第二组按降序排列的坐标。这不是 lat/long 到 long/lat,只是 1,2,3,4,5 到 5,4,3,2,1:

DECLARE @MyPolygon geography
DECLARE @FwdCoords varchar(max) = 'POLYGON((-33.871090 150.823941, -33.878274 150.823941, -33.878274 150.831348, -33.871090 150.831348, -33.871090 150.823941))'
DECLARE @RevCoords varchar(max) = 'POLYGON((-33.871090 150.823941, -33.871090 150.831348, -33.878274 150.831348, -33.878274 150.823941, -33.871090 150.823941))'

BEGIN TRY
    RAISERROR('Attempt to make polygon from forward string', 0, 1)
    SET @MyPolygon = geography::STPolyFromText(@FwdCoords, 4326)
    PRINT @MyPolygon.ToString()
END TRY
BEGIN CATCH
    RAISERROR('Attempt failed.  Try with reversed coordinates', 0, 1)
    IF @@ERROR <> 0
    BEGIN
        PRINT 'Proc: ' + ERROR_PROCEDURE()
        PRINT 'Line: ' + CONVERT(VARCHAR(10), ERROR_LINE())
        PRINT 'Number: ' + CONVERT(VARCHAR(10), ERROR_NUMBER())
        PRINT 'Message: ' + ERROR_MESSAGE()
    END
    BEGIN TRY
        RAISERROR('Attempt to make polygon from reversed string', 0, 1)
        SET @MyPolygon = geography::STPolyFromText(@RevCoords, 4326)
        PRINT @MyPolygon.ToString()
    END TRY
    BEGIN CATCH
        IF @@ERROR <> 0
        BEGIN
            PRINT 'Proc: ' + ERROR_PROCEDURE()
            PRINT 'Line: ' + CONVERT(VARCHAR(10), ERROR_LINE())
            PRINT 'Number: ' + CONVERT(VARCHAR(10), ERROR_NUMBER())
            PRINT 'Message: ' + ERROR_MESSAGE()
        END
    END CATCH
END CATCH

我收到以下错误

Line: 22
Number: 6522
Message: A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
System.FormatException: 
   at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParseLineStringText()
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParsePolygonText()
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParseTaggedText(OpenGisType type)
   at Microsoft.SqlServer.Types.OpenGisWktReader.Read(OpenGisType type, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

多边形是正方形。最后一个坐标匹配第一个坐标。查看坐标,它们都在 lat/lng,所有纬度 = -33.something,都在 -90 到 90 的范围内

据我所知,我对无效的经纬度没有任何问题。为什么 MS Geography 认为我相信?

您已经调换了纬度和经度值。你如何向自己证明这一点?

DECLARE @g GEOGRAPHY = geography::STPointFromText('POINT(10 20)', 4326)

SELECT @g.[Lat]; --returns 20

因此,WKT 表示将成对(经度、纬度)。