1

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

I am working with SQL server 2008 and facing problems of polygon orientation.

Question is -

  1. is there any solution to validate geography polygon or change the orientation to valid geography?
  2. is it possible to copy that IsValidDetailed method from sqlserver 2012 to 2008?
  3. if I have to do it manually, then what is the correct orientation of polygon for valid geography datatype?
  4. We can validate geometry datatype in SQL server 2008, is it ok to convert geography polygon in to geometry polygon and validated it?

Please assist. Thanks in advance

Amol Patil
  • 985
  • 2
  • 11
  • 43

2 Answers2

3

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
thor
  • 21,418
  • 31
  • 87
  • 173
Alan Engel
  • 56
  • 2
0

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.

Amol Patil
  • 985
  • 2
  • 11
  • 43