Saturday, March 31, 2012 11:55 PM
I´m creating polygons out of a collection of points, but i have a weird situation in which the SQL Server return me the enitre World :-):
SELECT geography::STPolyFromText('POLYGON ((9.6024305 47.58411, 9.5901797 47.5720098, 9.550566 47.5371757, 9.5319082 47.5357151, 9.5146841 47.5369248, 9.502768 47.5472144, 9.6024305 47.58411))', 4326)
The Management Studio 2008 shows nothing and isn´t able to render it, the Management Studio 2012 will show you a rect from -90 to +90 and from -180 to +180 :-).
Does anybody know what the error is ?
Sunday, April 01, 2012 8:47 AM
Please consider the "left hand rule". If you walk along the line of points, the described area is on the left side of you.
SQL Server 2008 can only build polygons with max size of a one hemisphere, therefore you get there an error; 2012 can build polygons of the complete world.
Turn around the order of points and it will work.
- Marked As Answer by LatinChriz Sunday, April 01, 2012 11:21 AM
Sunday, April 01, 2012 11:21 AM
Do you have any hint for me how i can i detect the order of the points in a C# program ?
The only possible (very bad performant) solution for me would be to query the area STArea() and check if it is too large and reverse the points... but that is no option for me...? :-) Any other ideas
Sunday, April 01, 2012 10:19 PMAnswererAssuming that what you really want to do is only create polygons smaller than a hemisphere, then you can check the result returned by the EnvelopeAngle() method. If it's 180, then your Polygon is created inside-out, and you should call ReorientObject() to reverse the point-ordering.
twitter: @alastaira blog: http://alastaira.wordpress.com/