I am allowing users to draw a polygon in Silverlight by clicking to draw. Then I loop through the points, convert them to longitude and latitude and then save to SQL (in a
I asked a similar question recently at the GIS StackExchange. I believe I have found a SQL-only solution, which is reproduced below:
Eventually found the answer at Spatial Ed's Blog.
SQL demonstrating the transform:
DECLARE @geom GEOMETRY = 'POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))';
DECLARE @geog GEOGRAPHY = @geom.MakeValid().STUnion(@geom.STStartPoint()).STAsText()
And excerpt from Ed's post:
The key to this behavior is the the
STUnion()
method. Since this is an OGC-based method, working on the entire geometry for a given feature, it forces polygons into the orientation required for the method - which just happens to be the one used for theGeography type
[...]. This method illustrated is quite efficient, keeping overhead small [...].