How to validated geography polygon in SQL server 2008?

后端 未结 2 1512
[愿得一人]
[愿得一人] 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:17

    I found solution, SQL Server Saptial Tools

    http://sqlspatialtools.codeplex.com/

    Followings are the methods solved my problem.

    IsValidGeographyFromText(string inputWKT, int srid)

    Check if an input WKT can represent a valid geography. This function requires that the WTK coordinate values are longitude/latitude values, in that order and that a valid geography SRID value is supplied. This function will not throw an exception even in edge conditions (i.e. longitude/latitude coordinates are reversed to latitude/longitude).

    SqlGeography MakeValidGeographyFromText(string inputWKT, int srid)

    Convert an input WKT to a valid geography instance. This function requires that the WKT coordinate values are longitude/latitude values, in that order and that a valid geography SRID value is supplied.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题