SQL Spatial polygon inside out

后端 未结 5 2645
攒了一身酷
攒了一身酷 2021-02-19 21:27

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

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 22:02

    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 the Geography type [...]. This method illustrated is quite efficient, keeping overhead small [...].

提交回复
热议问题