Change polygon "handedness" for SQL 2008 (reverse polygon vertex order)
Spatial Ed's blog had a concise solution. Here is some 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 an 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 [...].