SQL Server 2012, geography.STContains, wrong result?

前端 未结 1 1755
天命终不由人
天命终不由人 2021-01-20 01:51

I\'m using SQL Server 2012, geography.STContains (documentation) and I don\'t get why the code below fails.

If I switch to geometry it wor

相关标签:
1条回答
  • 2021-01-20 02:32

    Now I found the issue. The user drew the polygon starting lower-right and went clockwise. If I reorder the points from biggest latitude and then go counterwise by sorting on long, lat it works. Found a helper for it, but that only works if you "know it's wrong":

    if(sqlGeography.EnvelopeAngle() > 90)
        sqlGeography ? sqlGeography.ReorientObject();
    

    Just put together a small solution that will fix my values: https://github.com/danielwertheim/GeographyFactory

    and a blogpost about it: http://danielwertheim.se/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position/

    and a follow up about the real "issue", the left-hand rule:

    http://danielwertheim.se/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position-no/

    0 讨论(0)
提交回复
热议问题