2

STPolyFromText function works fine with both clock-wise and anti-clock-wise order of points when using master, but not working in anti-clock-wise mode when i use myDB. Here is my code:

use MyDB
go

DECLARE @polygon    geography    

DECLARE @clock_wise nvarchar(500)='POLYGON((35.2515 46.9657,35.2874 46.9784,35.3162 46.9466,35.3431 46.9817,35.3506 47.0122,35.3166 47.0324,35.3367 47.0541,35.3256 47.0768,35.3004 47.0673,35.2969 47.0479,35.2747 47.0527,35.2516 47.0521,35.2506 47.0146,35.2515 46.9657))'
DECLARE @anti_clock_wise nvarchar(500)='POLYGON((35.708 51.7622,35.6211 51.1277,35.4761 51.3704,35.7952 51.2544,35.5078 51.4838,35.5559 51.6161,35.7448 51.4571,35.8509 51.6945,35.8362 51.3961,35.708 51.7622))'

SET @polygon = geography::STPolyFromText(@anti_clock_wise,4326)   
select @polygon
Amid Gol
  • 305
  • 2
  • 7
  • Define "doesn't work" - do you get an error message? If so, *what* does the error say? What version of SQL Server are you using and what compatibility level is your database set to use? – Damien_The_Unbeliever Nov 30 '15 at 08:07
  • The version of Sql Server is 2012. I get this Error: Msg 6522, Level 16, State 1, Line 6 A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": System.ArgumentException: 24200: The specified input does not represent a valid geography instance. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a spatial instance to shift slightly. – Amid Gol Nov 30 '15 at 08:21
  • Which is exactly the error message you'll receive if the *database* is running in SQL Server 2008 compatibility mode. – Damien_The_Unbeliever Nov 30 '15 at 08:22
  • sorry @Damien_The_Unbeliever, version of MS SQL is 2014 and Compatibility Mode is 2008 and error message is as below: Msg 6522, Level 16, State 1, Line 6 A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": System.ArgumentException: 24200: The specified input does not represent a valid geography instance. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a spatial instance to shift slightly. System.ArgumentException: .... – Amid Gol Nov 30 '15 at 08:31

1 Answers1

1

Change your compatibility mode from SQL Server 2008 (100) to SQL Server 2012 (110).