How to check valid polygon RRS feed

  • Question

  • Hello sir

    i am taking a geograpy datatype in sqlsever2008.

    i am cut the polygon on to the map and insert in to the table

    but some times giving the following error or sometimes not!

    Msg 6522, Level 16, State 1, Line 2
    A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
    Microsoft.SqlServer.Types.GLArgumentException: 24205: The specified input does not represent a valid geography instance because it exceeds a single hemisphere. Each geography instance must fit inside a single hemisphere. A common reason for this error is that a polygon has the wrong ring orientation.
       at Microsoft.SqlServer.Types.GLNativeMethods.ThrowExceptionForHr(GL_HResult errorCode)
       at Microsoft.SqlServer.Types.GLNativeMethods.GeodeticIsValid(GeoData g)
       at Microsoft.SqlServer.Types.SqlGeography.IsValidExpensive()
       at Microsoft.SqlServer.Types.SqlGeography.ConstructGeographyFromUserInput(GeoData g, Int32 srid)
       at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
       at Microsoft.SqlServer.Types.SqlGeography.STGeomFromText(SqlChars geometryTaggedText, Int32 srid)


    please give me some idea what can i do for that condition.

    Wednesday, May 12, 2010 5:43 AM

All replies

  • Hello Umar,

    Please consider the "Left-Hand-Rule": If you walk (in mind) from one point to the next, the inner area is on your left side. So you have to define the points of a polygon counter-clockwise.

    That's the reason for "... it exceeds a single hemisphere ..." in the error message, your area is "outside the polygon" or it is really larger the a hemisphere?

    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    • Proposed as answer by Tom Li - MSFT Thursday, May 20, 2010 5:29 AM
    Wednesday, May 12, 2010 6:02 AM
  • Thanks for the reply Olaf Sir

    then what can i do

    i want to show the mesage for the user.

    polygon is valid or it is not valid polygon when it draw on the map.

    b'cause user draw any thing means user dont know what is clock or anti clock wise!

    you are understanding my problem!

    Wednesday, May 12, 2010 7:12 AM
  • Wrap your method that attempts to insert the polygon into your DB in a try/catch block. If the try fails with an exception 24205 then you can send a message back to the user, asking them to redraw the polygon.

    Alternatively, you can try to 'fix' the polygon they submitted to use the correct ring-orientation using the technique described in the link given by VindEx earlier.

    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Proposed as answer by Tom Li - MSFT Thursday, May 20, 2010 5:29 AM
    Wednesday, May 12, 2010 9:22 AM