Search code examples
sql-servergeometrygeographysqlgeographywkt

SQL WKT draws well with geometry, but not with geography data type


I have a following piece of code

DECLARE @g geometry;
DECLARE @borders geography;   
SET @g = geometry::STGeomFromText('SOME WKT', 0); 
SET @borders = GEOGRAPHY::STGeomFromText(@g.MakeValid().STAsText(),4326)
SELECT @g;
SELECT @borders;

Since it's too long to paste it here, WKT Can be fond at this link: https://justpaste.it/6qw0a

Can someone please explain to me, why it displays well when I draw it as geometry, but when I try to draw it as a geography, it displays entire world instead of a small group of islands.

Here's the screenshot: enter image description here


Solution

  • DECLARE @geom GEOMETRY = 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))';
    DECLARE @geog GEOGRAPHY = @geom.MakeValid().STUnion(@geom.STStartPoint()).STAsText()
    

    This topic had the answer to my question