SQL Spatial polygon inside out

后端 未结 5 2679
攒了一身酷
攒了一身酷 2021-02-19 21:27

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

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 22:11

    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
    

提交回复
热议问题