'The specified input does not represent a valid geography instance' exception when using SqlGeographyBuilder

后端 未结 2 584
抹茶落季
抹茶落季 2021-01-06 19:17

I\'ve written a small application that reads in from a series of KML files and then converts them into the Microsoft.SqlServer.Types.SqlGeography type using the

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 19:55

    I had this same error, but it turned out to be a polygon ring orientation problem. A simple matter of flipping the order of the coordinate arrays solved the problem.

    To illustrate, this fails with the above error:

     select geography::STGeomFromText ('Polygon  ( (10 10, 10 20, 20 20, 20 10, 10 10))',4326)
    

    whereas this works:

     select geography::STGeomFromText ('Polygon  ( (10 10, 20 10, 20 20, 10 20, 10 10))',4326)
    

    Note that I'm not flipping the x,y pairs within a point, I am flipping the order of the entire point array (e.g. {pt1, pt2, pt3, pt4, pt5} becomes {pt5, pt4, pt3, pt2, pt1}

提交回复
热议问题