In the SQL Server 2012 there is methods to validate geography \'.IsValidDetailed()\' and to change orientation \'.ReorientObject (geography)\'.
I am working with SQ
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.
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