How to validated geography polygon in SQL server 2008?

后端 未结 2 1545
[愿得一人]
[愿得一人] 2021-01-15 19:03

In the SQL Server 2012 there is methods to validate geography \'.IsValidDetailed()\' and to change orientation \'.ReorientObject (geography)\'.

I am working with SQ

2条回答
  •  长情又很酷
    2021-01-15 19:25

    This is working for me on SQL Server 2008. After loading the shape as a geometry, use MakeValid() to correct it, then reload into a geography.

    declare @gt nvarchar(max)
    declare @gm geometry
    declare @gmvalid geometry
    
    set @gmvalid = @gm.MakeValid()
    
      set @gt = @gmvalid.STAsText()
    
      --select @gt
      if LEFT(@gt,7 ) = 'POLYGON'
      begin
      set @gg = geography::STPolyFromText(@gt, 4326)
      end
      else
      begin
      set @gg = geography::STMPolyFromText(@gt, 4326)
      end
    

提交回复
热议问题