Unexpexcted behaviour STGeomFromText

  • Hey guys,

    I've got a weird behavior of SQL-Server regarding spatial objects here.  The code from below defines a postal code area in Frankfurt, Germany as a linestring. I want to transform this to a polygon, to check if some points are liying within this area.  But the resulting polygon is way bigger, than the original area of the linestring.  Even stranger is, that this code works as soon as I change the datatype from geography to geometry.  All the other German postal code areas can be converted to geography using this method. Is there an explanation why this one area can not?

    DECLARE @geo geography;

    SET @geo = geography::STGeomFromText('LINESTRING (8.6720136 50.110756800000004, 8.6730391 50.1111221, 8.6736415 50.110477100000004, 8.6735392 50.110440800000006, 8.6733426 50.110371400000005, 8.673323 50.110364800000006, 8.6732403 50.110337, 8.6731607 50.1103083, 8.6729404 50.1102288, 8.6726428 50.1101158, 8.6723155 50.110397500000005, 8.6720136 50.110756800000004)', 4326);



    SELECT @geo AS geo

    ,@geo.STSrid

    ,@geo.STAsText() AS WKText

    ,replace(@geo.STAsText(), 'LINESTRING ', 'POLYGON (') + ')' AS PolyText

    ,geography::STGeomFromText(replace(@geo.STAsText(), 'LINESTRING ', 'POLYGON (') + ')', @geo.STSrid) AS newGeography

    ,geometry::STGeomFromText(replace(@geo.STAsText(), 'LINESTRING ', 'POLYGON (') + ')', @geo.STSrid) AS newGeometry;

     

     

    Thanks in advance!

    Sebastian

  • Hi, folks!

    A collaegue of mine found the solution right here:

    https://alastaira.wordpress.com/2012/01/27/ring-orientation-bigger-than-a-hemisphere-polygons-and-the-reorientobject-method-in-sql-server-2012/

    Kind regards!

    Sebastian

  • Thanks for adding the solution!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply