sql空间数据给出了错误的答案

时间:2013-10-11 07:52:48

标签: sql spatial

我真的不知道该怎么办..

DECLARE @g geography = geography::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))',4326)
DECLARE @g2 geography =geography::STGeomFromText( 'POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))',4326)
Declare @union  geography  =  @g2.STUnion(@g)   
Declare @diff  geography  =  @g2.STDifference(@g)   

SELECT @g.STArea() + @g2.STArea() - @union.STArea()

SELECT  @union.STArea()+@diff.STArea()

ret:“12306061878,1564”      “123060620496,501” 找出5个差异......

附加:

 select @union.ToString()

ret

POLYGON ((0 2, 0 0, 2 0, 2.0000000000000591 1.0001522971041397, 3 1, 3 3, 1 3, 1.0000000000000655 2.0003044086154023, 0 2))

1 个答案:

答案 0 :(得分:0)

我真的不明白你的问题。我的猜测是,您可能期望使用Geometry代替Geography提供的结果:

DECLARE @g geometry = geometry::STGeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))',4326)
DECLARE @g2 geometry =geometry::STGeomFromText( 'POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))',4326)
Declare @union  geometry  =  @g2.STUnion(@g)   
Declare @diff  geometry  =  @g2.STDifference(@g)   

SELECT @g.STArea() + @g2.STArea() - @union.STArea()    
SELECT  @union.STArea()+@diff.STArea()
select @union.ToString()

返回:

POLYGON ((0 0, 2 0, 2 1, 3 1, 3 3, 1 3, 1 2, 0 2, 0 0))