I am allowing users to draw a polygon in Silverlight by clicking to draw. Then I loop through the points, convert them to longitude and latitude and then save to SQL (in a
You can check, if the result of the EnvelopeAngle()
method for the geography was 180, then use the ReorientObject()
function to correct it.
Here is the sample:
--A CW polygon
DECLARE @G3 GEOGRAPHY = 'POLYGON ((45 45, 44 45, 44 46, 45 46, 45 45))';
SELECT @G3.EnvelopeAngle(); --180
SELECT @G3.ReorientObject().STAsText(); --POLYGON ((44 46, 44 45, 45 45, 45 46, 44 46))
EDIT as stated in the comments you can may correct current geometries, using a simple update command (in the case you are sure they are not correct):
UPDATE foo_table SET bar_column = bar_column.ReorientObject()
WHERE bar_column.EnvelopeAngle() > 90