一台服务器上的几何错误,但具有相同数据的另一台服务器上没有
Geometry error on one server but not the other with same data
我有一个包含大约 400 行地理数据的 table,我正在使用 STWithin
方法来确定一个点是否存在于这些行的边界内。
在我的测试服务器上它工作正常。但是,对于最新版本的数据集,在这些数据行之一的实时服务器上查询失败。如果我从查询中排除该行,那么它就会成功。
错误是:
Msg 6522, Level 16, State 1, Line 3
A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry": System.ArgumentException: 24144: This operation cannot be completed because the instance is not valid. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a geometry instance to shift slightly.
查询的简化版本是:
DECLARE @Point GEOMETRY = GEOMETRY::Point(416420, 345058, 0)
SELECT *
FROM PolygonData
WHERE @Point.STWithin(GeoField) = 1
测试服务器是SQL Server 2012 (11.0.2100.60),正式服务器是SQL Server 2012 (11.0.6544.0)。
我不明白为什么相同的数据在一台服务器上成功而在另一台服务器上失败?非常感谢任何帮助,谢谢。
原来table里面有无效数据。将其添加为答案,同时还添加了一种方法来修复 table.
中的数据update t
set g = g.MakeValid()
from dbo.yourTable as t
where t.g.STIsValid() = 0;
(将 yourTable
和 g
分别替换为实际 table 和列的名称)通过一次性更新错误数据,您不会招致在 select 时间调用 MakeValid()
的开销(因为大概读取比写入更频繁)。您还可以为您执行的任何后续数据加载实现类似上述的内容。