Why is a specific polygon being rejected by SQL Server as invalid?

image

Here is a small bit of WKT that represents a polygon that stretches from roughly the coast of British Columbia to the shores of Lake Ontario:

You can visualize this using https://arthur-e.github.io/Wicket/sandbox-gmaps3.html and see that it is "fine".

BUT.. SQL Server does not like it. The following query returns 0 (false... ie the geometry is invalid):

And to add to the weirdness if I use SQL's "MakeValid" the resulting polygon is sort of the same but not really. At the BC end it's very narrow, and then in SK it branches out to wider. Here's the resulting MakeValid polygon:

I don't have a lot of experience with GIS.

The polygon is valid as a geometry but not as a geography.

There is a vertex in the upper section of the polygon but not on the lower segment. As a geometry (in brown below) it looks fine, but since geography uses great circle arcs instead of straight lines, the vertex becomes below the lower arc, resulting in a self intersection (and an odd looking multipart polygon, in green below)

PS: the green polygon is how it looks like in geography. If converted back to a geometry it would look like the one you have posted.



You can use geometry instead of geography, or you can add more vertices to the original polygon before casting it to geography... but then the use of geography becomes questionable :-)

Ask AI
#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70