开发者

How to check if a polygon exceeds the hemisphere limitation in SQL Server

I am storing polygons in an SQL server 2008 data base and I am aware of the hemisphere 开发者_C百科limitation.

http://blogs.msdn.com/b/isaac/archive/2009/02/06/the-geography-hemisphere-limitation.aspx

Is there a way to check before inserting/editing the polygon that it doesn't exceed the hemisphere limitation?

The application this is used in is written in JavaScript and C#, so the check could be in either of these languages or sql.


The article you link to gives one answer: use EnvelopeAngle to calculate half of the angle subtended by the geometrical object. If the result is >= 90, the object spans a hemisphere.

Another approach is to handle the error after it happens (by catching the exception, or however the error is generated) rather than checking that a particular object may cause an error beforehand.


what about

try
{ 
    Microsoft.SqlServer.Types.SqlGeography.Parse(YourPolygon); 
    // everything is ok...
}
catch (Microsoft.SqlServer.Types.GLArgumentException _E)
{
    // Polygon not ok
}

EDIT: the above code is the same used in the link you posted (look closely at the exception they show) - the check happens when the polygon is parsed into the SqlGeography type.

EDIT 2: Added correct Exception type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜