I have a few hundred POLYGON
s and MULTIPOLYGON
s, each containing 10k+ points, that I am trying to bring into SQL Server 2008.
Unfortunately, these shapes are "right-handed." Namely, the perimeter of each one is wound clockwise around the points it contains. For GEOGRAPHY
types, SQL Server assumes "left-handed" shapes, anti-clockwise around the interior. This means that SQL Server assumes that I'm trying to select the entire earth except for my shape. Some people describe this as "inside-out" shapes.
MSDN's Orientation of Spatial Data heading states that the ring winding direction is significant, without actually saying which orientation to use:
If we use the
geography
data type to store the spatial instance, we must specify the orientation of the ring and accurately describe the location of the instance.
If you pick the wrong ring orientation in SQL Server 2008, it crashes with the following error (emphasis mine):
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.
Importing the shapes as GEOMETRY
instead of GEOGRAPHY
works fine, but I'd like to use GEOGRAPHY
if I can.
Fixing this problem appears fairly trivial on SQL Server 2012 by testing the envelope angle and using ReorientObject()
, but I am tied to version 2008.
How should I convert the shapes?