• HowardW (4/16/2013)


    Unfortunately, BOL documentation is sketchy on this, but it follows the "left hand rule", which means that if you imagined walking along the line in the direction that the points are described, your left hand would describe area. So, if you describe them clockwise, you're trying to define a polygon across the whole world, minus the small "hole" you've described, which in 2008 will throw an error as it can't span two hemispheres. Generally you need to define them anti-clockwise to describe an area.

    So, if your users are inputting the coordinates clockwise, you'll have to reverse the order.

    Nice description:-)

    One way to ensure you get the orientation right for this is something like the following

    It takes advantage of the fact that the Geometry is so strict on the orientation of the exterior ring. The STUnion of the first point causes the geometry to reorient.

    ;with geom as ( -- used to make the query a bit clearer

    SELECT Geometry::STGeomFromText(

    'POLYGON((76.9410753250122 11.05135492884294,76.94399356842041 11.055229898350953, 76.95734024047851 11.053439837277391,76.96186780929565 11.045963581774801,76.94744825363159 11.044805271627415,76.93420886993408 11.048764567419667, 76.9410753250122 11.05135492884294))'

    ,0) g

    )

    SELECT Geography::STGeomFromWKB(

    g.STUnion(g.STPointN(1)).MakeValid().STAsBinary()

    ,4326)

    FROM geom