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

北城以北 提交于 2019-11-30 23:11:11

I've had the same problem and solved it using a project called Sql Server Spatial Tools (http://sqlspatialtools.codeplex.com).

It has (among other interesting stuff) these two methods:

  • MakeValidGeographyFromGeography
  • MakeValidGeographyFromText (which receives a WKT string)

They modify the points so that it conforms to the geography restrictions.

It works really, really well, and I've used it for several months now without any problem.

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}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!