【发布时间】:2016-07-28 00:53:36
【问题描述】:
我正在尝试将一些坐标转换为地理对象。下面是一个复制问题的简单测试工具。
由于 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 中,所有 lats = -33.something,在 -90 到 90 的范围内
据我所知,我对无效的纬度或经度没有任何问题。为什么 MS Geography 相信我这样做?
【问题讨论】:
标签: sql-server tsql sqlgeography